← Back home

Data · tokenization · architecture

Build the base model,
one contract at a time.

15 chapters

Move from text representation and data design to architecture, sparse experts, optimization, distributed training, and reproducible evidence.

See every chapter

Pre-trained / 15 chapters

How foundation models learn

Fifteen focused chapters connect the data, mathematical, architectural, and systems decisions behind a base language model.

  1. 01
    Chapter 01 · 13 Aug 20266 min read

    What a Language Model Learns

    Token representations, autoregressive factorization, teacher forcing, cross-entropy, and the limits of next-token prediction.

    Read
  2. 02
    Chapter 02 · 13 Aug 20268 min read

    From Unicode to Byte-Pair Encoding

    Code points, UTF-8 bytes, merge learning, vocabulary construction, compression, and exact encode–decode behavior.

    Read
  3. 03
    Chapter 03 · 13 Aug 20267 min read

    Corpus Design and Data Lineage

    Source registration, parsing, filtering, deduplication, decontamination, mixture weights, document boundaries, and immutable shards.

    Read
  4. 04
    Chapter 04 · 13 Aug 20265 min read

    Batches, Tensor Shapes, and Shifted Targets

    Turn token streams into input–target windows, track batch and sequence dimensions, mask invalid positions, and prevent split leakage.

    Read
  5. 05
    Chapter 05 · 13 Aug 20265 min read

    The Transformer Residual Stream

    Follow embeddings through encoder, decoder, and encoder–decoder families while keeping every tensor contract explicit.

    Read
  6. 06
    Chapter 06 · 13 Aug 20267 min read

    Queries, Keys, Values, and Causal Masks

    Build scaled dot-product attention, understand multi-head projections, apply causal and padding masks, and verify the softmax axis.

    Read
  7. 07
    Chapter 07 · 13 Aug 20266 min read

    Residual Blocks, Normalization, and MLPs

    Assemble pre-norm attention and feed-forward branches, preserve gradient paths, and reason about width, depth, and activation choice.

    Read
  8. 08
    Chapter 08 · 13 Aug 20266 min read

    Position and Context Length

    Compare learned positions, sinusoidal encodings, rotary embeddings, relative bias, extrapolation, and the real cost of longer context.

    Read
  9. 09
    Chapter 09 · 13 Aug 20266 min read

    KV Caches and Efficient Attention

    Separate full-sequence training from incremental decoding, account for cache memory, and test fused kernels against a clear reference.

    Read
  10. 10
    Chapter 10 · 13 Aug 20266 min read

    Scaling Laws and Training Budgets

    Allocate parameters, clean tokens, context, batch size, compute, and wall-clock budget without confusing size with capability.

    Read
  11. 11
    Chapter 11 · 13 Aug 20266 min read

    Mixture-of-Experts Routing

    Map tokens to experts with top-k routing, distinguish total from active parameters, and trace dispatch and combine operations.

    Read
  12. 12
    Chapter 12 · 13 Aug 20268 min read

    Expert Capacity, Balance, and Parallelism

    Handle overflow, token dropping, auxiliary losses, shared experts, expert parallel communication, and routing failure modes.

    Read
  13. 13
    Chapter 13 · 13 Aug 20267 min read

    Initialization and Optimization

    Set residual-aware initialization, AdamW parameter groups, warmup and decay schedules, gradient accumulation, and clipping.

    Read
  14. 14
    Chapter 14 · 13 Aug 20268 min read

    Distributed Training and Throughput

    Use mixed precision, fused kernels, compilation, data parallelism, all-reduce, and exact global-token accounting.

    Read
  15. 15
    Chapter 15 · 13 Aug 20267 min read

    Checkpoints, Evaluation, and Reproducibility

    Package weights with optimizer and data state, compare fixed-token runs, audit contamination, and preserve the evidence behind every result.

    Read