A model is what it eats
A small model that only reads children's stories won't answer support questions about printers. A model that only sees question-and-answer tables might learn the format, but hardly any general language. Very simply: what isn't in the data, the model can't learn. That makes the data just as much part of the model as its blueprint.
When you build your own model in part VII, you train on TinyStories: about 5.5 million tokens of simple children's stories, made specifically for small language models. Enough for a small model to learn to write, far too little to know much about the world. That shows this chapter's rule in action: your model will sound like a children's book because it only knows children's books.
Split first, then slice
This is where the nastiest trap of the chapter lurks. Imagine you slice a novel into overlapping text windows and distribute them randomly between training and testing. Then almost identical sentences end up in both piles. The model already “knows” the test, and the grade looks much better than it really is.
That is why there is a fixed order:
- Read in the raw documents.
- Remove exact duplicates.
- Split whole documents into training and validation.
- Learn the tokenizer only on the training documents.
- Only then cut both sets into tokens.
For a real publication you even need a third set, the test set. You only look at it at the very end, like a final exam you weren't allowed to practice for.
The split uses a seed, the starting number of a random number generator. Same seed, same “random” split. That way you can repeat your experiment exactly at any time.
A simple file format
Many projects store their training data in the JSONL format. JSON is a common text format for structured data; JSONL (“JSON Lines”) simply means: one entry per line, here one document per line.
{"text":"Lina finds a small key. She looks for the matching door."}
{"text":"A thunderstorm forms when moist air rises strongly."}The advantage: every document has clear boundaries. One single giant text file would be much harder to split cleanly. You can easily bring your own texts into this format.
You program exactly these steps yourself in step 2 of part VII: load, clean, split first, then learn the tokenizer. There every story has clear boundaries, without JSONL.
Where do the texts come from? Write it down!
For every source, note: origin, language, date, license or right of use, number of documents, approximate token count, which filters you applied and what you know about its weaknesses. Such a profile is called a corpus manifest. Whether you may use other people's texts depends on the source and the purpose; this book can't answer that across the board.
Very important: no personal data and no secrets in training! Small models in particular like to memorize texts and spit them out again later. Passwords, private messages or customer data have no business in training material. Filter them out with clear rules and check samples.
Good data is more than correct spelling
A text can be grammatically perfect and still contain wrong facts. Or half of a corpus consists of nearly identical advertising copy. Simple checks find empty texts, strange characters, endless repetition and exact duplicates. Finding slightly altered copies or wrong facts, on the other hand, is a big topic of its own.
For your learning project: do what you can, and honestly write down what you didn't check. A simple cleanup is not “complete quality control”.
Chaining documents together
In pretraining we append an EOS token after every document and lay all documents end to end into one long chain of tokens. From that we then cut random windows. A window can reach across a document boundary; then the model sees the end of story A and the beginning of story B. It learns the EOS in between as a signal for “something new starts here”.
This is deliberately kept simple. Anyone who wants to seal documents off from each other completely needs more complicated masks. For our project chaining is enough; you should just know that this is how it works.
Before training: look inside!
Sounds trivial, but saves days: turn twenty random training windows back into text and read them. Are the umlauts intact? Are there empty documents or JSON leftovers? Are the EOS boundaries where they belong? Then show the input and target of the same window side by side: is the target really shifted by exactly one token? Only then start the long run.
Count tokens instead of “epochs”
We draw training windows at random. An “epoch”, a complete pass through all the data, is then no longer a clear concept. That is why our trainer counts steps and processed tokens. With a small corpus, every example gets repeated very often. More steps then don't mean more knowledge; the model just keeps cramming the same texts.
In the experiment
The view shows how whole documents are distributed between training and validation with a fixed seed, and why slicing before splitting breaks the separation. It doesn't compute a quality score for your real data; it only makes the order visible.
Key points
- The model can only learn what is in the data. Data is part of the blueprint.
- First split whole documents into training and testing, then slice; otherwise the test cheats.
- Document where data comes from, keep private data out, read samples yourself before training.