What Is Pre-training? How LLMs Learn General Knowledge
An 826k-parameter GPT, 6 minutes on a Mac CPU: 1 MB of Shakespeare teaches it the shape of a play, 50 KB makes it memorize
Short version: pre-training is the stage where you hand a model a huge pile of unlabeled text and make it guess the next character, over and over. I tried it. I trained a tiny GPT with 826k parameters on 1 MB of Shakespeare for 6 minutes on a Mac CPU, and a model that spat out random characters started imitating the shape of a play. Give the same model only 50 KB and it memorized the text instead. After reading this you'll know what pre-training actually does, how to read a loss number, and why a company almost never needs to start from it.
Guessing the next character is the whole job
The character after "To be or not to b" is "e". The answer is already in the text. Nobody has to label anything, so text from the internet can be used as training material as is. That's called self-supervised learning.
GPT-style models guess the next token, and BERT guesses blanks punched into the middle of a sentence. A token is the unit a model cuts text into. In this experiment one character is one token.
What I tried: a tiny GPT on 1 MB of Shakespeare
The material was tinyshakespeare, Shakespeare's plays stitched together (1,115,394 characters, 65 distinct ones). I trained on the first 90% and kept the last 10% as a test set the model never saw.
The model is a GPT with 4 Transformer layers, 128 dimensions and a window of the previous 128 characters: 826,433 parameters, about the size of nanoGPT's Shakespeare example. With torch 2.8.0 on a Mac CPU, 3,000 steps (32 lines of 128 characters each step) took 380 seconds.
step seen text unseen text
0 4.33 4.33
100 2.43 2.43
500 1.68 1.84
1000 1.47 1.67
3000 1.25 1.53
The numbers are loss: how badly it failed to expect the next character. Lower is better. Picking any of 65 characters at random gives 4.17 (ln 65), and the starting 4.33 is right there. 1.53 roughly means it has narrowed the next character down to 4 or 5 candidates (e^1.53 ≈ 4.6).
Asking it to continue after "ROMEO:" shows more than the numbers do.
step 0 t3ZrjmhPPdvhRxTsXlgqWHVHca neqhAybPPNdfIxAlst
step 100 Thar mhis ke whselt Whouca neaman youd I tlst t My oure
step 500 Thou more therestle it on your and,
step 3000 Thou must know the first and good words golden great upon him.
HENRY BOLINGBROKE:
Why, says he hath thought awake a while idle;
By step 100 it has picked up spaces and the shape of short words. By 500, "Thou" and "hath" show up. By 3,000 it copies the play format: name, colon, line break, speech. It doesn't make sense and the grammar is half there. But nobody told it "this is a name and this is a line." That came out of guessing the next character and nothing else.
Too little text and it memorizes
At first I assumed that with enough steps, the amount of text wouldn't matter much. So I gave the same model the same 3,000 steps on just the first 50 KB (50,000 characters). I was wrong.
seen text unseen text
trained on 1 MB 1.25 1.53
trained on 50 KB 0.10 6.00
On the 50 KB run, loss on its own training text dropped to 0.10. It has nearly memorized it. Loss on unseen text bottomed at 2.34 around step 250, then kept climbing to 6.00. That's worse than guessing at random (4.17), because it's confidently wrong in the voice of the text it memorized.
I slid a 30-character window across a 200-character sample and checked whether each piece appears verbatim in the training text. For the 50 KB model, 30 of 171 pieces (17.5%) did. For the 1 MB model, none. The 50 KB model pulls out whole lines like "'Tis most like he will."
Over 3,000 steps the model sees 12.29 million characters. That's about 12 passes over 1 MB, and nearly 250 passes over 50 KB. Read the same text 250 times and the text itself goes in before any rule does. This is why real LLMs collect trillions of tokens.
A pre-trained-only model doesn't know when to stop
A model fresh out of pre-training is called a base model. People say it can't hold a conversation, so I checked how badly, asking the same 5 questions to Qwen2.5-0.5B base and Instruct (the version trained further on following instructions). transformers 4.56.2, greedy decoding.
Honestly, I was surprised how much the base model answered. "How many legs does a spider have?" got "A spider has eight legs.", and it wrote a haiku too. My guess is that the web has so many Q&A pages that pre-training alone teaches a fair amount of the Q&A pattern.
The difference showed up elsewhere. Give the base model just the question line and after "What is the capital of Japan?" it writes "What is the capital of India?". It didn't answer; it wrote the next line of a quiz book.
In chat format (text marking whose turn it is, user or assistant), it's even clearer. Within 300 tokens, the base model stopped on its own for 3 of 5 questions; Instruct stopped for all 5. The base model wrote a Chinese poem instead of a haiku and then repeated "InlineData" endlessly. On the spider question it answered, then invented the user's next turn and said "That's correct!" to itself.
When to stop talking and whose turn it is don't come easily from guessing the next character. Teaching that is the job of fine-tuning and RLHF.
How big real LLMs are
GPT-3 trained 175 billion parameters on 300 billion tokens (2020 paper). Meta says it pre-trained Llama 3 on over 15 trillion tokens. Characters and tokens aren't the same unit, but that's on the order of ten million times this 1 MB of Shakespeare.
The well-known reference for balancing model size and data is the Chinchilla paper (2022). Its conclusion: for the same compute, grow the data as you grow the model. Chinchilla itself was 70 billion parameters on 1.4 trillion tokens, about 20 tokens per parameter. The 12.29 million characters this 826k-parameter model saw come to about 15 per parameter.
The 50 KB run saw the same number of characters. There were just only 50,000 distinct ones. It's not only the amount that matters; you need lots of text that doesn't repeat.
Does a company ever need to pre-train?
Almost never. Pre-training is the part you take from someone who already did it. Fitting a model to your work usually goes in this order.
The job only needs different instructions: a prompt. Cheapest.
It must answer with internal facts the model doesn't know: RAG. Look up the documents and feed them in.
It has to internalize a tone, an output format or a classification: fine-tuning or LoRA. Teach a little more on top of a pre-trained model.
Pre-training from scratch: only if you deal with a language or symbol system public models can barely read, and you can collect a very large amount of non-repeating text. Even a small 100M-parameter model needs 2 billion tokens at the Chinchilla ratio. Without enough text, like the 50 KB run, you just pay to build a model that memorizes.
If you're wondering whether you need to train a model from scratch on your own data, feel free to ask negabaro. Usually we start with a small experiment to see whether RAG or fine-tuning already does the job.
Key Concepts
Collect unlabeled text — the answer (the next character) is already in it
Cut the text into tokens and hold some out for testing (the last 10% here)
Start from random weights and repeat next-token prediction — loss on unseen text 4.33 → 1.53
Watch loss on seen and unseen text together — a widening gap means it's memorizing (50 KB: 0.10 vs 6.00)
Teach the finished base model to follow instructions and to stop — fine-tuning, RLHF