Looks like magic
2026-05-28 · 12-min read
How are tokens generated? Magic, obviously. Stick with me — by the end, the trick falls apart and what’s left is a loop.
Hover any bullet for the deeper point.
№ 01
The hook
- A scroll that writes itself, one word at a timeA student points a wand, chants once, and a word scratches itself onto the parchment. Chant again, another word. Again, another. The essay is filling in — but the student isn’t composing it.
- They’re watching it arrive, not writing itNo plan, no draft tucked behind the ear. The student finds out what the sentence says when the sentence is done. That feeling — eerie now — is the whole talk.
- By the end, the trick falls apartWe’re going to follow the spell all the way through. Turns out there was never any magic — just one spell, cast over and over.
A student sits in the Owlery. There’s an essay due — the teacher assigned it, an owl is perched on the windowsill waiting to carry it off, and the parchment is mostly blank. The student has no idea what to write next.
So — stuck — they do what you do at a magic school. They point a wand at the parchment and chant: Modelus Contextus.
And a word appears. One word. Scratched onto the parchment by nothing. They blink. They chant again. Modelus Contextus. Another word. Again — another. And the essay starts writing itself, one word at a time, and here’s the strange part: the student doesn’t know what it’s going to say. They’re not composing it. They’re watching it arrive, word by word, as if the parchment knows something they don’t.
So how are the words — the tokens — generated? Magic, obviously. Stick with me. Because by the end, I’m going to show you the entire trick, and it’s going to turn out there was never any magic at all. Just a spell, cast over and over. Let’s slow it down.
№ 02
The scroll
- Red = spell’s hand. Blue = yours. Black = the scrollEvery fresh word lands hot — red if the spell wrote it, blue if you did. Both cool to black. Black is the scroll itself: settled, canon, the part the spell reads.
- A word isn’t finished until it’s blackBlack isn’t fading. It’s the strong state. Color is just the heat of having-just-been-written; the word cools into substance.
- If it’s not on the scroll, it isn’t thereNo secret notebook. No plan tucked behind the ear. If it’s going to shape the next word, it’s on the scroll, in plain sight. This is going to matter more than it sounds like.
- The scroll doesn’t care who wrote a wordOnce a word is black, the spell can’t tell whether the wand put it there or the student did. Same ink, same scroll, no difference.
Let’s slow the whole thing down and look at the one thing on the table: the scroll.
Everything the student has so far lives here. The assignment, every word written, in order. And the words are color-coded — not for decoration. When the spell writes a word, it lands in red. When the student picks up a quill and writes one themselves, it lands in blue. Red is the spell’s hand; blue is yours.
And then both of them cool. Red fades, blue fades — to black. And black is the scroll itself: the part the spell actually reads, in full, every single time it’s cast. A word isn’t finished until it’s black. The color is just the heat of having-just-been-written. Once it cools, the scroll doesn’t care who wrote it. The spell reads a blue-gone-black word you wrote exactly the way it reads a red-gone-black word it wrote. Same ink, same scroll, no difference.
Which means there’s no secret notebook. No plan tucked behind the student’s ear, no hidden draft. If it’s going to shape the next word, it’s on the scroll, in plain sight. Hold onto that.
№ 03
The cast
- Modelus Contextus — the model + the contextNot nonsense. The name calls out the two things the spell needs: Modelus, the wizard’s training, frozen years ago; and Contextus, the scroll, everything written so far.
- Reads the whole scroll, every timeNot the last line. All of it. Every cast is the spell sweeping the entire scroll, top to bottom, before producing anything.
- Doesn’t produce a word — produces a cloudThis is the part everyone gets wrong. The cast lights up every possible next word at once, each at a different brightness. A spread of possibilities, not a choice.
- The spell reveals. It doesn’t choose.Brightness = probability. ‘lighthouse’ burning bright; ‘lamp’ a little dimmer; ‘lasagna’ a faint flicker at the edge. And one strange little marker, barely glowing, way out at the very edge. Hold onto that one.
So what does the spell actually do? Here’s where the name finally pays off. Modelus Contextus. It’s not nonsense — it names the two things the spell needs. Contextus: the scroll, everything written so far. And Modelus: the model — everything the wizard learned, years ago, and never changed since. The spell takes those two things and reads the entire scroll, top to bottom, every single time it’s cast.
And watch what comes out — because this is the part everyone gets wrong. The spell does not produce a word. It produces a cloud. Every word it might write next, all at once, each one glowing at a different brightness. ‘lighthouse’ burning bright. ‘lamp’ a little dimmer. ‘lasagna’ a faint flicker way out at the edge. And — keep an eye on this, way out at the very edge, barely glowing at all — a strange little marker, <|end|>. Not a word. We’ll get to it. A thousand maybe-words plus that one odd signal, lit by how likely each one is. That whole shimmering cloud — that’s what one cast gives you. Not a decision. A spread of possibilities.
The spell didn’t pick. It just lit up the options. Something else does the picking.
(One beat for the purists: yes, a real wizard would call this Accio Tokenum — summon the token. Better Latin. But we named ours for what goes in, not what comes out — because the whole trick is in the inputs. Moving on.)
№ 04
The pick
- The wand swings — silentNo chant. No second spell. There’s exactly one incantation in this whole talk, and it’s already been cast. The pick is silent machinery.
- By default, it grabs the brightestThe most-likely candidate, most of the time. The wand lands on it, the word drops onto the scroll in red, and like everything else, it cools to black.
- The wizard didn’t chooseThe wand picked. The cloud came from the scroll plus the training. The wizard cast the spell and swung the wand — but which word fell out wasn’t theirs to decide.
- The student is a little surprised — every timeRemember the surprise. It’s the most honest thing in this whole post. We’ll come back to it.
So the cloud’s just hanging there — every possible next word, glowing. Something has to reach in and grab one. That’s the wand.
No chant. No second spell. The wizard doesn’t even decide. The wand just swings into the cloud and pulls one word out — and by default it goes for the brightest one, the most likely. It lands on the scroll in red, fresh and hot — and then, like everything else, it cools to black. Now it’s part of the scroll. Part of what the next cast will read.
And notice what didn’t happen. The wizard didn’t choose the word. The wizard cast the spell and swung the wand — but which word fell out wasn’t theirs to decide. It came from the cloud, and the cloud came from the scroll plus the training. The student is honestly a little surprised every time. Remember that — the surprise. We’ll come back to it, because it’s the most honest thing in this whole talk.
№ 05
The loop
- One word = one whole castEverything we just walked through — the chant, the cloud, the swing, the drop, the cool — that was one word. To get a sentence, you do the whole thing again.
- Each cast reads the new, longer scrollIncluding the word that just landed. The spell’s own last word is now part of what it reads to choose the next one. It’s feeding on itself.
- Quill-words go in identicallyScratch a word in with the quill, blue. The next cast reads it like any black word. The scroll doesn’t care who wrote it. (This is why “think step by step” works, and why prompts steer at all.)
- The trickle on your screen is this loop runningNot a loading animation. Not the essay being revealed from somewhere. Cast, drop, cast, drop — that’s the whole engine.
Here’s the thing you have to see: everything we just walked through — the chant, the cloud, the swing, the word dropping, cooling to black — that was one word. One. To get a sentence, you do the whole thing again.
Cast. Cloud blooms. Wand swings. Word drops, red, cools to black. The scroll is now one longer. And again — but notice: this cast reads the new scroll. Including the word that just landed. The spell’s own last word is now part of what it reads to choose the next one. It’s feeding on itself.
And here — the student gets impatient and scratches in a word with the quill, in blue. Watch what the next cast does with it. …Nothing special. It reads the blue word exactly like the red ones. Cools to black, same as everything else. The scroll doesn’t care who wrote it.
And now just… let it run. Cast, drop, cast, drop, faster than you can follow — and that blur, that streaming, words appearing one after another? That’s not a loading animation. That’s not the essay being revealed from somewhere. That is the spell, cast over and over, each word the seed of the next. When you watch a chatbot’s answer trickle in, you are watching this exact loop run. There’s nothing else happening. That’s the whole engine.
№ 06
The swing of the wand
- How you swing it sets the wand’s appetiteSame cast, same cloud. The only thing that changes is what the wand will reach for — the brightest, or something dimmer.
- Tight flick → brightest, every time (cold)A surgeon’s flick. Cast it twice over the same scroll, you get the same word twice. Low temperature.
- Wild flourish → a gamble on a dimmer one (hot)A big, sweeping, reckless arc — the wand might reach past the brightest and grab a candidate that was only faintly glowing. High temperature.
- Recklessness, not power — one dial, two directionsThe wild swing isn’t more powerful magic. It ’s less disciplined magic. Drunker, not smarter. “More creative” and “more reliable” aren’t two settings — they’re one dial turned opposite ways.
So far the wand has just grabbed the brightest candidate. But the wand has a setting — and it’s set by how you swing it. A tight, surgeon’s flick, and the wand takes the brightest every single time. Cast it twice over the same scroll, you get the same word twice. That’s a cold wand. Low temperature.
Now swing it wild — a big, sweeping, reckless flourish — and the wand might reach past the brightest and grab a candidate that was only faintly glowing. That’s a hot wand. High temperature. And here’s the thing to hold onto: the wild swing isn’t more powerful magic. It’s less disciplined magic. It’s not smarter — it’s drunker. It gambles.
Which is exactly why the same question can give you a different answer every time you ask — and why “make it more creative” and “make it more reliable” aren’t two settings. They’re one dial, turned opposite ways. You don’t get both.
There are a couple of related knobs that just keep the wand out of the junk — top-p draws a line and says only consider the brightest cluster, ignore the faint tail entirely. Same spirit: tidy up what the wand’s even allowed to reach for.
№ 07
The owl leaves
<|end|>has been in every cloud, all alongThe dim flicker at the edge of the cloud, back on slide three. It’s been there every cast. Easy to miss is the point.- When ‘done’ gets bright, the wand pulls it like any other wordNot a word, exactly — a signal, like the telegraph operators who closed every message with a mark meaning transmission complete. But mechanically, it’s just another candidate. The wand swings the same way.
- The owl was watching for that one tokenNot for the essay to look finished — it can’t read your prose. It was waiting for the one signal it was trained to watch for.
<|end|>lands; owl’s gone. - Nobody decided to stopThe student didn’t sit back and think “that’s a good essay.” The owl didn’t judge it finished. The spell just… eventually pulled the done signal out of the cloud, the same mechanical way it pulled every other word.
So the loop just runs. Cast, drop, cast, drop. What makes it ever stop?
Go back to that very first cloud. Remember the dim little flicker way out at the edge — <|end|>? It’s been there. Every single cast. Every cloud, that marker has been sitting in the corner, barely glowing, easy to miss. It’s not a word — it’s a signal, like the old telegraph operators who closed every message with a mark meaning transmission complete. Not part of the message. A sign the message is over.
And here’s the thing: it’s a candidate like any other. The wand could have grabbed it at any point — a wild enough swing early on, and the essay just… stops, mid-thought. But mostly it stays dim, because the essay isn’t done, so ‘done’ isn’t likely.
Until now. The essay’s said what it has to say — and that flicker is suddenly bright. ‘Done’ has become the most likely next thing. The wand swings — and the owl moves. The owl that’s been on that sill since the start of this post. It snatches the scroll and is gone.
It was waiting for exactly this. Not for the essay to look finished — it can’t read your prose. It was watching for that one signal. <|end|> lands, owl’s gone, off to the teacher.
And here’s the unsettling part. Nobody decided to stop. The student didn’t sit back and think ‘that’s a good essay.’ The owl didn’t judge it finished. The spell just… eventually pulled the done signal out of the cloud, the same mechanical way it pulled every other word. The ending wasn’t a decision. It was just one more token. Hold that feeling for one more section.
№ 08
The reveal
- The spell, cast over and over → a functionThe same computation, run again for every word. Fixed machinery. That’s the cast.
- The glowing cloud → a probability distributionReal term. You already know exactly what it is — it’s the brightness of the candidates. A spread over every possible next token, weighted by likelihood.
- Large Language Magic → the weightsBillions of frozen numbers, learned years ago at the academy, never changed since. That’s what people mean by “seventy billion parameters” — seventy billion of those numbers.
- The scroll → the contextEverything the model can “see” right now. System prompt, conversation, the tokens it just produced. Read in full, every cast.
- The wand’s swing → sampling temperatureCold = always grab the brightest. Hot = willing to gamble on a dimmer one. One dial, creativity against reliability.
<|end|>→ exactly what it said on the tinThe end-of-sequence token. A real token in the vocabulary. When it gets pulled, the loop halts. Nobody decided.
So let me tell you what you actually just learned. Because it wasn’t a fairy tale — every single piece of that story is a real thing, with a real name, and you already understand all of them.
The spell, cast over and over? That’s a function — the same computation, run again for every word. The glowing cloud of maybe-words? That’s a probability distribution — that’s the real term, and you already know exactly what it is, it’s the brightness of the candidates. The wizard’s training, learned years ago and never changed? Those are the weights — billions of frozen numbers. That’s what people mean by a model having ‘seventy billion parameters’ — seventy billion of those numbers. The scroll is the context. The wand’s swing is the sampling temperature. And <|end|>? Exactly what it said.
That’s it. That’s a large language model generating text. You didn’t watch a metaphor for the thing — you watched the thing, wearing a robe.
And remember the student who was a little surprised by every word? That’s the most honest part. The model doesn’t know the sentence it’s about to write. It writes one word, reads everything including that word, writes the next, and stops when ‘done’ gets bright enough. No plan. No intent. No magic.
That self-writing scroll that felt so unsettling at the start — it’s not unsettling anymore. It’s just a loop.
It only looked like magic.
L-L-M. Looks Like Magic. Turns out it stands for something a lot more boring. And now you know the whole spell.