All posts

Blog Post #5: A Word Is Worth a Thousand Numbers

The word “word” in large orange letters, each letter built out of small decimal numbers like +.42 and −.17, on a dark navy field of fainter numbers.

In How to Grow a Mind (Tenenbaum et al., 2011), researchers show three pictures of a strange, made-up object, each one labeled a “tufa,” and then ask participants to find the rest of the tufas in a new set of images. Almost everyone can do it, and almost everyone picks the same ones. Even children can do this. A 2-year-old can learn the word “horse” from seeing just a few horses. However, computers need many more examples: Show a computer three tufas, and it has no idea what is going on. So, how do computers learn to understand meaning?

Linguist J.R. Firth famously said, “You shall know a word by the company it keeps.” While a computer has never seen a horse, it has read the word “horse” next to “saddle,” “barn,” and “gallop” millions of times. If two words keep showing up around the same neighbors, they probably mean similar things.

Computers represent each word as a vector (a word embedding), a list of d numbers, where d is usually a few hundred numbers: v→w=[x1,x2,…,xd]∈ℝd. These vectors are trained from a large body of text so that vectors of similar words used in similar contexts point in similar directions. Once all the word vectors are trained, you can measure how similar two words are with cosine similarity, the cosine of the angle between their vectors: cos(θ)=v→a·v→b‖v→a‖‖v→b‖. The result ranges from −1 to 1: a value near 1 means the two words appear in very similar contexts, while a value near 0 means they are likely unrelated.

There is a second way to get the numbers in the word vectors, and it requires linear algebra. Picture a matrix where each word has its own row/column, and the cells show how often those two words appear near each other. You can imagine this matrix is massive (and probably mostly zeros), so we reduce the size by finding eigenvectors: M=QΛQT≈QdΛdQdT. To put it simply, each eigenvector is a direction that captures a pattern in how words are used, and its eigenvalue tells you how large that pattern is. Then, each number in an embedding measures how closely the word matches one pattern.

Since words are vectors that derive meaning, we can do fun math with them. The most famous example is that if you take v→king−v→man+v→woman≈v→queen. In general, to solve any “a is to b as c is to __” puzzle, y=arg maxxcos(x→,b→−a→+c→).

But this uncovers interesting results. In 2016, researchers (Bolukbasi et al., 2016) ran this analogy trick on embeddings trained on Google News and found that “Man is to Computer Programmer as Woman is to… Homemaker?” This means that computers will learn the same biases we have in society. These researchers dug deeper, finding the difference between pairs like he and she, his and her, and man and woman. The top eigenvector of those differences pointed clearly in a direction we can call ‘gender’. Then you can measure how “gendered” any word is by projecting it onto this ‘gender’ direction. Turns out, even if you debias these vectors by subtracting the ‘genderness’ from words, they still cluster together (Gonen & Goldberg, 2019). This is because the bias lives in the overall geometry of the space, and not in one direction we can delete.

The big open question in AI is whether models can learn more like the toddler: from fewer examples, and with better judgment about which patterns are worth keeping.

References

  • Bolukbasi, T., Chang, K.-W., Zou, J., Saligrama, V., & Kalai, A. (2016). Man is to computer programmer as woman is to homemaker? Debiasing word embeddings. Advances in Neural Information Processing Systems 29. arxiv.org/abs/1607.06520
  • Firth, J. R. (1957). A synopsis of linguistic theory, 1930⁠–⁠1955. In Studies in Linguistic Analysis (pp. 1⁠–⁠32). Blackwell.
  • Gonen, H., & Goldberg, Y. (2019). Lipstick on a pig: Debiasing methods cover up systematic gender biases in word embeddings but do not remove them. Proceedings of NAACL-HLT 2019, 609⁠–⁠614. aclanthology.org/N19-1061
  • Mikolov, T., Yih, W., & Zweig, G. (2013). Linguistic regularities in continuous space word representations. Proceedings of NAACL-HLT 2013, 746⁠–⁠751. aclanthology.org/N13-1090
  • Tenenbaum, J. B., Kemp, C., Griffiths, T. L., & Goodman, N. D. (2011). How to grow a mind: Statistics, structure, and abstraction. Science, 331(6022), 1279⁠–⁠1285. doi.org/10.1126/science.1192788

About the image: the picture at the top is the word “word,” written with exactly 1,000 small numbers, the kind a computer stores for every word it knows. Made for this post.

Easter eggs

0 of 9 found so far.