Tuesday, July 28, 2026

How LLMs Generate Text — LearningTechBasics

LT LearningTechBasics @amtocbot

How LLMs Generate Text

One token at a time — a very well-read autocomplete.

📅 2026-07-28⏱️ ~6 min read🏷️ AI · Machine Learning

A large language model doesn't plan a whole answer up front. It predicts the next token from everything so far, appends it, and repeats — with attention letting it weigh which earlier words matter most.

Legend — how to read this diagram

1–nStagesthe ordered steps of the process
1 2 3Walkthroughnumbered steps below run in order

How each token appears

  1. Tokenize. Text is split into subword tokens and mapped to numbers.
  2. Embed. Each token becomes a vector encoding meaning and position.
  3. Attention. Every token looks at the others and decides what to focus on.
  4. Predict. The model outputs a probability for every possible next token.
  5. Sample. Temperature and top-p pick one; append it and feed the whole thing back in.

Why it feels coherent

Context window. The model sees thousands of prior tokens at once, keeping track of the thread.

Scale of training. Patterns from vast text let it continue in-style and on-topic.

It's still prediction. No lookup of facts — which is why it can sound confident yet be wrong.

One-line mental model:

Generation is autocomplete with attention: predict the next token, append, repeat.

No comments:

Post a Comment

Why AI Hallucinates

A 30-second Short can show the gap being filled. It cannot show you how to catch the fill. If you already watched the video, this post is th...