Notes

Type vs Token

Count the words in the cat sat on the mat and you can give two honest answers. Six words went past; only five of them are different. That gap — between what you counted and what you catalogued — is the type/token distinction.

Two ways of counting
A token is a single occurrence of a word in running text. A type is a distinct word form, counted once no matter how often it appears. A news corpus of a million tokens may hold only fifty thousand types. Two quantities follow straight from this:

  • the vocabulary is the set of types, and it fixes the width of a count or TF-IDF matrix and the number of rows in an embedding table;
  • the type-token ratio (types divided by tokens) is a rough measure of lexical variety used in stylometry and clinical language assessment — it shrinks as text gets longer, so it only compares samples of equal length.

Why the type count never settles
Types keep arriving. Vocabulary grows roughly as a power of the token count — Heaps' law — so doubling a corpus still turns up thousands of new names, typos and compounds. That is the open-vocabulary problem in its plainest form, and the reason frequency cutoffs, an out-of-vocabulary bucket and subword tokenisation all exist.

Where confusing them hurts
The arithmetic of language models depends on knowing which you mean. A unigram probability divides a token count by total tokens, while add-one smoothing adds mass once per type in the vocabulary, so a wrong denominator distorts every estimate. The same slip shows up in evaluation: reporting coverage over types flatters a system, since the words it misses are rare types but a small share of tokens.

A token is one occurrence of a word in running text; a type is a distinct word form, counted once however many times it occurs. The cat sat on the mat has six tokens but five types. The set of types is the vocabulary, which fixes feature-matrix width and embedding-table size, while token counts drive frequency and probability estimates — mixing the two corrupts both the estimates and the smoothing applied to them.

Picture a librarian with twenty copies of the same novel on her trolley. Asked how many books she is holding, she can say twenty — or one, if she means titles. Both answers are correct; they simply count different things.

Words work the same way. Every word printed on a page is a token, an individual appearance. Every different word is a type. In the cat sat on the mat there are six tokens but only five types, because "the" turns up twice. Software reading text needs both numbers: the list of different words decides how much memory it must set aside, while the raw counts tell it which words are common and which are rare.