★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★★ FOUR BRAND-NEW COURSES ANNOUNCED! ★ Machine Learning End To End  •  Hands-On Deep Learning with Python  •  Generative AI & LLMs with Python  •  AI Agents and Agentic AI with Python  ★  Open the “Educational” menu above to explore them ★  ★  NEW! 5. JOB ASSISTANCE: JD Report • Resume customization • AI Mock Interviews — FREE with course bundles, or just ₹499 / US$5. Single Payment. No Subscription. ★

A language model made of nothing but counts

A language model made of nothing but counts
12-10-2026  |  By Tejas Desai, Ecube Analytics  |  Generative AI: Tokenization & decoding (Chapter 2)  |  4 min read
READ 5TH OF 8 IN THIS SERIES

A language model made of nothing but counts

Tokenization & decoding · Part 5 of 8

Before neural networks, language models were just tables of counts. Build one and the ideas from the last post, probabilities, perplexity and sampling, stop being abstract. It also shows exactly what a neural model has to do better.

Count what follows what

A character n-gram model predicts the next letter from the previous few letters. To train it, slide along the text and count which letter followed each context. To predict, turn the counts for the current context into probabilities.

A language model made of countsBar chart of the letters that follow the context th, and three ways of handling a context that never appeared in training.After the two letters “th”, what comes next?(counts from the training text)“e”61 of 76 (80%)“a”9 of 76 (12%)“i”3 of 76 (4%)“?”2 of 76 (3%)“o”1 of 76 (1%)What if the context was never seen?Raw countsno counts ? probability 0 ? the score collapsesAdd a little (smoothing)tiny but non-zero for every letterBack off to a shorter contextborrow the statistics of the last letter(s)
Left: real counts from the training text. Right: what happens when the context was never seen.

Test it on text it has not seen

I wrote a short text of about 2,400 characters with 40 different symbols, trained on the first 90% and measured perplexity on the rest. A model that knows nothing has perplexity 40, one choice among 40 symbols. Longer context should help, up to a point:

Letters of contextRaw countsWith a little added to every countBacking off to shorter contexts
018.918.919.0
139.511.812.0
22,62410.09.2
3567,45112.48.4
430,409,37416.88.6
5423,779,69321.48.9

Read the table as a story about generalisation:

  • With raw counts, even one letter of context already hurts (39.5, against 18.9 with none), and from two letters on the scores run into the thousands and millions. A longer context nearly always appears in the test text for the first time, has no counts, and so gets probability zero. Zero probability is catastrophic for the score.
  • Adding a small amount to every count avoids the zeros, but it spreads probability evenly over letters that make no sense.
  • Backing off to shorter contexts when the long one is rare is far better. The best model, with 3 letters of context, reaches about 8.4: roughly five times better than guessing.

What the models write

Letting the models sample text (same text, a fixed random seed) shows the same story:

  • 1 letter of context: Thas thes wont te gre t. ans the aft beattorr cucam tothe a t teandas the cis alderche. thefil ntoke
  • 3 letters of context: The of the fix in light team when the wrong is replies the worder, and ever ask what counted are. Fo
  • 5 letters of context: The warehouse opens at the works together to worry. At night the start. The driver sign, and the cus

Short context gives gibberish with English-like sounds. A medium context gives local phrases that do not add up to sentences. A long context starts to copy its training text, because there is little else to continue with.

What a neural network adds. A count table can only reuse contexts it has literally seen. A neural language model represents similar contexts with similar vectors, so it can make sensible predictions for contexts it has never met.

Build your own

Open in Colab Count, smooth, measure perplexity and sample text on a short text. Free in your browser.

Takeaways

  • A count table is a complete, tiny language model.
  • Raw counts fail on unseen contexts: zero probability ruins the score.
  • Smoothing and backing off to shorter contexts fix it.
  • Neural models generalise to unseen contexts because similar contexts get similar vectors.

Next in the series (Part 6): Greedy and beam search: the best word or the best sentence?

This blog is from chapter 2, course-2-generative-ai of 4 world-class courses on aibits.ecubeanalytics.com
← Previous Article 5 of 8 in this series Next →