Tabellab
AI & Data Science Intermediate

How Language Models Work by Hand: Tokens, Embeddings, Attention Weights, Softmax & Sampling with Temperature

Open up a tiny language model in a spreadsheet: token ids, embedding lookups, positional signals, attention scores, softmax and next-token sampling with temperature, with every cell checked as you go.

8 lessons 8 labs 2.1 h Certificate

One-time payment · lifetime access · lessons, labs, exam and certificate included · no subscription.

About this course

This course opens up a toy language model cell by cell. You split a prompt into tokens and look up their ids, read 4-dimensional embedding vectors with INDEX and compare tokens with dot products, and add sine and cosine position signals. With small weight tables and SUMPRODUCT you compute queries, keys and values, score every token against every earlier one with q · k ÷ √d, apply a causal mask and softmax, and mix the values into the attention output. Finally you turn logits into next-token probabilities with temperature, compare greedy, top-k and sampled choices, and see why long prompts cost more tokens, more scores and more memory.

Lessons

  1. Tokens: Splitting a Prompt, Vocabulary Ids & Token BudgetsLab14 min Pro
  2. Embeddings: Looking Up Token Vectors & Dot ProductsLab15 min Pro
  3. Positional Signals: Sine & Cosine Waves Added to EmbeddingsLab16 min Pro
  4. Queries, Keys & Values: Weight Tables and SUMPRODUCTLab16 min Pro
  5. Attention Scores: Scaling by √d, the Causal Mask & Softmax per RowLab18 min Pro
  6. Weighted Values: The Attention Output & Which Token Looks WhereLab15 min Pro
  7. Next-Token Probabilities: Temperature, Greedy Choice, Top-k & SamplingLab16 min Pro
  8. Context Length: Re-Sent History, Turn Costs & Why Long Prompts Weigh MoreLab16 min Pro