Separate token counts from word counts

Watch the spaces around tokens and probability values. · 170 words

Token counts and word counts measure different things. A word count splits text at spaces, while a token count depends on the tokenizer. For example, "booksellers can't" contains two space-separated words, but one tokenizer might produce the five tokens "book", "sell", "ers", "can", and "'t". The pieces inside "booksellers" and the split punctuation are tokenizer choices, not errors in the text. A report that says a model processed 1,000 tokens should name the tokenizer when readers need to reproduce the count.

Consider a museum shop sentence: "The mugs cost $12." It has four space-separated words: "The", "mugs", "cost", and "$12." Suppose a tokenizer attaches spaces to words, splits the dollar sign, and separates the final period. Its tokens are "The", " mugs", " cost", " $", "12", and ".", so there are six tokens. This does not mean there are six words. Use word counts for claims about vocabulary or readability. Use token counts for model input limits, prices, and processing rates, because models consume tokens rather than abstract words.

Check your recall

For "The mugs cost $12.", how many words and tokens does the example tokenizer produce?

Check your answer

It produces four space-separated words and six tokens under the stated tokenizer.

Sources and credits

Original KeyTouch lesson. Background reading · Hugging Face · LLM Course.