A Reference
for the Rest of Us!

The #1 guide for people who have never done it

Building Your OwnAI

FORDUMMIES

What the parts are, how they wire together, what data goes in, and what it costs. Written from a working build, including the parts that went wrong.

AI4DUMMIES · Book One

The wiringThe data mixThe training runWhat breaks

Most explanations of language models are either three equations or three hundred pages. This is the middle: enough to actually plan a build, decide what data you need, and know what you are looking at when the numbers on screen start moving.

No code here on purpose. Code goes stale and every framework spells things differently. The shape of the thing does not change, and the shape is what nobody explains.

What's in here
  1. What a language model actually is
  2. The parts, and what each one does
  3. Parameters: what people mean by "a billion"
  4. Size: picking your numbers
  5. Data: the part that decides everything
  6. The mix, in percentages
  7. Tokenizer: turning text into numbers
  8. The actual kit: what to install, where to get data
  9. The training run, start to finish
  10. Reading the numbers while it runs
  11. Personality: LoRA, fine-tuning, and not paying twice
  12. How much room each number takes
  13. What goes wrong

Chapter 1What a language model actually is

It predicts the next word. That is the whole job.

Everything else — answering questions, writing code, having a personality — falls out of doing that one thing extremely well over a very large amount of text. Nobody programs in "be helpful." You train next-word prediction, and helpfulness is a behaviour that emerges when the training text contains helpful exchanges.

This matters practically: you never write rules. If the model does something wrong, the fix is almost always in the data, not in a rule you add afterward. A hand-written rule is a patch over a hole in the training set.

The one sentence version A language model is a very large statistical guess about what comes next, refined billions of times against real text until the guesses get good.

Chapter 2The parts, and what each one does

A model is a stack of identical layers. Text goes in the bottom, comes out the top as a prediction. Each layer does the same two jobs.

Job one: attention (looking around)

Attention lets every word look at the other words and decide which ones matter. In "the dog that chased the cat was tired," attention is what connects "tired" back to "dog" and not to "cat." Without it a model only sees the previous word or two, which produces text that is topically right and grammatically scrambled.

Job two: the feed-forward block (thinking about it)

After looking around, each word gets processed on its own through a small expansion-and-contraction. This is where most of the model's actual stored knowledge lives — roughly two thirds of the parameters.

The supporting cast

PartWhat it doesWhy you care
Embedding tableTurns each token into a list of numbersThe model's vocabulary lives here
Position informationTells the model word orderWithout it, sentences are just word bags. Modern builds use rotary positions (RoPE)
NormalisationKeeps numbers in a sane range between layersSkip it and training explodes. RMSNorm is the current default
Output headTurns the final numbers back into "which word next"Where the actual prediction pops out
Worth knowing Grouped-query attention (GQA) lets several attention heads share the same lookup data. It cuts memory noticeably at almost no quality cost, and it is why a modern model of a given size runs on smaller hardware than one from a few years ago.

Chapter 3Parameters: what people mean by "a billion"

You hear that a model "has 7 billion parameters" and it sounds like a filing cabinet with 7 billion facts in it. It is not. It is closer to 7 billion dials.

Picture an old mixing desk, the kind with rows of knobs. Sound goes in one end, comes out the other, and every knob nudges what happens in between. Nobody labelled the knobs. Nobody decided what any single one does. You just turn them until the output sounds right.

A parameter is one of those knobs. It is a single number, usually something small and unremarkable like 0.0384 or -1.27. On its own it means nothing at all, and you cannot look at one and say what it is for.

So who turns them?

Nobody. That is the whole trick, and it is the part people find hardest to believe.

Training is a loop that runs millions of times:

  1. Show the model some real text with the next word hidden.
  2. Let it guess.
  3. Compare its guess to the actual word.
  4. Nudge every dial a tiny amount in whichever direction would have made that guess better.
  5. Do it again with different text.

Step 4 is the whole of machine learning. The nudge is tiny on purpose — far too small to fix the current mistake. It is not meant to. Each nudge is a fraction of a correction, and the model only becomes good because it gets billions of them, from billions of different sentences, and the pressures that keep pointing the same way accumulate while the random ones cancel out.

Nobody chooses what any dial means. Meaning arrives on its own: some dials end up tracking whether the subject is plural, some end up caring about the tone of a sentence, some do jobs nobody has a word for. You do not assign these roles and you cannot read them off afterward. They emerge because they were useful for guessing the next word.

Two different kinds of number This is worth keeping straight, because both get called "settings":

Parameters are the dials the model turns itself, during training. Billions of them. You never touch these.

Hyperparameters are the handful you set before you start — learning rate, batch size, how many layers. Maybe a dozen. These are the ones you can get wrong, and Chapter 8 is about them.

Why more dials is not automatically better

More dials means more capacity to represent things. It also means more dials that need enough examples to settle sensibly. Give a model 600 million dials and only a few million sentences to learn from, and most of those dials never receive enough pressure to point anywhere useful — they end up memorising the training text rather than learning language.

That is the ratio in the next chapter, and it is the reason a small well-fed model beats a large starved one.

Chapter 4Size: picking your numbers

Four dials decide how big your model is:

Real configurations from a working build, so these are not invented:

NameWidthLayersContextRuns on
tiny2566256A phone, no graphics card
small5128768Any gaming PC
large1536241024One good graphics card (~600M parameters)
Learned the hard way Bigger is not automatically better. A big model trained on too little data is worse than a small model trained on plenty. There is a rough ratio — call it 20 words of training text per parameter. A 600M model wants somewhere north of 10 billion words to earn its size. If you cannot feed it, build smaller.

Chapter 5Data: the part that decides everything

This chapter matters more than the rest combined. The architecture is nearly a solved problem you can copy. The data is where your model becomes good or stays useless, and it is where nearly all the real work goes.

The trap nobody warns you about

The easiest text to get legally is old — public-domain books, out-of-copyright encyclopedias. It is free, it is clean, and it will give your model the voice of a Victorian gentleman. It will not know what a phone is. Everything it says will sound like 1890 because it is 1890.

You need modern text, and you need conversation, and those are different problems from getting text at all.

The kinds of data, and what each buys

TypeWhat it teachesWatch out for
Filtered web textModern language, current concepts, rangeUse a quality-filtered set, not raw scrape. Raw web is mostly garbage
BooksLong-range structure, narrative, real paragraphsAge. Cap the old stuff or it dominates the voice
Conversation / dialogueTurn-taking, answering rather than continuingWithout this it monologues instead of replying
Reference (dictionary, encyclopedia)Facts, definitions, vocabulary breadthDense and repetitive. A little goes a long way
CodeStructure, logic, precision — helps reasoning even if you never want code outOptional, but cheap gains
Instructions (task then response)Doing what it is toldUsually a later stage, not the main run

Quantity, honestly

Text is measured in tokens, roughly three-quarters of a word each. A useful yardstick: a full-length novel is about 120,000 tokens. So one billion tokens is around 8,000 books.

Chapter 6The mix, in percentages

Ratios matter as much as volume. A defensible starting mix for a general conversational model:

ShareSourceWhy this much
60–70%Quality-filtered modern webThe backbone. Sets the register as contemporary
15–20%BooksTeaches structure longer than a paragraph. Cap it — this is the Victorian-voice risk
8–12%ConversationThe difference between a model that answers and one that rambles
3–5%ReferenceVocabulary and facts, without letting dictionary cadence take over
0–10%CodeOptional. Improves structured reasoning
A real mistake, worth stealing Filtering a corpus to remove a specific name, we deleted every document containing it. That silently destroyed the entire conversation set — 158,000 exchanges gone, because that name appeared in nearly every one. Out of a 14-million-token budget, 2,045 tokens survived.

The fix was to substitute the word rather than drop the document, which kept the turn-taking intact. Always count what survives your filter. A filter that quietly eats 99% of a category looks exactly like a filter that worked.

Chapter 7Tokenizer: turning text into numbers

Models cannot read letters. A tokenizer chops text into pieces and assigns each a number. Pieces are usually chunks of words: "unhappiness" might become "un" + "happi" + "ness."

Decisions that matter:

Chapter 8The actual kit: what to install, where to get data

Everything so far is the shape of the thing. This is the shopping list: names, what each one is for, and where it lives.

The one non-negotiable piece

PyTorch is what nearly everyone trains in. It runs the maths on the graphics card and, critically, works out the nudge for every single dial automatically, so you never write that part yourself. If you install one thing, this is it. Match the version to your card's CUDA release; the site gives you the exact command.

The alternative is JAX, which is genuinely good and common in research. But the tutorials, the example code and the answers to your questions are overwhelmingly PyTorch. Start where the help is.

Things you do not have to write yourself

WhatDoesWhere
TransformersModel architectures, ready-built — and worth reading, the code is unusually clearhuggingface/transformers
tokenizersTrains and runs the text-to-numbers stephuggingface/tokenizers
SentencePieceThe other standard tokenizer, used by many well-known modelsgoogle/sentencepiece
datasetsDownloads and streams big corpora without filling your diskhuggingface/datasets
AccelerateMulti-card and mixed-precision plumbinghuggingface/accelerate
PEFTLoRA and friends — see Chapter 11huggingface/peft
bitsandbytesShrinks a finished model for runningbitsandbytes
TensorBoard or Weights & BiasesDraws the loss curve, so you see the trend instead of one jumpy linetensorboard / wandb.ai

Where the data actually comes from

This is the part that is hardest to find written down anywhere, and it is the part that decides whether your model is any good.

SourceWhat it isRough size
FineWeb-EduWeb text filtered for educational quality. Modern register. The best single starting point1.3T tokens — take a slice
FineWebThe larger sibling, not education-filtered15T tokens
DolmaOpen corpus with a documented mix and permissive terms3T tokens
RedPajamaOpen reconstruction of a well-known training mix1T tokens
The Pile (uncopyrighted)Long-standing mixed corpus, academic and technical heavy~400B tokens
Project GutenbergPublic-domain books, free and clean. This is the Victorian-voice trap from Chapter 5 — cap it. Bulk mirror at the offline catalogues~75,000 books
Wikipedia dumpsFacts and clear expository prose. Simple English is a good small start; extract with wikiextractor~4B tokens (English)
The Stack v2Permissively-licensed source code, if you want the reasoning boost~900B tokens
UltraChat, Alpaca, OpenAssistantConversation and instruction data — the turn-taking without which it monologuesHundreds of thousands of exchanges
Internet Archive texts, WikisourceReference works, old encyclopedias, dictionaries. Same age caveat as GutenbergMillions of items
Downloading, the hard-won note Big datasets arrive as many compressed shards. Download each one whole, then verify it before accepting it. Some content servers ignore a request to resume a partial download and hand back the entire file again — if you are appending to what you already have, that silently produces a corrupt double-length shard that looks fine until training chokes on it days later. This cost us six files and a night.

Code worth reading before writing your own

Hardware, honestly

You haveRealistic target
No graphics cardRead nanoGPT and run a tiny model on the processor to watch the loop work. Do not try to train anything real
8 GB cardA small model (Chapter 4). Genuinely coherent output is reachable
16–24 GB cardSeveral hundred million dials. This is where it gets interesting — and it is an ordinary gaming card
Rented cloud hoursSensible for one long run. Rent before buying hardware to find out whether you enjoy this

Memory matters more than speed. A slower card with more of it beats a faster card that cannot hold your model.

When it breaks

Chapter 9The training run, start to finish

  1. Gather and clean — deduplicate, strip junk, fix encoding. Slow, unglamorous, decides your outcome.
  2. Train the tokenizer on a sample of the final mix.
  3. Pack — convert all text to token numbers in one big file. Do this once; doing it per-run wastes hours.
  4. Smoke test — 50 steps at full size. Catches memory blowups before you have burned a night.
  5. Train — the long part. Hours to weeks.
  6. Fine-tune — shorter runs on specific data to add behaviour or personality.
  7. Shrink and ship — compress for the target device.

The knobs during training

KnobPlain meaningPractical note
Learning rateHow big a correction each step makesThe one most likely to ruin a run. Too high and it diverges; too low and it crawls
Batch sizeHow much text per stepBigger is steadier. Limited by memory
Gradient accumulationFaking a big batch on small hardwareHow consumer cards train serious models
WarmupStarting gently before full speedSkipping it is a classic early-blowup cause
StepsHow many rounds totalWith batch size, decides how many times it sees your data

Chapter 10Reading the numbers while it runs

A training run prints a line every few seconds. It looks like this, and this one is real:

step 2457/3000  lr 5.27e-05  loss 2.550  140,221 tok/s

What loss values mean

LossReality
10+Random. Just started, or something is broken
4–6Learning letter and word patterns
2.5–4Real grammar appearing
1.5–2.5Coherent for a small model
Under 1.5Strong — or you are memorising, check against held-out text
Normal, do not panic Loss bounces between steps. One line reading 1.9 and the next 2.5 is fine — different batches are different difficulties. Watch the trend across hundreds of steps. A flat line for thousands of steps is a real problem; a jumpy line is just training.

Chapter 11Personality: LoRA, fine-tuning, and not paying twice

You have a base model. It writes decent English and has no self. Now you want a character — a support agent, a narrator, someone with a voice. There are three ways to do that and they cost wildly different amounts.

1. Just ask it (prompting)

Put "you are a helpful pirate" at the front of every conversation. Free, instant, changes nothing permanent. It also eats context space, and the character drifts as the conversation gets long, because nothing about the model actually changed.

Fine for trying an idea. Not how you ship a character.

2. Full fine-tuning

Keep training the whole base model on text in your character's voice. Every dial is still free to move, so the voice sinks in properly.

The catch is cost: you need memory for every dial plus the optimiser's bookkeeping for every dial, which is typically several times the model's own size. And you get a whole new model per character. Ten characters, ten full copies.

It is the right call when you have one character and enough memory. Our own runs do exactly this: the base is trained once over hours, then each character is a short run of a few hundred steps starting from a copy of it — about twelve minutes each, because the grammar is already paid for and only the voice has to move.

3. LoRA — the one most people should use

LoRA stands for Low-Rank Adaptation, and the idea is better than the name.

Rather than adjusting the model's millions of dials, you freeze all of them and bolt a small extra set of dials alongside. Only the small set trains. At runtime the model's original output and the little add-on's output are added together, and the result behaves like a model that learned your character.

Why it works: the change from "general English" to "this specific voice" is a much simpler change than the model itself. It does not need millions of free dials to express. A few million will carry it.

Full fine-tuneLoRA
Dials being trainedAll of themTypically well under 1%
Memory neededLarge — often several times the modelA fraction of that
What you end up withA whole new modelA small file, often a few MB
Ten charactersTen full modelsOne model, ten small files
Swapping between themLoad a different modelSwap the add-on, keep the model loaded
Depth of changeAnything, including new knowledgeVoice, style, format — excellent. New facts — weaker

The practical dial in LoRA is its rank — how many extra dials you allow. Small (8–16) is plenty for a voice or an output format. Larger (32–64) if the behaviour is more involved. Bigger is not better here either; too large and it starts memorising your examples instead of learning the pattern.

PEFT implements this and it is a handful of lines to wire in. The original paper is readable. QLoRA combines it with a shrunk base model so you can adapt a large model on modest hardware.

What to feed it

Far less than you would guess. A few hundred to a few thousand examples in the voice you want, and quality beats quantity every time — a hundred sharp examples beat ten thousand mediocre ones.

Write them in the shape the model will actually be used in. If it will answer questions, write questions and answers, not prose about the character. The model learns the form as much as the content, which is why a character trained only on monologue will monologue at you forever.

The trap that got us A character fine-tune inherits everything in the base, including identity. Our base corpus contained roughly 56,000 mentions of an earlier model's name plus its biography. Every character built on top claimed to be that model when asked sideways — not to "who are you", which answered correctly, but to "what was your name before".

Keep the base free of identity, and test by trying to break it rather than by asking the easy question. And when you filter the name out of your corpus, substitute it rather than deleting whole documents — see the disaster in Chapter 6.

Which to pick

Chapter 12How much room each number takes

Every one of those billions of dials has to be stored somewhere, and each takes up a certain amount of memory. That size is the single biggest reason serious AI has needed rooms full of expensive hardware.

Think of it as how many decimal places you keep. A number stored generously might be 0.038471629. Stored leanly it becomes 0.038. Same number, less room, slightly less exact. Cut the storage in half and your model is half the size. Cut it to a quarter and a model that needed four graphics cards now needs one.

The two places precision matters, and they are not the same

People conflate these constantly, and the difference is the whole story.

Shrinking a finished model is easy and everyone does it. Train it generously, then round all the dials down afterward. This is called quantization. It works well, it is well understood, and it is why you can run a capable model on a laptop.

Storage per dialA 600M modelQuality after rounding
Generous (16-bit)~1.2 GBThe reference
Half (8-bit)~600 MBEssentially identical
Quarter (4-bit)~300 MBSlightly worse, usually fine

Training in low precision is a different problem entirely, and it is genuinely hard.

Remember that each training nudge is tiny — deliberately far smaller than the error it is correcting. Now store the dial with very few decimal places. The nudge is smaller than the smallest change that storage can represent. So the dial receives the nudge and does not move. Then it happens again. And again.

The model stops learning entirely. Not slowly, not badly. It sits there while the training loop runs, and the numbers never change. Everyone hits this, which is why nearly all training happens at generous precision and the shrinking is saved for the end.

The thing worth understanding If a model could be trained at quarter size rather than merely stored that way, everything changes: the memory needed for the run drops by the same factor, and that memory is exactly what forces serious training onto datacenter hardware. It is not about the file being smaller. It is about what fits on the card while it is learning.

It has been done, on a gaming card

This is not hypothetical. A hardware manufacturer published work getting most of the way there on their own datacenter equipment, and their paper ended by listing what remained unsolved — getting the whole model down to the small format without training falling apart.

That remaining part has since been done, on a consumer graphics card of the sort people buy to play games, in a house. The published techniques did not transfer; what was actually killing the training turned out to be something not previously written down, and fixing that was the work.

The result that matters is not the smaller file. It is this: because everything takes less room, a bigger model fits on the same card — and the bigger model trained in the lean format outperformed the best smaller model trained the generous way.

So it is not a tradeoff where you accept a worse model to save money. Same hardware, better result.

What this chapter does not contain How. The specific method is proprietary and is not described here, and no amount of reading between these lines will reconstruct it. What is public and worth knowing is the shape of the problem: small nudges vanish into coarse storage, and that is what stops low-precision training from working. Anyone attempting it will meet that wall.

Chapter 13What goes wrong

SymptomUsual cause
Loss goes to NaNLearning rate too high, or no warmup
Loss flat from the startLearning rate near zero, or data not actually loading
Output is word saladUndertrained, or too little data for the size
Sounds antiqueCorpus is all old public-domain text
Rambles, never answersNo conversational data in the mix
Repeats one phrase foreverNeeds a repetition penalty at generation time
Claims to be a different modelIdentity leaked in from the base corpus
Out of memory immediatelyBatch or context too large. Cut batch, raise accumulation
Great on training text, bad on new textMemorising. More data, or fewer passes over it
The habit that saves the most time Measure before you change anything. The temptation is to guess a cause and patch it, and each guess is cheap for you and expensive in wall-clock. Prove the cause moves the symptom before committing to a fix — we lost a night to a "speedup" that turned out to touch code that ran barely a tenth of the time.

If you are starting today

  1. Build the small config, not the large one. Get all the way through the pipeline once.
  2. Gather 1 billion tokens in roughly the Chapter 5 mix.
  3. Train until loss is around 2.0, then look at what it says.
  4. Fix the data, not the architecture. That is where the improvement is.
  5. Only then go bigger.