ManiMage.ai

How language models work

From next-word prediction to the full Transformer — tokens, embeddings, attention, the MLP, training — then what turns it into a chat assistant.

20 stops34 min

The lessons, in order

  1. What a language model actually does

    One job: guess the next word. Probabilities over every word, sample, append, repeat.

    1min1:28

  2. Tokens and embeddings

    Text becomes tokens, tokens become vectors. Similar words cluster; directions carry meaning.

    1min1:27

  3. The problem attention solves

    “River bank” and “bank deposit” start from the identical vector. Meaning must come from neighbors.

    1min1:19

  4. The only math you need

    Dot product = similarity meter. Matrix × vector = a stack of learned questions. The model IS the matrices.

    2min2:07

  5. Neural networks

    multiply, add, bend

    A neuron multiplies, adds and bends. Stack layers of them into a neural network: one function, set by its weights and biases.

    2min2:27

  6. Attention: words talking to each other

    Queries, Keys, Values. Scores → softmax → weighted sum. Watch softmax(QKᵀ/√d)·V happen.

    2min2:15

  7. Multi-head attention + the MLP

    Many heads track many relationships; each token thinks alone in the MLP, where facts live.

    2min1:50

  8. The whole Transformer, assembled

    Embed → (attend + think) × 96 → unembed → probabilities. The box, opened; the loop, closed.

    2min1:31

  9. Mixture of Experts (MoE)

    Replace the one big MLP with many experts plus a router picking the top 2. 47B stored, ~13B paid.

    2min1:37

  10. Tokenization and BPE

    Byte-Pair Encoding merges its way to a vocabulary — and why models can't count the r's in strawberry.

    2min1:54

  11. Supervised learning

    examples with answers

    A line learns house prices from labeled examples, then faces houses it never saw. Text, it turns out, labels itself.

    2min2:24

  12. How the matrices get filled in

    Weights start as noise. Guess, measure surprise, nudge downhill — trillions of times.

    2min1:50

  13. How the model knows word order

    Attention is order-blind. Position fingerprints and RoPE put the sequence back.

    Also rests on Sine and cosine Calculus

    2min1:41

  14. No peeking: causal masking

    Mask the upper triangle so the future never leaks — and one sentence trains every position at once.

    1min1:14

  15. The KV cache

    what context costs

    Keys and values get cached; every new token reads a longer shelf. The n² cost, and why long chats slow down.

    1min1:17

  16. Pretraining

    the internet as flashcards

    Every prefix is a question, the next word is the answer. The result: an autocomplete, not an assistant.

    2min1:34

  17. From autocomplete to assistant (RLHF)

    Fine-tuning teaches the format; human preferences train a reward model that shapes behavior.

    2min1:35

  18. Temperature

    how models choose

    Greedy loops and drones. Temperature sharpens or flattens; top-p cuts the weird tail.

    2min1:31

  19. Scaling laws

    why bigger got better

    Loss vs compute is a straight line on log scales; abilities switch on in jumps.

    1min1:20

  20. Opening the black box

    Heads with jobs, single-concept neurons, superposition — the interpretability frontier.

    2min1:46