To represent words in a way that captures their meaning and relationships, we might try to define different attributes or features for each word. For example, we could define features such as "masculine" or "feminine" for the word "king", or "fast" or "slow" for the word "car". But doing this by hand is impractical for a large vocabulary.
So to create embeddings for words, we can turn to machine learning algorithms to automatically define the traits we will use to represent words and assign values for each particular word.
The embedding is a list of 50 numbers that range from -2 to 2. A visual representation makes comparison with other word vectors easier. The values can be arranged in a single row:
See how "Man" and "Woman" are much more similar to each other than either of them is to "king"? This tells you something. The concepts of βManβ and βWomanβ, despite being βoppositesβ in gender, are very similar overall. A βkingβ is a very different concept from βManβ and βWomanβ despite being more closely associated with one of them.
We will rely on colors to make these comparisons. But keep in mind that a computer algorithm could use cosine_similarity to measure the similarity between two word vectors, and reach similar conclusions.
"boy" and "girl" also have places where they are similar to each other, but different from "woman" or "man". Could these be coding for a vague conception of youth?
All but the last word represent people. The object "water" illustrates differences between categories. For example, a blue column runs through the person-related words but stops before "water".
There are clear places where "king" and "queen" are similar to each other and distinct from all the others. Could these be coding for a vague concept of royalty?
Although it is tempting to interpret the meaning of each dimension, we must be cautious about over-interpreting the results. There is no dimension that maps directly to βgenderβ or βageβ. A human didnβt design the 50 dimensions; they are just what a machine learning algorithm learned worked best to capture the relationships in the data it was trained on.
Despite the limitations of interpreting individual dimensions, word embeddings clearly capture some of the relationships between words. This can be seen in the way that adding and subtracting word vectors can reveal semantic relationships. A well-known example is "king" - "man" + "woman". If we take the 50 element vector for "king", subtract the 50 element vector for "man", and add the 50 element vector for "woman", we get a new 50 element vector. If we ask the question, "what word is most similar to the resulting vector?", we find that it is very similar to the vector for "queen".
Figure1.8.The Gensim library in Python supports addition and subtraction of word vectors and identifies the words most similar to the resulting vector. The image lists these words with their cosine similarities.
Figure1.9.The vector resulting from "king-man+woman" does not exactly equal "queen", but "queen" is the closest word among the 400,000 embeddings in this collection.