Why LLMs can't count letters

LLMs often get mocked for failing at tasks like counting how many R's are in the word "strawberry." Why does this happen?

A large language model takes input text and breaks it down into smaller pieces of text called tokens. Then it converts the tokens into arrays of numbers called vectors. The LLM takes those vectors as input for the rest of its layers.

'Strawberry'
    |  Tokenizer
    v
['Str', 'awber', 'ry']
    |  Embedding lookup
    v
[[0.0011, ...], [0.5029, ...], [0.4125, ...]]

Because LLMs are not trained to count letters in a word, the vector representation does not retain a precise character-level memory of the original text. That is why LLMs don't know how many R's are in "strawberry," and other similar errors.


2025-07-07: Based on more recent testing, newer LLM versions are a lot better at these tasks. GPT-4o, for example, appears to have been trained to count those letters. But this is still a good explanation of how LLMs work, and probably still applies to older and smaller models.

2025-07-08: It turns out LLMs are now accurate on dictionary words, but still fail on random sequences of letters. how many r's in rrrorrrorrrorrro returned 11 instead of 12, even after counting. So they aren't really counting letters at all. Even now.