← ELI5 · Nestor G Pestelos Jr

How Large Language Models Work

A picture-book breakdown of token cuts, probability games, and the attention spotlight.

Card 1 of 5

1. Computers Don't Read Words. They Cut Them Into Number Tokens.

When you give text to an AI, it chops your sentence into small puzzle pieces called tokens. Each token gets matched to a number in a giant dictionary.

Input sentence: "The robot wrote code"
The#464
robot#8451
wrote#4321
code#2438
Why do tokens matter?
Common words like "the" get 1 token. Rare words or complex code get sliced into multiple pieces. If a sentence has 10 words, it usually becomes about 13 tokens.
Card 2 of 5

2. It Is Playing the World's Biggest Guessing Game.

An AI does not write whole paragraphs at once. It looks at all previous tokens and asks: "What is the single most likely token to come next?"

"The cat sat on the..."
mat
65%
rug
20%
couch
10%
moon
1%
Why does it feel smart?
It was trained on billions of books and websites. It learned the patterns of human grammar and logic by guessing trillions of missing words during training.
Card 3 of 5

3. The Attention Spotlight: Connecting the Clues.

How does it know what "it" means in a long story? The Attention Mechanism shines spotlights backwards on important clues in the sentence.

"The bank refused the loan because it was out of money."
✨ Spotlight connects "it""bank" (financial institution, not a river bank!)
What makes Attention special?
Before Transformers (2017), computers read text one word at a time in order and forgot early words. Attention lets every word look at all other words simultaneously.
Card 4 of 5

4. Memory vs. An Open Notebook (Why RAG Stops Hallucinations).

If you ask an AI a secret or new fact from memory, it will guess plausibly—and make things up (hallucinate). To fix this, we give it a search notebook (RAG).

❌ Guessing from Memory
"What is my bank balance?" → AI invents $4,200 out of nowhere.
✅ Looking up Facts (RAG)
Searches database → pastes real ledger → AI answers $842.10 accurately.
What is RAG?
Retrieval-Augmented Generation: First fetch the exact documentation or private notes, then paste them into the prompt before asking the model to answer.
Card 5 of 5

5. The Model Proposes. A Separate Gate Decides.

In real production systems, you never let the AI execute money transfers or delete databases on its own. The model proposes a plan; a strict policy gate verifies it.

🤖 AI Proposes Plan
🛡️ Policy / Human Gate
⚡ Safe Execution
Why the human gate matters
Because models are statistical predictors, they can be tricked by prompt injection or make errors. Real systems wrap models in deterministic guardrails.