Professional Documents
Culture Documents
• Next week:
• Monday is a holiday
• Tuesday is an optional workshop
• Meaning I won’t prepare anything, but you can come with questions/projects and we can
work on them together
• Assignment 3 is due
• Wednesday is your final exam
• 8:30-11:30am, Buchanan B209 (like your normal morning class)
• And, that’s a wrap
• I’ll do the marking as soon as feasible
N-GRAM MODEL
• So, how do we build an n-gram model?
• Steps:
• Read through the corpus
• Identify each gram that occurs
• For each gram, memorize the n-1 following grams
• When done, calculate the probability of each n-gram
N-GRAM MODEL
• Here’s a simple example using Green Eggs and Ham by Dr. Seuss
Corpus Grams
Do you like do (3), you (1), like (3), green (2), eggs (2),
Green eggs and ham and (2), ham (2), I (2), not (2), them (1), Sam-
I-am (1)
I do not like them,
Bigrams
Sam-I-am.
I do not like do you (1), you like (1), like green (2), green
Green eggs and eggs (2), eggs and (2), and ham (2), ham I
ham. (1), I do (2), do not (2), not like (2), like them
(1), them Sam-I-am (1), Sam-I-am I (1)
N-GRAM MODEL
• What’s a good way to track N-grams in Python? We need a word (key) that
connects to the next-n-words (value)
N-GRAM MODEL
• What’s a good way to track N-grams in Python? We need a word (key) that
connects to the next-n-words (value)
• Dictionary