Ep. 03 — Why AI Sometimes Invents: Probability, Temperature, and Context Slate
Yesterday we saw that AI doesn't read words, but tokens: fixed Lego bricks that compose every sentence. Today the question is: how does it choose the next brick? And why does it sometimes "invent" things that don't exist?
The Big Misconception: It Doesn't Search, It Completes
Imagine opening a book to a random page and reading: "Once upon a time there was a..." Your brain completes it immediately: "...king", "...prince", "...dragon". You're not searching for the answer in a mental encyclopedia. You're predicting it based on how many times you've seen that sequence.
AI does exactly this: predicts the most probable token given what it just read. It doesn't "know" facts. It calculates probabilities.
The Bag of Dice (Temperature)
When the AI must choose the next token, it has a list of candidates ordered by probability:
- "king" — 45%
- "prince" — 30%
- "dragon" — 15%
- "gnome" — 5%
- "toast" — 0.1%
Temperature decides how it draws from this bag.
- Low temperature (e.g., 0.1): picks almost always the first. Predictable, coherent, but rigid. Like a loaded die that always rolls "6".
- High temperature (e.g., 1.0): draws more randomly. "gnome" and even "toast" get a chance. More creative, more surprising, but also riskier: it can output nonsense.
- Zero temperature: deterministic. Always choice #1. Useful for code or precise facts.
Life analogy: low temperature = following a recipe to the letter. High temperature = improvising in the kitchen with what's in the fridge. Sometimes a masterpiece is born, sometimes a disaster.
The Slate That Erases Itself (Context)
There's a physical limit: the AI has a slate of finite size. Everything you tell it, everything it replies, everything it "remembers" of the conversation must fit on it.
When you write a lot, the first pieces fall off the edge and disappear forever. The AI doesn't "forget" them by choice: they literally no longer fit on the slate. It's like talking to someone with a short-term memory of a few minutes: if the conversation goes on, the beginning vanishes.
This explains why:
- In long chats the AI loses the thread from the start.
- It can't "study" an entire book loaded all at once: the slate fills up and the first pages fall off.
- API costs grow: more tokens on the slate = more compute = more money.
Why It "Invents" (Hallucination)
If you ask a precise fact (e.g., "Who won the Nobel Prize in Physics in 2023?") and the AI hasn't seen it often enough during training, it doesn't answer "I don't know". It completes the sentence with what statistically seems plausible. Sometimes it guesses right. Sometimes it invents a name, a date, an article that doesn't exist.
It doesn't lie. It predicts. And prediction, without real grounding, can drift.
Where We Stop Today
We've understood the engine: probability + temperature + finite slate. AI doesn't seek truth. It completes the most probable pattern within a limited space.
Enough theory: tomorrow we open the workbench from scratch on your computer and write the first 5 lines of code.
👉 Episode 4 — The Workbench: What Is the Terminal, Python, and Our First File Back to progettosiliceo.online/tutorial-agenti.html to continue.