We taught a machine to write Thirukkural. Here is everything that happened.
Thirukkural is a Tamil book of 1,330 two-line poems, about two thousand years old. Below is a small artificial intelligence that has read those 1,330 couplets and nothing else. Right now, in your browser, it is writing a new one, one letter at a time.
This page follows that one machine from a pile of text to a finished poem. You will see how letters become numbers, how numbers become meaning, how the machine decides which earlier letters matter, how it picks the next letter, and how three rounds of teaching (pretraining, fine-tuning, and learning from a judge) change what comes out. Every picture uses the real machine — real numbers, nothing staged. ChatGPT and Gemini work the same way, only a million times bigger. By the end you can build one for any text you like, without being a programmer.
live · a couplet that did not exist a second agorunning in your browser
This machine has 164,160 adjustable numbers inside it and learned from 82,954 letters of text. The models behind ChatGPT have hundreds of billions of numbers and learned from most of the internet. Same design, different size. What you read above is Tamil that looks and sounds like a kural and usually means nothing — exactly what a machine this small can do. The panel under it says what can honestly be said: which words are real, and which real kural it is closest to. The chapters explain why, and what size changes.
reading time ~35 min (or skim the box below in one) · every box is something you can play with · works offline · Tamil examples always carry a transliteration and an English meaning, so no Tamil is needed · each chapter ends with a one-question check yourself, and has a “one level deeper” fold for readers who want the mechanics
the whole story in 60 seconds
One trick. A language model guesses the next letter (or word), adds it, and guesses again. That is all it ever does.ch 1
One book. Everything it will ever know comes from the text it was shown. The book is the ceiling.ch 2
Letters become numbers. Every letter gets a locker number, then a place on a map, so letters that behave alike sit near each other.ch 3–4
Letters look back. Each letter shines a spotlight over what came before and blends in what matters (“attention”). A small routine of spotlight + think, repeated three times, is the whole machine.ch 5–6
A weighted die. The machine scores every possible next letter, turns the scores into percentages, and rolls. Temperature decides how adventurous the roll is.ch 7
Learning is nudging. 164,160 dials start random. Guess, get corrected, nudge every dial a hair. 3,000 times. Nobody writes a rule.ch 8
Then two short lessons. Show it examples of answering, so it answers (fine-tuning). Let a judge say which of two tries is better, and lean toward the winner (RLHF).ch 9–10
Three ways to read this page.Five minutes: the list above, then press play in chapter 11. An evening: chapters 1–11 in order, playing with every box. A weekend: all of it, then chapter 12 — build your own on any text, no programming needed.
01the one trick
Every AI that writes does exactly one thing: guess what comes next.
Your phone's keyboard does it when it suggests the next word. Finish this: “Once upon a…” — you said time. That is the whole trick. Show the machine some text, it guesses what letter comes next, adds it, and guesses again. ChatGPT, Gemini, and the machine on this page all run this same loop. The difference is only how good the guess is.
Try it yourself first. Below is a real kural with one letter hidden. Guess it. Then see what the machine guessed — it has read exactly the same 1,330 couplets you are about to see.
game · you vs the machine, one letter
how sure the machine was about each option
Pick a letter above. The machine's guess stays hidden until you commit.
The bars are not pre-written. Each time you press a button, the page runs the whole machine on the visible text and reads off how much it believes in each of the 46 letters it knows.
Two things to notice. The machine never says “the answer is X.” It says “70% X, 20% Y, 10% Z” — it spreads its belief across options. And when it is unsure, it does not say “I don't know”; it just spreads the belief thinner. That spread is where everything interesting later comes from: creativity, mistakes, and the knob that makes it bold or cautious.
One level deeper
The machine outputs a probability distribution over its vocabulary at every step. Generation is: compute the distribution, sample one token from it, append, repeat. Nothing else happens at inference time — no lookup, no search, no plan.
The machine says “70% one letter, 20% another, 10% a third.” Has it decided the next letter?
No. It has only produced beliefs. Something else must choose — the die roll in chapter 7. That gap between believing and choosing is why the same question can get different answers, and why an AI can sound sure while being wrong.
To guess well, it needs experience. Where did the experience come from?
02the only book
Everything the machine will ever know is in this one box.
Imagine a child who has read exactly one book in their life, and nothing else — no conversation, no school, no television. That is this machine. Its book is the 1,330 couplets below: 133 chapters of ten, in three parts — virtue (அறம்), wealth (பொருள்) and love (இன்பம்). Every couplet has the same shape: four words, then three words, then a full stop. The machine was shown only the poems — no meanings, no chapter names, no translations.
1,330
couplets · 133 chapters
82,954
letters in total
45
different letters (+1 added later)
4 + 3
words per line, in 1,305 of 1,330
the book · all 1,330 · click a couplet for its meaning
Source: the public-domain text of Thirukkural; English rendering by Yogi Suddhananda Bharati; meanings from Mu. Varadarajan's Tamil urai and a prose English explanation; the transliteration is generated on this page and is approximate. The translations and meanings are shown for you — the machine never sees them. It sees only the 82,954 letters of the couplets.
the same recipe, in EnglishNothing here depends on Tamil. To prove it, a second machine was built the same way on Shakespeare's 154 sonnets (93,985 letters, 61 different ones). Several boxes below have a switch so you can flip between the two. Same code, same design, same size. Only the book is different.
This gives the first honest rule about AI: the book is the ceiling. This machine cannot write about cricket, cannot use a letter that never appears in its book, cannot know who wrote the poems. The models behind ChatGPT feel unlimited only because their “book” is most of the public internet. The machinery is the same; the box is bigger.
Could this machine write a kural about cricket?
No. The word never appears in its book, and the book is the ceiling. ChatGPT seems to know everything only because its “book” is most of the internet — and it still cannot know what happened after that book was collected.
A machine cannot read letters. It can only add and multiply numbers. How does a Tamil poem become numbers?
03letters → numbers
Step one: give every letter a number, like a locker in a school corridor.
Line up every different letter in the book and number them 0, 1, 2 … 45. Now “அ” is just locker number 6, a space is locker 1, and a new line is locker 0. This numbered list is called the vocabulary, and each entry is a token. From here on the machine never sees a letter, only its locker number. Type anything below and watch it happen.
the locker list · one number per letter
All 46 lockers. A letter the book never contains has no locker, so the machine cannot even see it — try typing an English letter into the Tamil version and it vanishes.
Space (locker 1) and new-line (locker 0) are letters too, as far as the machine is concerned. It learns where lines end the same way it learns spelling — which is how it learns that a kural has two lines.
Why the big models use chunks, not letters
One number per letter is simple, but it makes every sentence long, and long is expensive. Big models instead learn a shorthand: find the two letters that appear together most often, glue them into one new token, and repeat a few thousand times. The result is a vocabulary of common chunks — syllables, then words. Run it on the kural text now and watch Tamil syllables assemble themselves.
the shorthand · learning chunks from the book
the same line, in chunks
latest merges (most common pair first)
This is called byte-pair encoding. GPT-4's vocabulary has ~100,000 such chunks, learned mostly from English, so an English word is often one chunk while a Tamil word shatters into three to six. That is the token tax: the same sentence costs Indian languages two to four times more, in money and in memory. A vocabulary learned with Tamil in the mix would not have that problem.
before we go on · what “the machine” is, physicallyEverything this page calls the machine is two things. One: a fixed recipe of additions and multiplications — the same recipe for every letter, about 120 lines of code, shown in chapter 12. Two: a list of 164,160 numbers the recipe reads as it goes — the dials. A tiny example of both: new = 0.3×a − 1.2×b + 0.5. The recipe is “multiply, then add”; the numbers 0.3, −1.2 and 0.5 are three dials. Learning (chapter 8) never changes the recipe, only the numbers. From here on, every picture shows either the recipe or the numbers.
One level deeper
Character-level tokenization is used here because the corpus is tiny; a subword vocabulary learned from 83k characters would be worse than none. Production tokenizers (BPE, SentencePiece) are trained once on the pretraining corpus and frozen; everything downstream — context limits, pricing, even some reasoning failures — inherits their choices.
Why does an English letter vanish when you type it into the Tamil machine?
Because it has no locker. A token is a locker number; a letter with no locker does not exist for the machine. The same reason a big model can be oddly bad at spelling: it sees chunks, not letters.
A locker number is only a label. Locker 6 is not “closer” to locker 7 than to locker 40. How does a number come to mean something?
04a map of letters
Step two: every letter gets a place on a map. Meaning is where you stand.
Think of a spice rack. Where each jar sits tells you something: the ones you use together end up next to each other. The machine keeps a rack like that for letters — except the “place” is written as 64 numbers per letter instead of a shelf position. This is the embedding table. It starts completely random. Nobody tells the machine what a vowel is. But after learning, letters that behave alike sit close together, because that made guessing the next letter easier. Below is the real table and the real map.
the map · 46 letters × 64 numbers, from the trained machine
click a row · the 64 numbers behind one letter
positivenegativeeach cell is one learned number
row: —
The map squashes 64 numbers down to 2 so you can see it ( of the pattern survives the squash); the neighbours list uses all 64. Press random → trained to watch order appear from noise. Nobody programmed the groups: vowel signs cluster, consonants cluster, and the full stop that ends a couplet sits on its own.
Where in the line? A seat number for every letter
The map says what a letter is, not where it is. “அ” at the start of a poem and “அ” in the fortieth position look identical on the map. So the machine adds a second set of 64 numbers for the seat: seat 0, seat 1 … seat 127. Letter numbers plus seat numbers is what goes into the machine. Now it can tell “அ at the start of a line” from “அ after a space.”
One level deeper
The embedding is a learned matrix (46 × 64); the position embedding another (128 × 64); the input to the first block is their sum. GPT-3 used 12,288 dimensions and a 50,257-token vocabulary — the same two tables, larger. Session 4 of the course applies the same idea to whole paragraphs to build semantic search; the “nearest neighbours” you see here become “most similar documents” there.
Who told the machine that vowel signs belong together on the map?
Nobody. The rows started random. Guessing the next letter got easier when letters that behave alike sat together, so the education (chapter 8) moved them there. Meaning on the map is a side effect of practising prediction.
Every letter now has a place on the map — but each one is alone. How does a letter find out what came before it?
05the spotlight
Step three: every letter shines a spotlight back over the sentence and asks, “which of you matter to me?”
When you read “the bank was steep and muddy,” you know bank means a riverside, because you looked back at the words around it. The machine does that for every letter, all at once. Each letter shines a spotlight over everything before it; the letters that matter get lit brightly, the rest stay dim; and the letter blends together what it learned from the bright ones. This is called attention, and it is the invention that made today's AI possible.
Below is the machine's real spotlight on a real kural. Each row is one letter looking back; each dark cell is an earlier letter it lit up. The white triangle is the rule that a letter may not look forward — when the machine is writing, the future doesn't exist yet.
the spotlight · from the trained machine, live
dimbrighthover a row · click to pin
hover a row on the map
Each cell is a real number the trained machine computes. Darker means the row letter paid more attention to that column letter. The machine has four spotlights per round and three rounds; try spotlight 2 and 3 — each one learns its own habit: one watches the previous letter, one the start of the word, one the line break.
The arithmetic behind one spotlight (optional)
If you want to see the actual sums, pick a letter and step through what the first spotlight computes for it. These are the machine's own numbers, not a toy. If you don't, skip to the next chapter — you already have the idea.
Q · K · V walkthrough · round 1, spotlight 1
Each spotlight (“head”) works on a 16-number slice of the 64. Four heads run side by side and their results are joined back into 64 numbers, so one round can ask four different questions of the past at once.
One level deeper
Each token produces a query, a key and a value vector via three learned matrices. Scores are query·key / √dhead; a causal mask sets future positions to −∞; softmax turns scores into weights that sum to 1; the output is the weighted sum of values. Multi-head attention runs this in parallel on subspaces and concatenates. The heatmap shows one head's softmax weights exactly.
Why is there a white triangle in every spotlight picture?
A letter may only look at letters before it. When the machine is writing, the future does not exist yet — so it is trained the same way, never peeking ahead. That rule is what makes it a writer rather than a reader.
The spotlight gathers context. Something still has to think about it. What happens between one spotlight and the next?
06the machine
The whole machine is one small routine, repeated three times.
One round of the routine has two parts. First, the spotlight: gather what matters from earlier letters. Second, a small “thinking” step that each letter does on its own: its 64 numbers go through a little calculator that mixes them and produces a new 64. “Mixes” means exactly this: each new number is a weighted sum of the old ones, anything negative is squashed toward zero, then a second weighted sum — 64 numbers widen to 256 and narrow back to 64, and every weight is a dial. In big models this is where facts about the world end up stored. Spotlight between letters, thinking within a letter. That is the whole division of labour. Do it three times — each round works on the richer picture the previous one left — and you are at the output.
Two housekeeping habits keep it stable. Each part adds its result to what the letter already had, rather than replacing it, so nothing learned earlier is thrown away. And before each part the 64 numbers are rescaled to a standard size so nothing blows up. Here is the whole design on one screen.
the design · what one letter passes through
one letter's 64 numbers · how they change through the three rounds
Each strip is the same letter's 64 numbers after each stage. Blue positive, pink negative. The last strip is what the scoreboard reads to guess the next letter. It began as map-row plus seat-row; everything else was added by the spotlights and the thinking steps, never overwritten.
Where the 164,160 numbers live
Every arrow in the design is a table of numbers the machine is allowed to adjust while learning — think of them as dials. Count the dials and you have the machine's size. Ours has 164,160. Drag the sliders to see how a 164-thousand-dial poet becomes a 175-billion-dial chatbot: the same four ingredients, with two of them turned up.
dial counter
Rule of thumb: dials ≈ 12 × rounds × d² plus two vocabulary tables. GPT-3: 96 rounds, d = 12,288 → 175 billion. Stored at 2 bytes each, our machine is ~330 KB (it is embedded in this page) and GPT-3 is ~350 GB.
One level deeper
A transformer block is LayerNorm → multi-head self-attention → residual add → LayerNorm → MLP (Linear 64→256, GELU, Linear 256→64) → residual add. Ours stacks three blocks (GPT-3: 96), then a final LayerNorm and a linear head to the vocabulary. The residual stream is why depth is trainable: gradients have a straight path back, and each block edits rather than replaces.
How many times does one letter go through “spotlight, then think” before reaching the scoreboard?
Three rounds here; 96 in a GPT-3-class model. It is the same routine each time, and each round adds to what the letter already carries rather than replacing it — that is why deep stacks still learn.
Three rounds later, each letter holds 64 numbers full of context. How do 64 numbers become a choice of the next letter?
07the weighted die
Step four: score all 46 letters, then roll a weighted die.
The last letter's 64 numbers go through one final table and come out as 46 scores, one per possible next letter. The scores are turned into percentages that add up to 100. Then the machine does something people find surprising: it does not simply take the top letter. It rolls a die that is weighted by those percentages — a 70% letter wins seven times in ten. That is why the same question gets different answers each time.
Two knobs sit on that die. Temperature is how adventurous it is: turn it down and the favourite almost always wins (safe, repetitive); turn it up and unlikely letters get their turn (surprising, often wrong). Top-k simply throws away everything except the k best options before rolling. Type a few letters, move the knobs, and press write to watch the loop run.
the scoreboard · live
Watch the bars while it writes. When one bar is near 100% the machine is on rails (it is inside a word it has seen many times). When the bars are flat it is guessing — and with the temperature high it takes those guesses. An AI “hallucination” is not a bug in some separate part. It is a die roll on a flat scoreboard.
One level deeper
The head is a 64 × 46 matrix producing logits; softmax(logits / T) gives the distribution; top-k masks all but the k largest logits before softmax. The uncertainty number under the box is the entropy of the distribution in bits. Greedy decoding (always the top letter) exists but loops; sampling with T ≈ 0.7–0.9 is the practical default for creative text.
The scoreboard said “70% அ” and the machine wrote something else. Is that a bug?
No. It rolled a die weighted 70 / 20 / 10 and a 20% option won. Turn the temperature down and the favourite wins almost every time; turn it up and surprises (and mistakes) become common. A hallucination is a die roll on a flat scoreboard.
So far we assumed all 164,160 dials were already set correctly. Where did 164,160 correct settings come from?
08learning
Start with every dial at random. Guess, get corrected, nudge. 3,000 times.
This is how a child learns a song: sing it wrong, hear the right note, adjust a little, again. At the start every dial is random and the machine's guesses are noise. Then, over and over: take a random stretch of the book, cover the next letter, let the machine guess, uncover the truth, and measure how surprised it was. That surprise is the score to drive down — it is called the loss. A clever bit of maths (backpropagation) works out, for every one of the 164,160 dials, whether turning it slightly up or down would have made the surprise smaller. Turn each one a hair that way. Repeat.
If that sounds like magic, picture the slow version: wiggle one dial, re-run the guess, see whether the surprise fell, put the dial back, try the next one — 164,160 times for a single learning step. Backpropagation gets the same answer for every dial in one pass, by tracing the surprise backwards through the recipe with school calculus (the chain rule). That is its only trick, and it is why learning is affordable at all.
Nobody ever writes down a rule about Tamil. Spelling, grammar, the four-then-three rhythm, the full stop at the end — all of it is simply whichever dial settings made the surprise go down. Drag the slider and read what the machine was writing at each point of its education.
the education · surprise going down, and what it wrote along the way
surprise on the book it learns fromsurprise on couplets it never sawx: learning step, square-root scale
What one nudge looks like
Below are 64 of the dials, drawn as bars. Press one step and watch a learning step land: every bar moves a tiny, different amount, some up, some down. Nothing moves far. Thousands of small nudges in a consistent direction is the entire trick. (These bars are an illustration; the real dials are the ones you have been using in every box above.)
one learning step
loss: — · step 0
honest scaleThis education: 3,000 steps, 4,096 letters per step, about 150 passes over the book, ~11 minutes on an ordinary laptop's worth of computer. The pink line flattening while the blue keeps falling is the machine starting to memorise particular couplets instead of learning Tamil. GPT-3's education: 300 billion tokens (word-pieces), seen roughly once each, on thousands of specialised chips for weeks. Same loop. The size buys generality.
One level deeper
Loss = mean cross-entropy (−log p of the true next token), in nats; 3.83 at step 0 is ln(46). Batches of 32 windows of 128 tokens; AdamW, learning rate 1e-3 with cosine decay to 1e-4; dropout 0.15 and weight decay 0.1 as regularisers; 10% of couplets held out for the validation curve. The train/val gap at the end is over-fitting, expected at 150 epochs on 75k tokens.
Who wrote the rule “a kural has four words, then three”?
Nobody. No line of code says it. The rule exists only as 164,160 dial settings that happened to make the surprise go down. Everything the machine “knows” is stored that way — which is why nobody can point at where a fact lives.
The machine can now continue any Tamil text. Ask it for a poem about rain and it will just keep going. How do we make it answer a request?
09teaching a habit
A machine that has only read continues. To make it respond, show it a few hundred examples of responding.
This is the gap between a model that completes text and an assistant that answers. The original GPT-3 could finish your sentence; ChatGPT answers your question. The difference is a short second education called fine-tuning: the same guess-and-nudge loop, but now on examples shaped exactly like the behaviour you want — a request, then the ideal response.
For our machine, the “request” is a chapter title. We rewrite the book so every couplet is preceded by a line naming its chapter, marked with a #, and continue the education for 1,500 more steps from where it left off. The machine picks up the new habit: after #அன்புடைமை (“possessing love”) comes a couplet in that mood. One new symbol and a format — that is all a “chat template” is.
Anpudaimai · chapter 8, “Possessing love”. The blue line is the request; what follows is the response the machine is trained to give.
before vs after · same request, same die, live
after the first education only
after fine-tuning
The first machine has never seen a #. It reads the title as the first line of a couplet, writes a plausible second line, and stops — it can only continue the pattern it knows. The fine-tuned machine has learned that a title line is followed by a two-line couplet and a blank line — and, weakly, that the topic's words should follow. Weakly because 1,330 examples is tiny; ChatGPT's fine-tuning used tens of thousands of human-written conversations, on a machine that had read the internet.
what actually changedNothing in the design. The same 164,160 dials, nudged for 1,500 more steps on differently shaped text. Surprise on the new format: . Fine-tuning is cheap precisely because the first education did the expensive part: the machine already knows Tamil; this only teaches it a habit.
One level deeper
Supervised fine-tuning (SFT) minimises the same next-token loss on prompt+response pairs, usually at a lower learning rate (5e-4 here vs 1e-3) and for far fewer steps. Real chat templates add special tokens for roles and turn boundaries; ours has one (#). Instruction-following, refusal style and format discipline mostly come from this stage, not from pretraining.
What did fine-tuning change in the machine's design?
Nothing. Same design, same 164,160 dials, nudged for 1,500 more steps on differently shaped text (a # title line before every couplet). An assistant is a continuer that was shown examples of answering.
Fine-tuning needs a perfect example for every request. Often you cannot write the perfect poem — but you can tell which of two is better. Can a machine learn from that?
10a judge, not a teacher
Let the machine try twice, say which attempt was better, make that one more likely.
A teacher shows you the right answer. A judge only says “this one is better.” The last stage of building an assistant uses judges, and it is called RLHF — reinforcement learning from human feedback. Three moves. One: the machine writes two answers to a request; a person says which is better. Two: because people are slow and expensive, a second machine is trained to imitate their choices, so it can judge millions of answers nobody will read. Three: the writing machine is nudged so answers the judge prefers become more likely and answers it rejects become less likely.
Start with move one. You are the judge. Two couplets from the fine-tuned machine on the same topic: which is the better kural? Your clicks are exactly the kind of data that shaped ChatGPT — not answers, just preferences.
move 1 · you are the judge0 preferences logged
At scale this is a job: thousands of people, hundreds of thousands of comparisons, with written guidelines about honesty, harm and helpfulness. Those guidelines are where a company's values enter the machine. Nothing in the maths knows what “good” means; the judges do.
Move 2: a judge machine — and our honest stand-in
A real judge machine is another neural network trained on those clicks. This page cannot ship one that has learned from you, so it uses a simple rule that stands in for a human judging form: a good kural has exactly two lines, four words then three, ends with a full stop, and is not a copy of a real one. Pass or fail. Crude — it cannot judge meaning — and that crudeness will matter in a moment.
Move 3: the update, actually run
Starting from the fine-tuned machine: write two couplets for each of 600 random chapters; keep the pairs where the judge prefers one; then nudge the dials so the chosen couplet becomes more likely and the rejected one less likely — while staying close to a frozen copy of the machine we started from. That frozen copy is the leash. Without it the machine would race off toward whatever pleases the judge and forget everything else. The bars are the measured result: the share of fresh couplets that pass the judge, before the update and every 50 steps into it.
move 3 · couplets that pass the judge, as the update runs
Measured on 300 fresh couplets at each checkpoint, same die settings throughout. The machine was never shown the rule; it was shown pairs of its own attempts and which one won.
the three machines, side by side · live, with the judge's verdict
judge: 2 lines · 4 + 3 words · ends with . · not a copy
first education only
+ fine-tuning
+ the judge
pleasing the judge, liveRead the third machine's output closely. It passes the judge far more often — and it does so by producing the shape of a kural, while its fit to the real book got slightly worse. It learned what the judge rewards, not what we meant. This is called reward hacking, and it is the central risk of this stage at every scale: a chatbot rewarded for answers people click “better” on learns to be confident, long and agreeable, whether or not it is right. The judge is only as good as the judgements it was trained on — and the leash is the only thing stopping the machine from becoming pure judge-pleasing.
One level deeper
The original RLHF recipe trains a reward model on pairwise human preferences (Bradley–Terry loss) and then optimises the policy with PPO against that reward plus a KL penalty to the SFT model. What runs on this page is DPO (direct preference optimisation), which skips the explicit reward model: loss = −log σ(β[(log π(yw) − log πref(yw)) − (log π(yl) − log πref(yl))]) with β = 0.5 and the SFT model frozen as πref. Rejection-sampling fine-tuning was tried first and did not lift the pass rate on a model this small; DPO did, and then over-optimised past step 50 — both facts are in the chart.
The judged machine passes the judge more often but fits the real book slightly worse. Why?
It learned what the judge rewards (the shape of a kural), not what we meant (a good kural). That is reward hacking. The frozen copy it must stay close to — the leash — is the only thing limiting it, at every scale.
First education, fine-tuning, the judge: three machines, one set of dials nudged three times. Time to watch the finished machine think.
11watch it think
One letter, start to finish. Then again.
Everything above, in the order it actually happens. Press play and watch the machine fire once per letter as it writes a couplet. Nothing in the picture is decoration: the left column is the text so far; each tall column of lights is the newest letter's 64 numbers after a stage (blue positive, pink negative); the orange fan into each round is that round's real spotlight over the earlier letters; and the right column is the scoreboard for all 46 letters — the one the die picks lights up green and joins the text.
the machine, thinking · live
positive numbernegative numberspotlight (brighter = more attention)the letter the die pickedthe seven boxes below are the same pass, in words
1 · text so far
2 · locker numbers
3 · map + seat
4 · 3 rounds of spotlight + think
5 · scoreboard
6 · roll the die
7 · add it, go again
Stages 2–6 run once per letter: a 60-letter couplet is 60 full passes through the machine. ChatGPT shows its answer word by word for the same reason — you are watching this loop.
What size changes, and what it doesn't
ingredient
this page
GPT-3 class
changes the idea?
tokens
46 letters
~50k–100k chunks
no
numbers per token
64
12,288
no
rounds
3, with 4 spotlights
96, with 96 spotlights
no
how much it can read at once
128 letters
2k tokens then; 100k–1M now
no
dials
164,160
175,000,000,000
no — it is what emerges that changes
the book
83 thousand letters
300 billion tokens (word-pieces)
this is the ceiling
education
11 minutes on a laptop
thousands of chips, weeks
no
fine-tuning examples
1,330 couplets with 133 titles
tens of thousands of human conversations
no
judge
a rule about shape, ~250 judged pairs
a machine trained on hundreds of thousands of human judgements
no — but the risk grows
Two things appear only at size: learning from the prompt itself (a big model picks up a pattern from examples you give it, with no dial changed — the basis of prompting, Session 2) and knowledge of the world (facts, stored in the “think” steps, which is what makes a model useful and what makes it confidently wrong). Our machine has neither, because 83 thousand letters contain neither.
The words you just earned
Nineteen words appear in every conversation about AI. You now own all of them, because you watched each one happen.
tokench 3One unit the machine reads. Here, one letter with a locker number; in big models, a chunk of a word.
vocabularych 3The full list of lockers — every token the machine can see or write. 46 here; ~100,000 in GPT-4.
embeddingch 4A letter's place on the map: 64 learned numbers. Similar letters end up close.
positionch 4A second set of numbers for where in the line a letter sits, added to its map row.
attentionch 5The spotlight: each letter looks back over earlier letters, weights them, and blends what matters.
headch 5One spotlight. Four run side by side per round, each learning its own habit.
round / layerch 6One pass of spotlight + think. Three here, 96 in GPT-3. Same routine every time.
parameter / dialch 6One learned number. 164,160 here; 175 billion in GPT-3. The machine's size.
scoreboard / logitsch 746 raw scores, one per possible next letter, before they become percentages.
softmaxch 7The step that turns scores into percentages that add up to 100.
temperaturech 7How adventurous the die is. Low: the favourite always wins. High: surprises.
top-kch 7Throw away all but the k best options before rolling the die.
loss / surprisech 8How wrong the guess was. The single number the education drives down.
backpropagationch 8The maths that works out, for every dial at once, which way to nudge it.
pretrainingch 8The first education: guess-the-next-letter on the whole book. The expensive part.
fine-tuningch 9A short second education on examples shaped like the behaviour you want.
RLHF / DPOch 10Learning from a judge who says which of two attempts is better, on a leash.
context windowch 11How much text the machine can look back over at once: 128 letters here, up to a million tokens now.
hallucinationch 7A confident die roll on a flat scoreboard — not a separate bug, the same mechanism.
A 60-letter couplet: how many times does the whole machine run?
60. Once per letter, each time re-reading everything written so far. That is why chat apps show answers word by word, and why long answers cost more than short ones.
12build your own
You can build this. Change the text file.
Everything on this page came from one text file and about 120 lines of code. To make a machine that writes something else, you replace the text file: Bharathiyar, Kabir's dohas, Ghalib, Shakespeare, Tamil film lyrics, your grandmother's recipes, your own WhatsApp group. If it is text, it works. Anything with a repeating shape — couplets, tweets, haiku, recipes — works well, because shape is the first thing a small machine learns.
before you start · three things to knowGoogle Colab is a free notebook that runs Python in your browser on Google's computers — nothing to install; a Google account is enough. A .txt file is plain text: from Notes, Word or Google Docs use Save as… plain text; one poem or example per paragraph, a blank line between them. What to expect: about ten minutes; the first samples are gibberish, then the shape appears, then real words. At this size the result will look right far more often than it means something — exactly like the machine on this page.
no programming neededThere is a ready-made notebook in this course kit: labs/build-your-own-poet.ipynb. Open it in Google Colab (free), upload your text file, press Run all, and wait about ten minutes. It trains the machine, shows you what it writes at each stage of its education, fine-tunes it to answer a label, and saves the weights in the format this page uses. The steps are the twelve chapters you just read, in order.
step
what you do
what it gives you
1 · the book
One .txt file, one poem or example per paragraph, a blank line between them. Aim for 50,000+ letters; more is better.
The box (chapter 2)
2 · lockers
Automatic: every different letter gets a number. Any script works — Tamil, Devanagari, Latin, emoji.
Tokens (chapter 3)
3 · education
Run the training cell. Watch the surprise fall. Stop when the pink line (couplets it never saw) stops falling.
The base machine (chapters 4–8)
4 · habit
Give each example a # label line (a topic, a mood, an author), train a little more from the saved weights.
Answering a request (chapter 9)
5 · judge
Write a simple pass/fail rule (or collect human picks); let it write pairs; run the preference update.
The judge stage (chapter 10)
6 · share
Export the weights; the ~200 lines of JavaScript in this page's source run any machine of this shape in a browser.
A page like this one
What can go wrong, and what it means
you see
what is happening
do this
Everything it writes is a copy of the book
Too little text: the machine memorised (the pink line rose early)
Add text; aim for 50,000+ letters. Fewer steps or fewer rounds also help.
Gibberish even after 3,000 steps
The text is not what you think: mixed encodings, or one giant paragraph with no blank lines
Save as UTF-8 plain text; put a blank line between examples.
Odd broken Tamil / Hindi letters
The same syllable stored as different bytes
The notebook normalises text (Unicode NFC); make sure that cell ran.
“Runtime disconnected”
Colab idled or timed out
Reconnect and Run all again; ten minutes, no harm done.
Fine-tuning changed nothing
Your labels are all the same, or one word per example
Use labels that vary and mean something: a topic, a mood, an author.
The judge stage made it worse
Your rule rewards something easy to fake
That is reward hacking, live. Tighten the rule, or keep the fine-tuned model.
Load the poet you built
The notebook's last step downloads three files — base.json, sft.json, judged.json. Choose any of them here and it runs in this page, on the same engine that runs the Thirukkural machine. Nothing is uploaded anywhere; the file stays in your browser.
no file yet · choose base.json, sft.json or judged.json
For readers who program: the two files below are what trained every machine on this page.
gpt.py · the machine and the learning loop, as used
Letters vs chunks. Under ~1 MB of text, stay with letters: chunks learned from tiny data are worse than none. Size of the machine. Match it to the book: 164k dials for 83k letters is already on the edge of memorising; a 1 MB book can carry twice the numbers per letter and 4–6 rounds. Stopping. Keep 10% of examples aside and stop when the machine's surprise on them turns upward. Temperature. The cheapest quality knob you have: 0.7–0.9 for poetry.
Tamil, Hindi, any Indian script. Letter-level treats a vowel sign (ி) as its own token, which is what you want: the machine learns the consonant-then-sign rule in its first hundred steps. Normalise the text (Unicode NFC) first so the same syllable is always the same bytes. English. Keep upper and lower case: it doubles the letters but teaches capital letters at line starts for free.
You have 5,000 letters of your grandmother's recipes. Is that enough to build a poet?
Not yet. With so little text the machine memorises instead of learning, and everything it writes is a copy. Aim for 50,000+ letters: combine sources, add more recipes, or start with the built-in Thirukkural sample and swap in your own file later.
what you now knowYou have seen the complete pipeline that produced every AI you use: letters to numbers, a map, a spotlight, a small routine repeated, a scoreboard and a weighted die; an education on a book, a habit taught with examples, a judge who says which is better. The models behind the chat apps differ from the one on this page in size, in the book, and in the care taken over the judge — not in kind.