Save this video free

Building makemore Part 2: MLP

Andrej Karpathy · 1:15:40 · Watch on YouTube

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Andrej Karpathy builds a character-level MLP language model inspired by Bengio et al. (2003), replacing the bigram model’s one-character context with a learned embedding for each character and a neural network that predicts the next character. He implements the dataset, embedding lookup, hidden and output layers, cross-entropy training, mini-batches, learning-rate tuning, and train/dev/test evaluation; a model with 10-dimensional embeddings and 200 hidden units reaches about 2.17 validation loss, improving on the bigram model’s 2.45.

Key takeaways

Chapters

0:00 Why Bigram Context Fails and the MLP Approach
1:48 Bengio et al. (2003): Embeddings Enable Generalization
9:03 Building Character Context Examples with a Sliding Window
12:19 Character Embeddings as a PyTorch Lookup Table
18:35 Flattening Embeddings for the Hidden Layer
29:16 Producing Character Logits and the Initial Loss
32:17 Why PyTorch Cross-Entropy Is Safer and Faster
37:57 Backpropagation and Overfitting 32 Examples
42:00 Mini-Batches and a Learning-Rate Range Test
51:00 Learning-Rate Decay Improves the Bigram Baseline
53:10 Train, Dev, and Test Splits for Generalization
1:00:00 Scaling the Hidden Layer and Diagnosing Underfitting
1:05:30 Visualizing Learned Character Embeddings
1:11:00 Ten-Dimensional Embeddings and the 2.17 Dev Result
1:13:00 Sampling Names and Running the Notebook in Google Colab

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 hi everyone today we are continuing our implementation of makemore now in the last lecture we implemented the bigram language model and we implemented it both using counts and also using a super simple neural network that had a single linear layer now this is the jupyter notebook that we built out last lecture and we saw that the way we approached this is that we looked at only the single previous character and we predicted the distribution for the character that would go next in the sequence and we did that by taking counts and normalizing them into probabilities so that each row here sums to one now this is all well and good if you only have one character of previous context and this works and it's approachable the problem with this model of course is that

0:46 the predictions from this model are not very good because you only take one character of context so the model didn't produce very name like sounding things now the problem with this approach though is that if we are to take more context into account when predicting the next character in a sequence things quickly blow up and this table the size of this table grows and in fact it grows exponentially with the length of the context because if we only take a single character at a time that's 27 possibilities of context but if we take two characters in the past and try to predict the third one suddenly the number of rows in this matrix you can look at it that way is 27 times 27 so there's 729 possibilities for what could have come in the context if we take three characters as the context suddenly we have

1:34 20 000 possibilities of context and so there's just way too many rows of

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Andrej Karpathy.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.