Natural Language Processing · M2 · mocks

Q1 (2 marks)

M2 Mock A · core calculations

M2 · confirmed 2 + 2 + any two of 3 + 3 + 3 · worked practice

Q1

For “we study language models”, list the unigrams, bigrams and trigrams. Do not add boundary markers. (2 marks)

Given

Four tokens in the stated order.

To find

All contiguous n-grams for n=1,2,3.

Formula and why it applies

\#\text{ n-grams}=T-n+1LaTeX: \#\text{ n-grams}=T-n+1

T is the number of tokens. Slide a window of n consecutive tokens, one position at a time.

Solution

Step 1. Unigrams, window size 1

(we), (study), (language), (models); count=4.

Step 2. Bigrams, window size 2

(we study), (study language), (language models); count=4−2+1=3.

Step 3. Trigrams, window size 3

(we study language), (study language models); count=4−3+1=2.

4 unigrams, 3 bigrams and 2 trigrams, listed above.