internalsGet Pro

Module 10 · Lesson 9 of 12Pro

Training a small transformer from scratch

Level
Advanced
Topic
Deep learning architectures
Reading time
22 min

When you finish this page you can

  1. Train a character-level transformer on product titles in PyTorch, on a laptop CPU in a few minutes.
  2. Predict three reference losses before training starts: the random start, a bigram baseline and the floor set by the data’s own randomness.
  3. Choose the token unit and the model size from the data and the compute budget, and say what would change each choice.
  4. Spot a leaking causal mask from a loss that falls below what the data allows.

Builds on 4 lessons

Start with lesson 718 min
  1. Attention: the maths of focusing on what matters18 min
  2. The transformer, layer by layer18 min
  3. Learning rate schedules and warmup17 min
  4. Debugging a network that won’t train17 min

A transformer that guesses 1 in 35

is our example online store. Joseph, who leads the growth team, wants the search box to finish what a customer types: “tuya glass wa” should become “tuya glass water bottle 750 ml”. Farah, an ML engineer, has the notebook sample’s 50,000 product titles and a laptop with 8 CPU threads.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan