Course 7 of 9

NLP and Transformers

After this course you can follow a sentence through a transformer, and train a tiny one.

10 lessons, 3 labs and a project. About 55 min of video.

Start with lesson 1
  1. TokenizationA model reads text as pieces, each one a number from a fixed list, and the pieces are learned: what was common became one piece.6 min
  2. Word embeddingsA model's first layer gives every token a row of numbers, its vector, and training puts tokens used alike close together.5 min
  3. Language modelingA language model gives every token a chance of coming next. It practices on plain text, where each next token is the answer. Perplexity expresses its average uncertainty as a count of equally likely choices.6 min
  4. Lab 1Score any text, token by tokenYou will cut any text into the series' model's tokens, find a token's nearest rows in the model's table by hand, and score a text token by token: each token's surprise in bits, and the text's perplexity.40 min
  5. Recurrent networks and their limitA recurrent network reads one token at a time and keeps all of it in one small state, so the start fades and every step waits for the one before.7 min
  6. AttentionEach token gives every token before it a share, the shares add up to 1, and it takes in a blend of those tokens by their shares, so the same word gets a different vector in every sentence.6 min
  7. Queries, keys, values and headsEach token makes a query, a key and a value; a share comes from a query's dot product with each key, divided and put through softmax, and the shares blend the values.6 min
  8. Lab 2Attention, written by handYou will write a recurrent network's step and attention's steps by hand, hold each against PyTorch's own with torch.allclose, and read one row of a real model's attention.40 min
  9. PositionAttention on its own can't see the order of the words, so each query and key is turned by an angle that grows with its place, and a score then depends only on how far apart two tokens are.7 min
  10. The transformer blockA transformer is one block repeated: in each, attention lets the tokens share and an MLP works on each token alone, each part reading a rescaled copy and adding its change to the vector that runs up through them all.6 min
  11. Encoders and decodersA decoder's tokens see only the tokens before them so it can write, while an encoder's tokens see the whole text so it reads, and for a label on many texts a small trained encoder beats a chat model asked.7 min
  12. Lab 3Open up a real transformerYou will run a real model's block by hand from its own parts, run all 28 that way and read the stream after each, move every place 10,000 along, and test what each token can see in a decoder and in an encoder.45 min
  13. ReviewQuestions from the whole course9 questions from 9 lessons, in a mixed order. See what you still remember.
  14. EndingWhat can you build with transformers?The course's project: build a tiny GPT on your computer, train it on Shakespeare until it writes something like a play, then on a text of your own.1 min
  15. ProjectTrain a tiny GPT, and watch it learn to writeYou build a GPT of one and a half million weights from the course's own parts, trained on your own computer until it writes like a play, then trained again on a text you choose.4 h