Explain the role of an unknown token

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

A language model works with tokens, which are small pieces of text such as words or word parts. A tokenizer converts text into tokens using a fixed vocabulary learned from training data. If a new word has no entry, the tokenizer can send an unknown-token marker, usually written <UNK>. This marker tells the model, "I cannot represent this exact word, so use my general unknown-word pattern." For example, suppose the vocabulary contains "the," "cat," and "sat," but not "espresso." The text "the cat sat" stays unchanged, while "the espresso sat" becomes "the <UNK> sat."

An unknown token is useful because it keeps input length and shape predictable. The model does not need a new column for every possible word. It also lets the model share what it has learned from other unseen words. However, the marker can hide useful details. If a restaurant guide contains the unseen name "Zorbin," converting that name to <UNK> makes it indistinguishable from any other unseen name. The model may still use nearby words, such as "near the station," to predict what comes next. Thus, <UNK> is a fallback label, not a claim that all unknown words have the same meaning.

Check your recall

In the example vocabulary, how does the tokenizer encode "the espresso sat," and what information is lost?

Check your answer

It encodes "the <UNK> sat." The identity and spelling of "espresso" are lost, although its position and unknown status remain.

Sources and credits

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