Draft Work in progress. Content and links may change without notice.
Free512-page book · 34 decks · no signup, no paywall

Machines do not read.
Here is what they do instead.

Every chatbot you've used is built on a handful of ideas you can learn in a weekend. Start at "what even is a word" and finish at "I know why attention works." No black boxes.

Written by Ramaseshan Ramachandran

7units, in order
512pages of book
34slide decks
1,633pages of slides
15things to break in the lab
The path

Seven units. Each one earns the next.

Do them in order and nothing arrives out of nowhere. By the time you hit transformers, every piece of the diagram is something you already built.

01

Words are weirdly predictable

Text and its regularities

Before any model, look at the raw material. A handful of words do most of the work in any language, vocabulary grows in a shape you can predict, and "how do I even cut this string into pieces" turns out to be a real research problem.

02

Turning words into numbers

Representing words

Models can't read letters, only numbers. The trick that changed everything: a word's meaning is the company it keeps. Count what appears near what, squeeze it down, and you get vectors where directions mean things, including the ugly ones.

03

The math that learns

Neural foundations

One neuron is a line that splits a plane. Stack them and you can carve any shape. Then the only real question left: how does a pile of numbers know which way to move? That's gradient descent, and backprop is just the chain rule with good bookkeeping.

PerceptronsDecision boundaries ActivationsLoss functions Gradient descentBackpropagation Feedforward netsGeneralization
04

Guessing the next word

Language models and sequences

This is the whole job. Count word pairs and you have a language model. A bad one, but a real one. Everything after this is a better way to answer the same question, with memory that survives longer than three words.

05

Attention is the whole trick

Transformers and LLMs

Instead of reading left to right and hoping you remember, let every word look at every other word at once and decide what matters. That's it. That's the idea the entire modern field is standing on.

06

Making LLMs do what you want

Working with LLMs

The part everyone skips to. Except now you'll know why any of it works. Why temperature changes the vibe, why LoRA is cheap, why RAG beats fine-tuning for facts, and why BLEU scores are argued about.

07

Who gets hurt when it's wrong

Responsible NLP

Models learn the patterns in their training text. All of them, including the ones nobody wanted. This unit is about finding that bias with the same maths you used to build the thing, and knowing what you can actually do about it.


The book

The whole thing, written down properly.

512 pages that go where the slides can't: the derivations, the worked examples, and eight projects you actually build. Reads in the browser. No download, no app. The slides are eight years of lectures, and they were the outline the book grew from.

  1. 5 chaptersPart I

    Language as Data

    What Natural Language Processing Is · Corpora and Preprocessing · The Empirical Laws of Text · Term Weighting and Similarity · Subword Tokenisation

  2. 4 chaptersPart II

    Meaning as Geometry

    Vector Space Models · Count Vectors, PPMI, and SVD · Neural Network Fundamentals · Learned Word Embeddings

  3. 6 chaptersPart III

    Language Models

    n-gram Language Models and Perplexity · Neural Language Models · Recurrent Networks · Gated Recurrence: LSTM and GRU · Machine Translation · Text Classification and Evaluation

  4. 4 chaptersPart IV

    The Transformer Era

    Contextual Embeddings · Self-Attention and the Transformer · A Transformer You Can Check By Hand · Pretrained Transformers: BERT and GPT

  5. 6 chaptersPart V

    Working with Large Language Models

    Steering LLMs: Decoding and Prompting · Adaptation and Alignment · Retrieval-Augmented Generation · Evaluating Generated Text · Building with Language Models · Efficiency: Smaller, Cheaper, Faster

  6. 1 chaptersPart VI

    Applications

    Summarisation

  7. 1 chaptersPart VII

    Responsible Practice

    Responsible NLP

  8. 9 chaptersPart VIII

    Projects

    About the projects · Project 1: The Shape of Language · Project 2: Build the Tokenizer · Project 3: Embedding Forensics · Project 4: Language Models · Project 5: A Genre Classifier · Project 6: Transformer Anatomy · Project 7: Steering Language Models · Project 8: A Retrieval System, Audited

  9. PDF · p475Part IX

    Appendices: Reference Implementations

    n-gram Language Model · Scaled Dot-Product Attention · Embedding Geometry · Decoding Mechanics · BM25 Retrieval · Glossary · Bibliography


The code

Every worked table, as a script you can run.

The book counts, smooths and multiplies by hand so you can see it happen. These are the same numbers, in Python you can change. Open one in Colab, or download it and run it on your laptop.

Browse all 28 worked examples → 28 scripts · runs in Colab or on your laptop

The labs

Poke at the ideas with your hands.

Four live demos run right here, and eleven more labs are one click away. All of it runs in your browser, with no server and no model download. Drag the sliders until something breaks. That's the point.

Where do words even end?

Models don't see words. They see tokens. Byte-pair encoding starts from single characters and repeatedly glues together whichever pair shows up most often. Drag the slider to run more merges and watch letters fuse into chunks that look suspiciously like morphemes. This is really training BPE, live, on the text in the box. The faint ▁ marks where a word starts, and a pair is only merged if it occurs at least twice, so a word seen once stays split into several tokens.

Final tokens

·vocab size
·tokens produced
·chars per token
Why it matters: a model reads text as a sequence of tokens, and the vocabulary size is the number of different tokens it knows. It is a trade-off. With a small vocabulary, words break into many short tokens, so every text becomes a longer sequence of tokens and the model has to put each word back together. With a large vocabulary, a text needs fewer tokens, but the embedding table grows and rare tokens are seen too seldom to learn well. Models like GPT use about 50,000 to 100,000 tokens, so a common word is usually one token and a rare word is a few tokens.
Eleven more: watch a bag of words lose the word order, a HAL or COALS matrix fill one target word at a time, or edit distance fill its table cell by cell. Then play with decoding, attention, retrieval, smoothing and perplexity, a classifier threshold, the vanishing gradient and alignment. All labs →

Jargon decoder

Words people say without explaining.

Every one of these gets a proper treatment somewhere in the decks. This is just so you're never lost in a thread.

Token

The chunk a model actually sees. Usually not a whole word. "unhappiness" might arrive as un + happi + ness. Everything is priced and limited in tokens.

Embedding

A list of numbers standing in for a word, sentence or document, arranged so similar meanings sit near each other. Usually a few hundred numbers long.

Corpus

A pile of text you're learning from. Plural: corpora. The single biggest lever on how a model behaves, and the least glamorous part of the job.

Softmax

Turns any list of scores into probabilities that add to 1, with the biggest score getting the biggest share. It's how a model converts "I like this word 8.2" into "42% chance".

Perplexity

How surprised a language model is by real text. Lower is better. Perplexity 20 means it was about as unsure as picking uniformly between 20 options at each word.

Attention

Each token looks at all the others and computes a weighted average of them, weighted by relevance. Repeat a few dozen times, and that's a transformer.

Transformer

The architecture underneath basically everything since 2017. Attention plus small feedforward layers, stacked, with no recurrence, which is why it trains fast on GPUs.

Temperature

A knob on randomness when generating. Low = repetitive and safe. High = creative then incoherent. It literally divides the scores before softmax.

Fine-tuning

Taking a trained model and nudging its weights on your own data. Expensive at full size, which is why LoRA exists.

LoRA

Freeze the big model, train two tiny matrices alongside it. You get most of the benefit of fine-tuning for a fraction of the memory. The "PEFT" family.

RAG

Retrieval-augmented generation: search your documents first, paste the hits into the prompt, then answer. How you give a model facts it was never trained on.

RLHF

Humans rank model outputs, a reward model learns those preferences, then the model is tuned to score well. It's what makes a raw LLM feel like an assistant.

BLEU

An old translation metric that counts overlapping word sequences with a reference translation. Widely used, widely complained about, still the default.

Zipf's law

Word frequency is inversely proportional to rank. A handful of words are everywhere and most words are almost nowhere. See the lab.

Hallucination

Fluent, confident, wrong. Not a bug bolted on. It is a direct consequence of a model whose only training objective was "sound like the next word".

Context window

How many tokens the model can look at in one go. Anything outside it doesn't exist, no matter how important you thought it was.


Start here

What you need before unit 01.

Python you can read, not write fluently

Lists, loops, dictionaries, functions. If you can write a word counter, you're fine. You'll pick up NumPy along the way.

School maths, honestly

Vectors, dot products, a bit of probability. Derivatives help by unit 03 but the slides build them up rather than assuming them.

No GPU, no cloud bill

Everything through unit 04 runs on a laptop. Colab's free tier covers the rest if you want to train something.

Do the lab as you go

Read the unit, then come back here and break the matching demo. Units 01, 02 and 04 each have one waiting.

Open unit 01.

Fifteen pages. Twenty minutes. You'll know what the field is actually asking.