Section 10 of 24 · 37 lessons
Natural Language Processing
The words we read are comprehensible to us, but a numerical model needs some way to process them. We will start by turning text into pieces with numerical IDs. Then we can ask how a model might learn relationships between those pieces and use the surrounding words to interpret them.
Tokens and Basic Units
Before a model can work with text, we need to decide what pieces it will receive. A word, a character, and a byte each give us a different starting point.
Rules for Word Boundaries
Splitting text on spaces leaves us with questions about punctuation, contractions, and different writing systems. These tokenizers make explicit choices about where one piece ends and another begins.
Scripts Without Spaces
Not every writing system places spaces between words. We need another source of information about the boundaries, whether that comes from a dictionary, a probability model, or labelled examples.
Predicting Token Sequences
Some words are more likely after a particular phrase than others. Counting short sequences gives us a simple way to make a next-token prediction and a reason to consider phrases we have never seen.
Learning a Subword Vocabulary
A vocabulary containing every possible word would be enormous, and it would still miss new words. Reusing smaller pieces helps, but we need a way to decide which pieces deserve an entry.
Word Structure
Words such as walk, walked, and walking share more than a few letters. We will look at how recurring word parts can be learned from examples or described with explicit rules.
Fixed Tables and Shorter Sequences
A large vocabulary takes up space, while a long sequence takes work to process. Hashing and byte patches make different compromises when those costs become a problem.
Codes for Numerical Inputs
The idea of assigning a piece an ID can also be applied to numerical data. We will replace continuous values with a limited set of codes and examine what information is lost.
Word Vectors from Counts
A token ID identifies a word without telling us how it relates to other words. The contexts in which words occur give us information we can use to build more useful numerical representations.
Word Vectors from Prediction
If a representation helps a model predict the words around it, it must preserve something useful about how that word is used. These methods learn word vectors from that requirement and related observations.
Representing Order and Context
The same word can play different roles depending on where it appears and what surrounds it. A model needs access to that information as well as the word itself.
Representing a Whole Text
Searching or comparing documents often calls for one representation of each text. We can combine its word vectors or learn a document vector, with different consequences for what survives.