How AI writes
Prepared for Fountain Valley School by Terence Parr ’82
To get the most from AI, we have to form a mental model of how it behaves, like any other tool. AI’s most obvious quirk is that it can hallucinate or, at the very least, can give different results for the same prompt. Paraphrasing AI researcher Andrej Karpathy, AI is always dreaming but sometimes it’s useful. The first step towards effective AI use is understanding why it “dreams” so that we can counteract or even take advantage of it.
You also might have noticed that AI is much weaker and slower when generating text (or images) than it is at consuming and understanding information. That’s because AI reads everything we give it all at once, sort of like a human looking at an image, but it replies one word at a time without backing up to make corrections. Putting together the dreaming and reading-vs-generating nature of AI explains most of its behavior.
To help visualize this, take a look at the enclosed animation I built for you (with AI’s help) for a simplified and idealized AI reading and generating text. From the same phrase prefix, you’ll see that the randomness inherent in the model yields different complete sentences. Below the animation, you’ll find some more details to lock in this mental model.
Read in
It reads everything at once
Your whole prompt, plus everything it has written so far, goes in together every time, and each word can affect every other. That’s why it’s good at analyzing, summarizing, and critiquing text you give it. Your words steer everything it writes.
Tip: give it context, an example, and the format you want. Paste in the material you want it to work from.
Think
It predicts likely next words
From its training, the model learned which words tend to follow which. For each next word, it works out how likely every word it knows is to come next. The bars show those likelihoods. They measure what sounds likely, not what’s true.
Tip: it’s strongest on topics people write about a lot, and weakest on rare facts, exact numbers, quotes, and sources. Check those.
Pick
It picks with some chance
The model doesn’t always pick the most likely word (tallest bar). It picks at random, with taller bars more likely to win. Press Run again and watch the same start turn into different sentences.
Tip: ask twice or regenerate. If the answers disagree, don’t trust either one yet.
Append
It writes one word at a time, with no going back
Each picked word joins the text and goes back in, and every later word has to fit with it. Like an improv troupe, it builds on whatever was said, even a mistake. One unlucky or wrong-but-plausible word gets followed by smooth, confident words that fit it. That’s how AI hallucinates.
Tip: a confident tone isn’t evidence. If it goes off track, start fresh instead of arguing. For hard problems, ask it to work step by step before it answers.
Finished runs
Each finished sentence lands here, so you can compare runs.