Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · AI · GPT, built from scratch · with code: Python · about 21 min to read

Play it as a journeyTutor comes with a plan

The MLP Language Model

Tokens and Embeddings
Tokens and Embeddings · Open board

The Tokens and Embeddings board draws text turned into lists of numbers. This lesson learns one for every character: the third of six lessons that end with a small GPT built from scratch.

Before you start. A weight is one adjustable number inside a network. Training nudges every weight, over and over, to shrink the loss, one number for how wrong the guesses were. Training finds, for every weight at once, which way to nudge it (Autograd by Hand builds the code that does this). In The Bigram Model a model read 3,000 returns-desk replies and guessed each next character from only the one before it, turning 51 scores (one per possible character) into chances with softmax. Its loss on replies it never trained on was 1.97, where knowing nothing scores 3.93. From Tokens & Embeddings: an embedding is a short list of numbers that stands for one piece of text, kept as one row of a table and picked out by that piece’s id. From What a Neural Network Is: a hidden layer is a row of neurons between the input and the answer, each adding up its inputs times weights plus a bias, an extra adjustable number that shifts where the neuron fires. From Why the Loss Won't Go Down: the learning rate is how far each nudge goes, and the loss curve, the loss printed as training runs, shows whether it is right.

Lesson 61 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 2003, Montréal: Bengio’s curse of dimensionality, a table too big to fill
  • The context: the last eight characters, on a strip
  • The embedding: ten learned numbers per character, laid side by side
  • The hidden layer and tanh: squash every total into minus one to one
  • Validation loss: the score on replies it never saw
  • The learning rate, read off the loss curve
  • What the embedding learned: the digits sit together
  • Where eight characters run out
  • One guess, worked by hand
  • Where the 26,961 numbers live
  • Turning a loss back into a chance
  • Pointing the same way
  • All of it in code

Terms it explains: Tokens and Embeddings, curse of dimensionality, context, tanh, MLP, validation loss, analogy arithmetic, BPE, cosine similarity, dense vector, dimension d, embedding, embedding matrix, positional encoding, semantic search, static vs contextual embedding, token, token ID, tokenizer, vector database, vector space, vocabulary.

Lab

One sentence, one tokenizer, a vocabulary you can grow. How many tokens does it cost?

Drag How many pieces it knows left to right, then open the tab Another script, and an emoji, and watch How many tokens.

Open Tokens and embeddings

Related papers

Review AI