Why did Andrej Karpathy say bigram language models break down with more context?
Andrej Karpathy said the problem with taking more context is that the table of possibilities grows exponentially and quickly becomes unmanageable. With two previous characters, the number of context rows jumps to 729, and with three characters it becomes around 20,000. That leaves too few counts for each context, so the model breaks down and predictions stay poor.
“That 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 the 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 * 27. So there's 729 possibilities for what could have come in the context.”

Key takeaways
- More context can cause combinatorial explosion.
- Sparse counts make simple lookup models unreliable.
- Use a method that generalizes across similar contexts.
Context
In an online lecture on makemore, Karpathy explains why the earlier bigram model is limited and motivates moving to an MLP. The quote above is taken word for word from the recording's transcript.
In the transcript
…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 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 the 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 * 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 20,000 possibilities of context. And so that's just way too many rows of this matrix. It's way too few counts for each possibility, and the whole thing just kind of explodes and doesn't work very well. So that's why today we're going to move on to this bullet point here, and we're going to implement a multi-layer perceptron model…
Read the full transcript of Building makemore Part 2: MLP, online lecture
Topics
More questions about Andrej Karpathy
- How does Andrej Karpathy sample from a trained language model?
- What did Andrej Karpathy say about overfitting and hyperparameter tuning?
- What did Andrej Karpathy say about scaling laws in large language models?
- How does Andrej Karpathy decide when to use reasoning models, search, or tools with LLMs?
- What does Andrej Karpathy mean by the 'cognitive core' in LLMs?
- How small did Andrej Karpathy think powerful AI models could become?
All Andrej Karpathy answers · All Andrej Karpathy recordings
How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.