CodeBaobab
COURSE 12 OF 21

LLM Foundations

Understand what a language model actually computes, so the cost, latency, and failure modes of an LLM feature stop being surprises.

Background reading
Free course preview

Introduction to Large Language Models

A large language model learns statistical patterns in token sequences and uses those patterns to predict what token may come next. Repeating that prediction one token at a time produces a longer response.

Give the model the text “The sky is”. Its immediate task is not to write a whole paragraph. It assigns a probability to every token that could come next, such as “blue”, “clear”, or “falling”.

The tokenizer first converts the text into token IDs. An embedding table turns each ID into a vector, and the Transformer updates those vectors by passing them through attention and feed-forward layers.

At the final position, a linear layer produces one score for every vocabulary token. Softmax converts those scores into probabilities. The system selects one token and appends it to the text.

The model then repeats the same process with the longer text. This is autoregressive generation: every new token depends on the tokens already present, so output tokens must be produced in order.

P(xt=v∣x<t)=[softmax⁡(Wht)]v=exp⁡ ⁣((Wht)v)∑u∈Vexp⁡ ⁣((Wht)u)P(x_t=v\mid x_{<t})=\big[\operatorname{softmax}(Wh_t)\big]_v=\frac{\exp\!\left((Wh_t)_v\right)}{\sum_{u\in\mathcal V}\exp\!\left((Wh_t)_u\right)}
Continue learning

Continue with Pro

Get Pro on codebaobab.com.

See Pro plans
Complete course

What you will learn next

  1. 01Tokenization
  2. 02Embeddings and Semantic Similarity
  3. 03Attention and the Transformer Block
  4. 04Encoder, Decoder, and What an LLM Keeps
  5. 05Inside the Transformer Block
  6. 06Mixture of Experts
  7. 07The Context Window and the KV Cache
  8. 08Sampling and Decoding
  9. 09Quantization
  10. 10Adapting a Model Without Retraining It
  11. 11Choosing the Intervention
  12. 12Learning BPE Merge Operations
  13. 13Example 1 — Size the KV Cache Before Promising a Context Length
  14. 14Example 2 — Compare Three Decoding Rules
  15. 15Example 3 — Trace the LLM.int8() Decision
  16. 16Review
  17. 17References