Skip to main content

Subsection 1.5 Words vs Tokens

We have focused on representing words. However, language models that rely on embeddings actually process tokens. A token can be a whole word, part of a word, a symbol, or any other piece of text. While common words are typically represented as single tokens, less common words may be split into multiple tokens. For example, a tokenizer might treat dog as one token, split dogs into dog and s, and split tokenize into token and ize. Below is an example of how a tokenizer might split up the sentence “Joanna took her cat and her caterpillar to the veterinarian.”:
Colored boxes divide the sentence into tokens, splitting "Joanna" into "Jo" and "anna" and "caterpillar" into "cater" and "pillar".
Developing a large, but fixed, token vocabulary allows a model to handle a wide variety of words without needing to store a separate entry for each possible word. From the example above, we can see that the tokenizer does not have an entry for caterpillar, presumably because it did not appear much in the training data. But it is able to represent it as a combination of other tokens. And, if it has seen cater and pillar used together before it probably has learned an embedding for each of those tokens that includes concepts like “insect” and “legs”. Algorithms for identifying ways to split text into tokens are an interesting problem in their own right, though we will not explore them in detail here
The embeddings for tokens are learned in the same way as word embeddings—via training, the model learns to represent each token as a vector of numbers that captures some of its possible meanings. Much like the way in which an embedding for “bank” must capture the concepts of both a financial institution and a river, the embeddings for tokens must capture the various meanings and contexts in which each token can appear. “pillar” will need to have associations with concepts like “support” as well as some association with “insects” based on its usage in various contexts.
If you are interested you can explore how models tokenize text using one of these tools: