liveBook · Manning

Token count

As explained in How Large Language Models Work

The quantity of tokens consumed as input to or produced as output by a language model.

A token count measures how many pieces of text an LLM receives as input or produces as output. These pieces may be words, fragments, or characters rather than whole words. section 2.2.4

Count does not simply follow character or sentence length. Byte-pair encoding greedily chooses familiar pieces, so a longer string can contain fewer tokens than a shorter variation. section 2.2.4

Token counts matter because they affect:

  • Billing, when providers charge for input and output tokens. section 2.3.3
  • Response time, which depends partly on how much text the tokenizer represents. section 2.3.3
  • Language equity, because some languages require substantially more tokens than English for comparable requests. section 2.3.3

A counterintuitive count

GPT-3 tokenizes “I’m running” into one fewer token than “I’m runnin.” The complete word is common enough to have its own token, while the shortened form is split into pieces such as “run” and “nin.” section 2.2.4

Figure 2.6 Tokenizing two different sentences
figure

Compare the tokenization of two nearly identical strings and see why token counts can reverse ordinary expectations about length. section 2.2.4

How How Large Language Models Work covers it

How deep it goes
Explains BPE-driven counting with a worked comparison, but stops short of formal tokenizer algorithms.
Examples
Uses GPT-3 tokenizations of “I’m running” and “I’m runnin,” plus cross-language cost comparisons.
What it assumes
Teaches tokenization concerns directly without requiring prior machine-learning or programming background.
What you can do after
Evaluate tokenization-related cost, latency, language disparities, and software differences before deploying or upgrading systems.
How it connects
Connects token count with tokenization, byte-pair encoding, vocabulary, Unicode, language equity, and commercial LLM pricing.

Also explained in

Compare how 4 books explain token count →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Large Language Models Work. The section links point to the parts of the book it draws on.