Natural Language Processing · TEE · papers

Q4c · Most probable bigram continuations

2025-02-21 · re-exam · recovered AI paper

Previous examination · complete worked answers

Question. Train on <s> I love programming </s>; <s> Programming is fun </s>; <s> I love coding </s>; <s> Coding is great </s>. Predict next tokens for <s> I love ..., <s> programming ..., <s> coding ... using a bigram model. [10 marks]

Answer

Given

<s> I love programming </s>
<s> Programming is fun </s>
<s> I love coding </s>
<s> Coding is great </s>

To find

Most probable next token for each prefix.

Formula: which one and why

P(w\mid h)=\frac{c(h,w)}{\sum_v c(h,v)}LaTeX: P(w\mid h)=\frac{c(h,w)}{\sum_v c(h,v)}

Lowercase lexical tokens; include sentence-end as an observed next token. Bigram prediction uses only the last token of the prefix.

Step 1. Count each adjacent pair separately within sentences

BigramCount
<s> → coding1
<s> → i2
<s> → programming1
coding → </s>1
coding → is1
fun → </s>1
great → </s>1
i → love2
is → fun1
is → great1
love → coding1
love → programming1
programming → </s>1
programming → is1

Step 2. Continue <s> I love

CandidateCount / history countProbability
coding1/20.500000
programming1/20.500000

Highest: programming, coding. This is a tie; no tie-break rule is supplied.

Step 3. Continue <s> programming

CandidateCount / history countProbability
</s>1/20.500000
is1/20.500000

Highest: </s>, is. This is a tie; no tie-break rule is supplied.

Step 4. Continue <s> coding

CandidateCount / history countProbability
</s>1/20.500000
is1/20.500000

Highest: </s>, is. This is a tie; no tie-break rule is supplied.

Final answer

<s> I love → programming or coding
<s> programming → </s> or is
<s> coding → </s> or is

If an examiner explicitly restricts the answer to a lexical word, exclude END and state that restricted candidate set. Do not silently remove an END tie.