From a label to the next word
See how autocomplete chooses between “rain” and “snow” using three entries from a weather diary.
A small language model starts with a question: which word is likely to come next? Before training a network, try a predictor that counts familiar continuations. Its result gives you something to compare the trained model against.
A small example
A weather diary has three entries: “light rain”, “light rain” and “light snow”. You type the first word, “light”. How might autocomplete pick the second? Rain appeared twice and snow once. Choosing the more frequent ending gives “rain”.
From a count to a prediction
Add “light snow” once. The score is now 2–2, so the rule has no single winner. One more “light snow” makes it 2–3 and autocomplete will suggest “snow”.
The counter describes what people wrote in the diary. It could still rain tomorrow. And if the next entry starts with “heavy”, the counter has no examples for that opening. That is a useful test for a trained model that can use similarities between phrases.
Python right here
Copy the “light snow” line inside the list, including its comma. Run once with four entries, then add the line again and run with five.
Click Run to see the result.
Python message
Done reading?
Mark the lesson as read to move your track progress forward.
Lesson marked as done.
Now build your own version
Write a probability calculation for different counts. Check whether it handles rare words and changing vocabulary sizes.
Progress saved in this browser
Clear your history or open this on your phone, and the marks will be gone. Leave your email and they'll move to your account. No password needed.
Done. moved to your account. You can see your progress on any device. My progress