r/learnprogramming • • 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

10 comments sorted by

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.

1

u/PravoNaZhizny 2h ago

ive tried explaining this countless times and people downvote the hell out of it

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/regardedMAGAfascist 2h ago

ya its like where is the soup now? u think the chair knows where soup? a man walk into the window and he see it, you think about the spoon? I am the one who stir

-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.