Why Can't a Chatbot Count the Letters in Strawberry?

5 min read

Why Can't a Chatbot Count the Letters in Strawberry?

The problem

Ask a chatbot how many times the letter r appears in "strawberry" and, for a long time, many would confidently say two. There are three. The same model might explain quantum physics a minute later. That looks like a contradiction. It is not. It comes from how these models see text in the first place.

Models do not read letters

A language model never sees the letters you type. Before your message reaches the model, a program called a tokenizer chops it into tokens. A token is a chunk of text, often part of a word, sometimes a whole word, and each one is swapped for an ID number. The model only ever sees the list of numbers.

You can watch this happen with OpenAI's open-source tokenizer library, tiktoken. Here is what two of its tokenizers do with the word:

TokenizerInputWhat the model sees
cl100k_base (GPT-4 era)strawberrystr · aw · berry
o200k_base (GPT-4o era)strawberryst · raw · berry
both strawberry (with a space before it, as in a sentence) strawberry
bothHow many r are in strawberry?How · many · r · are · in · strawberry · ?

Animation: Two real tokenizers split strawberry differently, and each chunk becomes an ID number the model sees instead of letters.

Look at the last row. In a normal question, "strawberry" is one token. To the model it is a single ID number, like a word in a language it learned to use without ever seeing it spelled out.

Animation: Inside a normal question, strawberry is a single token, so the letters the model would need to count are hidden inside one ID.

So how would it know the spelling at all?

Only indirectly. The model has read text where words get spelled out, rhymed, misspelled or discussed letter by letter. From that it picks up a rough sense of what letters live inside each token. But that knowledge is fuzzy and second-hand. Nothing in the input says "this token contains three r's".

Counting makes it worse. To count, you need to look at each item, keep a running total and not skip or double count. A model produces its answer one token at a time, mostly from patterns. A model that is pattern-matching instead of counting can easily land on a plausible wrong answer.

So the model is being asked to do two things it is structurally bad at: look inside a token it cannot see into, and do careful step-by-step counting in one shot.

Why it is good at physics but bad at this

Explaining physics is a pattern task. The model has read thousands of explanations and can produce a fluent new one. Counting letters is a precision task about the hidden insides of tokens. Being impressive at one says nothing about the other. This mismatch shows up elsewhere too: reversing words, counting words in a paragraph, rhyming, and some arithmetic on long numbers, which tokenizers also chop into odd chunks.

It is the same root cause behind a lot of strange model behaviour. If something depends on individual characters, the model is working blind. The same logic explains part of why models make things up: they produce what is likely, not what was checked.

How to get the right answer

Make the letters into tokens. Ask the model to spell the word one letter per line first, then count. Written out like s, t, r, a, w..., each letter becomes its own token, so the model can actually see them.

Animation: Spelled out one letter at a time, each letter is its own token, and counting the r gives 3.

Let it think step by step. Models that write out their reasoning before answering tend to do better here, because the working is laid out where the model can see it.

Use code for exact work. If the answer has to be correct, have the model run a tiny program instead of guessing. One line settles it:

python
print("strawberry".count("r"))  # 3

Many chat apps and agents now do this automatically by calling a code tool. That is the honest fix: let the model decide what to compute, and let ordinary code do the computing.

The short version

Chatbots stumble on "how many r's in strawberry" because they never see letters. They see tokens, and in a normal sentence the whole word is one token. Counting letters inside it is guesswork. Spell it out, let the model reason, or hand the counting to code.

Sources