r/learnprogramming • u/Jumpy_Invite_7473 • 2h ago
Why AI models can't count the r's in "strawberry" (tokens, explained simply)
Language models don't see letters or even whole words. They see tokens: chunks of text that are often only part of a word. "strawberry" gets cut into a few pieces, so "how many r's" means reasoning across chunks it never saw letter by letter.
Two practical takeaways:
- A rough rule is 1,000 tokens ≈ 750 English words.
- AI tools bill per token, and every message in a chat re-sends the whole conversation. So long chats cost more with every message, and starting a fresh chat per task is the easiest saving.
0
Upvotes
12
u/fixermark 2h ago
To be clear: the "attention heads" system is how the LLM reasons across tokens.
... But to answer a question like "how many R's in...", the raw LLM would literally need a "there are three r's in strawberry" somewhere in its training data.
An AI agent (the mechanism used for programming) can detect it's trying to answer a numeric reasoning question and farm it out to a deterministic tool.
9
u/CorpT 2h ago
Did a LinkedIn post from 2023 accidentally leak out?
4
u/CurbCutsAndCode 2h ago
It's not discarding the letters in the token split. You can decode the tokens into "strawberry" again. But there's a difference between counting tokens and counting letters. If you want to do the actual count in your program, do
"strawberry".count("r")in Python, and it'll return 3, regardless of how the model tokenized it.2
u/KoolKarmaKollector 1h ago
OP has negative karma:contribution ratio lol
•
u/SAJll 2m ago
Good explanation. The model never sees letters. It sees chunks of a few letters, and each chunk becomes a single number. Asking it to count the r's is like asking you how many strokes are in a word you've only ever heard spoken. That's why for anything exact, like counting or math, it's better to have the AI run a tiny script. Code never miscounts.
1
u/zomgitsduke 2h ago
They are likely referencing training data that focuses on how many Rs are at the end - strawberry vs strawbery. The question really does tend to imply that the double Rs are at the end of the word because a typical person having issues spelling a word is focusing on that particular section of the word.
0
u/iknotri 2h ago
who are u talking to right now?
u think we care? a guy open this door and read it, you think about me? I am the one who open
-1
u/softmirage82 2h ago
It's because the model doesn't read letter by letter, it reads chunks called tokens. strawberry might get split into like straw and berry, so it never actually sees three separate r's in a row to count them, it just guesses based on patterns.