AITeky Learn

AiTeky Original Interactive Learning & Practice Advanced

Transformers from scratch

Build attention, position codes, the causal mask and a full transformer block with NumPy, train a tiny GPT in PyTorch, and size a language model for real use, with delivery reviews and support tickets.

Nearly every modern language model, from the ones that complete your sentences to the ones that chat, is built from one repeated part: the transformer block. It looks complicated from the outside, but the parts are few and short. In this course you build them yourself.

You will write attention as a soft dictionary lookup, see why it cannot tell the order of words and add position codes, add the causal mask that keeps a language model honest, assemble a whole block and count its weights, and then train a small GPT in PyTorch on delivery reviews and compare it with the counting model of the sequence models course. The industry lessons answer two questions a team has to face: how big a model, and on what hardware, and whether a small transformer is worth using at all for routing support tickets. You need the NLP and deep learning courses first.

  • Learn lessons explain one idea at a time, with code you can run (the PyTorch lesson runs in Colab).
  • Industry ready lessons size a 7-billion-weight model for support replies from first principles, and compare a small transformer with word counts on real tickets. Each ends with the interview questions that go with it.

Locked. Sign up free

Learn

Understand each idea with everyday examples. No coding background needed.

  1. 01 30 min Free sample πŸ”’ AiTeky Pass Attention by hand Build attention from a dictionary lookup, then write scaled dot-product self-attention in a few lines of NumPy, see the weight table it produces, and find out why the scores are divided by the square root of the size.
  2. 02 25 min πŸ”’ AiTeky Pass Order and masks: positions and the causal mask Show that attention alone cannot tell "dog bites man" from "man bites dog", fix it with sinusoidal position codes, and learn the causal mask that stops a language model from peeking at the words it has to predict.
  3. 03 30 min πŸ”’ AiTeky Pass The transformer block Assemble multi-head attention, a residual connection, layer normalisation and a feed-forward layer into one transformer block in NumPy, trace the shapes through it, and count its weights to see where the size of a model comes from.
  4. 04 35 min πŸ”’ AiTeky Pass A tiny GPT in PyTorch Train a small decoder-only transformer on 2,250 delivery reviews, measure its perplexity against the bigram table of the last course, and let it write new reviews.

Industry ready

Real problems from real jobs, and the questions interviewers ask about them.

  1. 05 40 min πŸ”’ AiTeky Pass On the job: sizing a model for support replies Work out from first principles whether a 7-billion-weight model fits on one GPU, how much memory each conversation takes, how fast it writes, how many GPUs a busy support desk needs, and what quantisation changes.
  2. 06 40 min πŸ”’ AiTeky Pass On the job: should a small transformer route the tickets? Measure how well a TF-IDF model routes support tickets, train a small transformer encoder on the same tickets, compare accuracy, speed and effort fairly, and recommend what to ship.

We use essential cookies to run the site. With your permission we also set one anonymous ID to count unique visitors, and analytics cookies to see which pages help learners. Cookie notice

Join AiTeky Learn. It's free.

Create a free account to track your progress, save items for later and get study suggestions.

Sign up free Log in