Word embeddings: turning words into vectors that capture meaning
10 questions on one-hot vectors, embedding matrices, learning embeddings from context with the continuous bag of words and skip-grams, and vector arithmetic.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
A dictionary has 50,000 words and the embeddings have 300 dimensions. About how many numbers are in the embedding matrix?
- About 15 million
- About 50,000
- About 300
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
A neural network works on numbers, so before a sentence can be processed, each word has to become a vector. The most obvious way is to give every word its own slot in a very long list and put a one in the slot for that word and zeros everywhere else. It works, in the sense that the network can tell words apart, but it is wasteful and strangely blind. A dictionary of several hundred thousand words gives vectors that long, and the vector for cat is exactly as far from dog as from tax. Word embeddings fix both problems by mapping each word to a short dense vector in which nearby points mean related things.
This quiz explains how that map is built and learned. You will see how a one-hot vector picks out a column of a matrix, so that an embedding is simply a lookup in a table, and how big the table is for a realistic dictionary. You will then see how the table is learned without any labelled data, by a simple trick in which the training examples come from the text itself: hide a word, and ask a small network to guess it from its neighbours, or show it a word and ask it to guess the neighbours. These two variants have names, the continuous bag of words and skip-grams, and the quiz asks which is which.
The surprise is how much structure the learned table contains. Words used in similar contexts end up close together, and the directions between points can capture relations, so that simple arithmetic on vectors can answer analogies. You will try one such analogy. The quiz also looks at the role embeddings play today, not as a stand-alone tool but as the first layer of larger networks, which can be fixed or can continue to learn.
Some misconceptions are worth heading off. Embeddings are not hand-written dictionaries of meaning, they are learned. The training needs no human labels, which is why it can use vast amounts of text. And an embedding in this sense gives a word the same vector wherever it appears, whereas a transformer goes further and adjusts the vector according to context.
The quiz suits learners who are meeting language models for the first time, and practitioners who want to understand the first layer of a text model. It needs only simple arithmetic. There are 10 questions, each with an explanation, and it takes about four minutes. Embeddings also illustrate a recurring theme in machine learning: a simple prediction task, solved at scale, can force a model to discover useful structure. Nobody tells the embedding that Paris and London are alike. The structure appears because it helps to predict missing words. The same principle, learning rich representations from the structure of unlabelled data, underlies the pre-training of today's largest models, so the small model in this quiz is the ancestor of a very large family.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation follows every answer, so the quiz works as a short lesson on embeddings.
›Do I need to know how language models work?
No. The quiz starts from the problem of turning words into numbers. You should know that a neural network takes vectors as input, and that training adjusts its weights. Everything else, including the training trick, is explained along the way.
›What is a one-hot representation, and what is wrong with it?
Each word in a fixed dictionary gets a vector as long as the dictionary, with a one in its own position and zeros elsewhere. Real dictionaries have hundreds of thousands of entries, so the vectors are huge. Also, any two different words are equally far apart, so no similarity between words such as dog and cat is captured.
›What is a word embedding?
It is a dense vector of typically a few hundred numbers that represents a word. The embedding is computed by multiplying the one-hot vector by an embedding matrix, which just selects one column of the matrix. The matrix is learned from a large body of text, so that related words get nearby vectors.
›What is word2vec?
It is a popular technique for learning embeddings that can be viewed as a simple two-layer neural network. Samples are windows of a few adjacent words taken from a large text. The error is summed over the samples, which are treated as independent, and the embedding matrix is read off from the trained weights.
›What is the difference between continuous bag of words and skip-grams?
In the continuous bag of words, the context words in a window are the inputs and the middle word is the target, so the network learns to fill in a blank. Skip-grams reverse the roles: the centre word is the input and the context words are the targets.
›Why is this called self-supervised learning?
Because no one has to label anything. The training data is a large collection of unlabelled text, from which windows are drawn at random, and the targets come from the text itself by masking out the words the network is trying to predict.
›Why do related words get nearby embeddings?
Related words tend to appear with similar neighbouring words. It is easier for the network to predict the missing words when words used in similar contexts have similar embeddings, so training pushes them together. The space then shows richer structure, in which relations between words correspond to directions that can be added and subtracted.
›How are embeddings used today?
Mostly as the first layer of a larger network. They can be fixed, using a standard pre-trained embedding matrix, or treated as an adaptive layer that learns during end-to-end training, initialised either randomly or from a standard matrix.