🧠 My Tiny Brain Train your own tiny LLM β†’

How do LLMs work? A hands-on guide for beginners

ChatGPT, Claude and Gemini are large language models (LLMs). This guide explains, in plain English, what is going on inside them, and every idea comes with something you can try on My Tiny Brain, a free tiny language model that you train yourself, from nothing, right in your browser.

1. The big idea: an LLM guesses the next word

Underneath everything, a language model does one simple job: given some text, it guesses what comes next. Not a whole answer at once, just the next small piece. It adds that piece to the text, then guesses again, and again, until the reply is finished. A long, thoughtful-looking answer is thousands of these guesses in a row.

The model never looks anything up. Everything it "knows" is stored as patterns in a huge collection of numbers (called parameters or weights) that were tuned while it practised guessing the next word on enormous amounts of text. Big chatbots have billions of these numbers; My Tiny Brain has from a quarter of a million up to about a hundred million.

Try itAsk My Tiny Brain something and open the πŸ’­ Thinking tab. For every word of its reply you'll see the words it was choosing between and how likely it thought each one was.

2. The oldest language model: just counting

Before neural networks, language models simply counted: "after the words once upon a, the word time came next 97 times." To write, they picked a likely next word from those counts. This is called an n-gram model, where n is how many words back it looks.

It has a built-in problem. Look back only one word and the sentences are nonsense. Look back many words and it can only copy sentences it has already seen, because longer word sequences are almost never repeated. Modern LLMs were invented to escape this trade-off.

Try itSet Brain type to Counting and move the Memory slider from 1 to 3 to 8. Watch it go from word salad to real-looking English to copying the books word for word. The πŸ“š Memory tab shows its tables of counts.

3. Tokens: how an LLM reads text

LLMs don't read letters or whole words. They read tokens: chunks of text such as the, ing or fri. Common words become one token; rare words are spelled out of several. The list of tokens is built before training with a method called byte-pair encoding (BPE): start with single letters, find the pair that appears side by side most often (say t + h), glue it into a new token (th), and repeat thousands of times.

Why bother? With whole words, every word needs its own slot and any new word, name or typo is a complete blank. With tokens, a fixed list of a few tens of thousands of pieces can spell any word, even made-up ones. This is also why chatbots are priced and limited "per token" rather than per word.

Try itType a sentence with a typo, like my freind is. The counting brain says Never seen: freind; the transformer reads it as pieces it already knows and often still copes.

4. Embeddings: turning words into numbers

A neural network can only do arithmetic, so each token is turned into a list of numbers called an embedding. At first these numbers are random. During training they are nudged so that tokens used in similar ways end up with similar numbers. Nobody tells the model that Monday is like Tuesday, or that he is like she: it discovers it, because those words appear in similar places.

You can picture an embedding as a position on a map of meaning. Real LLMs use maps with thousands of directions; we can squash them down to two or three to look at them.

Try itOpen πŸ—ΊοΈ Word map or 🧊 3D β†’ Word space on a brand-new brain, then again after training. Scattered words gather into groups: numbers, days, names, pronouns.

5. How a neural network learns

A neural network is a big recipe of multiplications and additions that turns the embeddings of the text so far into a score for every possible next token. Learning works like this:

  1. Take a bit of real text and hide the next word.
  2. Let the network guess. Measure how wrong it was (this measure is called the loss).
  3. Work out, for every single number in the network, which way to nudge it to make that guess a little less wrong (this is backpropagation), and nudge them all a tiny bit (gradient descent).
  4. Repeat millions of times.

No rule of grammar is ever written in. Everything comes from these tiny nudges adding up.

Try itIn the πŸ‹οΈ Train tab, press Start practising and watch the error number fall. About 8 means pure guessing; below about 4 it starts writing real phrases.

6. Attention and the transformer

The breakthrough behind ChatGPT came in 2017 with the transformer, introduced in a research paper famously titled Attention Is All You Need. Its central trick is attention: for each token, the model looks back over all the earlier tokens and decides which ones matter right now. To continue "The king said that he…", it's useful to look back at "king", not at "that".

A transformer is built from layers. Each layer does one round of "look back with attention, then think about what you found", and each layer has several attention heads that look for different things at the same time. Stacking more layers lets the model build up more complex understanding. GPT-style chatbots are this same design, just far bigger: more layers, longer embeddings and a much longer window of text they can see at once (the context window).

Remarkably, nobody programs what each head should look for. One head ends up tracking the previous word, another follows names, another punctuation, all on its own, through training.

Try itTrain a transformer, type the king said that he, then click a word of the reply to see an attention heatmap, or open 🧊 3D β†’ Through the layers to watch a sentence pass through each layer.

7. How ChatGPT and Claude are trained

Chatbots are made in stages:

  1. Pre-training. The model practises next-word prediction on a vast amount of text: books, websites, code. This is where it picks up language, facts and reasoning patterns. It is by far the most expensive stage.
  2. Fine-tuning. It practises on examples of questions and good answers, so it learns to behave like an assistant instead of just continuing text.
  3. Learning from feedback. People (and other models) rate its answers, and it is nudged towards the kinds of replies that were rated well. This is often called RLHF, reinforcement learning from human feedback, and it's what the thumbs-up and thumbs-down buttons in chat apps feed into.

A real risk when teaching a model something new is catastrophic forgetting: practising one new lesson too hard can damage what it already knew. A common cure is replay: mixing each new lesson with a bit of the original practice material.

Try itGive your brain some books (pre-training) and the πŸŽ“ Q&A practice starter set (fine-tuning), then rate its replies with πŸ‘, πŸ‘Ž or ✏️ to correct it (feedback). Each correction is mixed with replayed library text.

8. Overfitting: memorising instead of learning

A model can get very good at the text it practises on simply by memorising it, without learning how the language really works. That's called overfitting. To catch it, a small slice of text is held back and never practised on: the test set. If the model keeps improving on its practice text but gets worse on the test text, it has started memorising.

The cures are more and more varied text, and a model that isn't too big for the amount of text it has. Model size and data have to grow together: a huge model with little to read just learns it by heart.

Try itTrain a transformer on just one short book and watch the πŸ‹οΈ Train chart: the orange test line goes down, flattens, then rises. Press ↩️ Go back to restore the version saved at its lowest point.

9. Temperature and top-p: how a reply is chosen

The model's output for each step is a list of probabilities, one per token. The chatbot still has to pick one. Temperature decides how adventurous that pick is: low temperature almost always takes the favourite (safe but repetitive), high temperature takes long shots more often (varied but error-prone). Top-p only allows the most likely tokens that together add up to, say, 90% of the probability, cutting off the weird tail. These settings change how a model sounds without changing anything it knows.

Try itAsk the same question with Creativity (temperature) low and high, Focus (top-p) tight and loose, and Drafts at 1 and 5.

10. Why AI needs graphics cards (GPUs)

Almost all the work in a transformer is multiplying big grids of numbers. A graphics card has thousands of small cores that can all do the same multiplication at once, which is exactly what that needs. That's why AI companies buy GPUs by the tens of thousands. My Tiny Brain uses your own graphics card through WebGPU in Chrome or Edge, so its larger sizes, up to about the size of 2019's GPT-2, can train in a browser tab.

11. Why LLMs make things up ("hallucinations")

Because a language model is trained to produce a likely-sounding next word, not a checked fact, it can write fluent sentences that are simply wrong. Where its training text was thin or contradictory, the most plausible-sounding continuation may be invented. Big chatbots reduce this with more training, feedback and tools such as web search, but the underlying mechanism is the same next-word guess you can watch in a tiny model.

12. Glossary of AI words

LLM (large language model)
A neural network trained on huge amounts of text to predict the next token. ChatGPT, Claude and Gemini are built on LLMs.
Token
A chunk of text the model reads and writes: a word or part of a word.
Tokenizer / BPE
The method that splits text into tokens. Byte-pair encoding builds tokens by repeatedly gluing together the most common neighbouring pieces.
Embedding
The list of numbers that stands for a token. Similar words end up with similar numbers.
Parameters / weights
All the numbers inside the model that training adjusts.
Attention
How a transformer decides which earlier tokens to look back at when choosing the next one.
Transformer
The neural network design, built from layers of attention, used by modern LLMs.
Context window
How many tokens back the model can see at once.
Loss
A score for how wrong the model's guesses are. Lower is better.
Pre-training / fine-tuning
Practising on lots of general text, then on examples of the behaviour you want.
Overfitting
Memorising the practice text instead of learning general patterns.
Temperature / top-p
Settings that control how adventurous the choice of each next token is.
n-gram model
An old kind of language model that counts which word follows the previous n words.
RLHF
Reinforcement learning from human feedback: improving a model using people's ratings of its replies.

The best way to understand an LLM is to build one.
My Tiny Brain is free, runs entirely in your browser, and keeps everything you add on your own computer.

🧠 Start training your tiny brain β†’