Part IV — Speaking, Thinking & Limits Chapter 12 of 12

Context Windows, Hallucinations, Tools & Reasoning

Why models forget, invent confident stories, reach for tools, and think step by step.

9 min read · 3 interactive labs · Course Finale

If you have ever chatted with an AI for an hour, you have probably met its three strangest quirks firsthand:

  1. It suddenly forgets something you told it at the very beginning of the chat.
  2. It invents a fake book title or citation with the calm confidence of a tenured professor.
  3. It blunders a simple riddle when answering fast—yet solves it effortlessly the moment you say, "Think step by step."

Now that you can see how a transformer works from the inside out, none of these quirks are mysterious anymore. Every single one follows directly from the glowing machinery you have already explored!

1. The Sliding Context Desk (Why Models Forget)

A language model does not have a human diary that quietly updates in the background. Every time you send a message, the model re-reads the entire conversation sitting on its working surface—a fixed-size space called the Context Window.

Picture this context window as a glowing desk with a limited number of slots. While the conversation fits on the desk, attention spotlights can reach back and connect any detail to any other. The moment the desk fills up, however, the oldest cards slide off the left edge into darkness. To the model, anything that falls off the desk simply ceases to exist.

Even for cards still on the desk, attention is not always uniform: models often pay sharpest attention to the beginning and the very end, leaving details buried in the middle a little dimmer—a quirk researchers call "Lost in the Middle." Click + Add Message below to fill the desk and watch both effects happen live!

Interactive Lab 1 The Sliding Context Desk (Memory Window)
3 / 6 slots used
Click + Add Message until more than 6 cards arrive. Watch older cards slide off the left edge and fade out, while the glowing spotlight curve dips slightly in the middle of the desk.

2. Why Hallucinations Happen—and How Tools Cure Them

When a model invents a fake fact, we call it a Hallucination. People often wonder: "Why didn't it just stay silent?"

Look at the probability bars and you will see the answer instantly. For a well-known fact seen thousands of times during pre-training—like "The Eiffel Tower is in ___"—one single bar (Paris) towers over the rest.

Now ask about something obscure or nonexistent. The model's memory vault has no towering peak—the probability bars flatten out into a low, uncertain sea of plausible-sounding words. Yet the sampling wheel still has to spin. Because the model is a master of fluent grammar, it smoothly stitches those plausible words into a confident-sounding sentence—complete with an invented date and journal name!

How do modern AI systems fix this? They stop relying on blurry memory alone and reach for Tools—like web search, a document lookup, or a calculator. Dropping a real retrieved fact card directly onto the context desk turns a flat guessing game into a towering, grounded peak! Try toggling between the three modes below.

Interactive Lab 2 Why Hallucinations Happen (Pattern vs. Fact)
Grounded Fact

A well-known fact creates one sharp towering bar. Switch to Obscure Question to see the flat bars that trigger confident inventions—then click Ground with Search Tool to watch the retrieved card rescue the model!

3. Thinking Out Loud: The Scratchpad Trick

Here is our final "aha!" moment—and it explains the biggest breakthrough in recent AI.

When you ask a transformer to answer a tricky puzzle immediately, it only gets one single trip up its stack of layers before it has to spit out the answer token. That is plenty of time to spot familiar patterns, which is why it often falls for seductive traps.

Consider the famous bat-and-ball riddle: "A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost?" Almost everyone—human and AI alike—feels a fast impulse to blurt out $0.10.

Now watch what happens when we let the model Think Step by Step (called Chain-of-Thought). Every intermediate sentence it writes gets placed right back onto the Context Desk! Each new "thinking token" buys the model another full pass through its entire stack of layers—turning its own output stream into a glowing external scratchpad.

Interactive Lab 3 Fast Answer vs. Chain-of-Thought Scratchpad
Choose a mode to run the puzzle
Each glowing scratchpad card gives the transformer another full pass of computation—letting it test a guess, spot that $1.10 + $0.10 = $1.20 is too high, and land cleanly on $0.05.
From Chatbots to Agents

Combine everything in this chapter—a Context Desk, Step-by-Step Thinking Tokens, and External Tools (search, code, calculators)—and you get an AI Agent: a language model that can plan, look up real facts, check its own work, and iterate until a job is done.

Check Your Intuition

Why does asking a language model to "think step by step" dramatically improve its accuracy on multi-step math and logic puzzles?
Course Complete · Chapters 1 – 12

You Can Now See Inside the Machine

Pause for a moment and look back at the journey you just took—without a single intimidating equation.

You started with a simple next-word guessing game. You watched text snap into tokens and lift off into maps of meaning where directions carry ideas. You stepped inside the Transformer to see multi-head attention spotlights routing context, memory vaults lighting up facts, and layers stacking meaning floor by floor. You saw trillions of tiny nudges shape raw weights during pre-training, human feedback sculpt an assistant during post-training, temperature bend the skyline of probabilities, and context desks, tools, and scratchpads turn fluent predictors into reasoning partners.

The next time you watch words stream across a screen, they won't look like magic—and they won't look like cold mystery either. You will see the glowing bars, the shifting spotlights, and the vast map of human language humming quietly underneath. Thank you for exploring Seeing Language.