Why Your LLM Can't Count the R's in 'Strawberry'
Ask a state-of-the-art language model a question a six-year-old can answer — how many R's are in "strawberry"? — and there's a decent chance it says two . The answer is three. The model has read more text than any human who has ever lived. It can write working code, explain quantum mechanics, and pass the bar exam. But it trips over counting letters in a common word. This isn't a one-off glitch,…
Language models, despite their vast knowledge, struggle with simple tasks like counting the number of R's in the word "strawberry." This is not a sign of their intelligence but rather a consequence of how they process text. When a language model encounters a word, it doesn't see individual letters; instead, it sees tokens, which are chunks of text that can be whole words, pieces of words, single characters, or even just spaces.
For example, the word "strawberry" is typically broken down into three tokens: "str," "aw," and "berry." Asking the model to count the R's in "strawberry" is akin to guessing from memory, as it has no access to the individual letters.
The tokenization process is crucial for understanding why language models have this limitation. It allows them to handle a vast array of words and languages effectively, but it also leads to difficulties in tasks requiring character-level analysis. This tokenization method, known as Byte-Pair Encoding (BPE), merges common sequences of characters into single tokens while leaving rare sequences fragmented.
As a result, English text, which dominates the training data, tends to fragment into fewer tokens, while other languages or non-Latin scripts require more tokens.
This tokenization system also affects other aspects of language modeling. For instance, it contributes to the model's struggles with spelling and letter games, as it cannot see the individual letters it needs to count. It impacts language pricing, as the cost of using an API in different languages can vary significantly due to tokenization differences. Additionally, spaces are treated as part of the following token, which can lead to inconsistencies in how words behave depending on their position.
While newer approaches are being developed to address these issues, such as byte-level or character-aware models and the use of tools to circumvent the limitations, the fundamental design choice of tokenization remains a key factor in language models' behavior. This tokenization-centric approach is integral to understanding many quirks and limitations observed in large language models.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.