Lecture 11 : Word Representation
How to represent a word?
In traditional NLP / IR, words are treated as discrete symbols.
Vector dimension = number of words in vocabulary (e.g., 500,000)
Problems with words as discrete symbols
Example: In web search, if user searches for “Baltimore motel”, we would like
to match documents containing “Baltimore hotel”. But
The vectors are orthogonal, and there is no natural notion of similarity between
one-hot vectors!
this notion of similarity?
Ludwig Wittgenstein
"The meaning of a word is its use in the language"
Source: https://web.stanford.edu/~jurafsky/slp3.
Distributional Hypothesis: Let's define words by their usages
One way to define "usage":
words are defined by their environments (the words around them)
Zellig Harris (1954):
If A and B have almost identical environments we say that they are synonyms.
Source: https://web.stanford.edu/~jurafsky/slp3.
What does recent English borrowing ongchoi mean?
Suppose you see these sentences:
And you've also seen these:
Conclusion:
"sauteed"
Source: https://web.stanford.edu/~jurafsky/slp3.
Ongchoi: Ipomoea aquatica "Water Spinach"
Yamaguchi, Wikimedia Commons, public domain
空心菜
kangkong
rau muống
…
Source: https://web.stanford.edu/~jurafsky/slp3.
Defining meaning as a point in space based on
distribution
Each word = a vector
Similar words are "nearby in semantic space"
We build this space automatically by seeing which words are nearby in text
Source: https://web.stanford.edu/~jurafsky/slp3.
We define meaning of a word as a vector
Called an "embedding" because it's embedded into a space
The standard way to represent meaning in NLP
Modern NLP algorithms use embeddings as the representation of word meaning
Fine-grained model of meaning for similarity
Source: https://web.stanford.edu/~jurafsky/slp3.
Intuition: why vectors?
Consider classical algorithms:
Source: https://web.stanford.edu/~jurafsky/slp3.
Encoding similarity: Distributional Vectors
Let’s take an example
Distributional Vectors: Computing Similarity
Context Weighting via association measures
Pointwise Mutual Information (PMI)
Statistically measure whether two words co-occur frequently (relative to their global frequencies)
Even simpler: Can use documents as context
Context weighting: documents as context
Sparse versus dense vectors
One-hot (or distributional) vectors (includes tf-idf, PMI, etc.)
Alternative: learn vectors which are
Source: https://web.stanford.edu/~jurafsky/slp3.
Sparse versus dense vectors
Why dense vectors?
Source: https://web.stanford.edu/~jurafsky/slp3.
Common methods for getting short dense vectors
Singular Value Decomposition (SVD)
“Neural Language Model”-inspired models
Alternative to these "static embeddings":
Source: https://web.stanford.edu/~jurafsky/slp3.
Word2vec
Instead of counting how often each word w occurs near "apricot"
We don’t actually care about this task
Big idea: self-supervision:
the gold "correct answer" for supervised learning
Source: https://web.stanford.edu/~jurafsky/slp3.
Distributional Representation
Reasoning with Word Vectors
Reasoning with Word Vectors
Perhaps more surprisingly, we find that this is also the case for a variety of semantic relations.
A simple vector offset method based on cosine distance shows the relation.
Vector Offset for Relations
Singular - Plural
Gender
Analogy Testing
Daniel Jurafsky and James H. Martin. 2024. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models, 3rd edition. Online manuscript released August 20, 2024. [Chapter 6]