What did Andrej Karpathy say about why tokenization causes strange LLM behavior?

Karpathy says tokenization is at the heart of a lot of the weirdness people notice in large language models. Many problems that look like architecture or training issues actually trace back to how text gets split into tokens. He specifically points to spelling, non-English text, arithmetic, Python, whitespace, and bizarre prompt-specific behavior as examples.

“So tokenization is at the heart of a lot of weirdness in large language models, and I would advise that you do not brush it off. A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization and fundamentally trace back to it. So if you've noticed any issues with large language models — can't, you know, not able to do spelling tasks very easily — that's usually due to tokenization. Simple string processing can be difficult for the large language model to perform natively. Non-English languages can…”
— Andrej Karpathy, Talk / tutorial presentation, 2019 · at 4:23
Andrej Karpathy: Andrej Karpathy on Tokenization: Building GPT's Tokenizer

Key takeaways

  • Don’t assume every LLM quirk comes from the model itself.
  • Check tokenization when tasks involving spelling, code, or structured text fail.
  • Non-English and whitespace-heavy text can be especially sensitive to tokenizer design.

Context

In a 2019 tutorial on tokenization, Karpathy explains why token boundaries matter before demonstrating tokenizer behavior in a browser app. The quote above is taken word for word from the recording's transcript.

In the transcript

…And that's because tokens are, again, pervasive. So here, they mentioned that they trained on two trillion tokens of data, and so on. We're going to build our own tokenizer. Luckily, the byte pair encoding algorithm is not that super complicated and we can build it from scratch ourselves, and we'll see exactly how this works. Before we dive into code, I'd like to give you a brief taste of

So tokenization is at the heart of a lot of weirdness in large language models, and I would advise that you do not brush it off. A lot of the issues that may look like just issues with the neural network architecture or the large language model itself are actually issues with the tokenization and fundamentally trace back to it. So if you've noticed any issues with large language models — can't, you know, not able to do spelling tasks very easily — that's usually due to tokenization. Simple string processing can be difficult for the large language model to perform natively. Non-English languages can…

work much worse, and to a large extent, this is due to tokenization. Sometimes LLMs are bad at simple arithmetic, also can be traced to tokenization. GPT-2 specifically would have had quite a bit more issues with Python than future versions of it due to tokenization. There are a lot of other issues. Maybe you've seen weird warnings about a trailing whitespace — this is a tokenization issue. If you…

Read the full transcript of Talk / tutorial presentation

Topics

What others said about artificial intelligence

More questions about Andrej Karpathy

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.

Search every transcript
Open the full search page →