Language is glorious chaos.
How do we represent the meaning of a word?
In traditional nlp, we regard words as discrete symbols (represented by a one-hot vectors )
It’s obvious that vectors ar orthogonal, thus ther is no natural notion of similarities for one-hot vectors.
The main idea is: A word’s meaning is given by the words that “frequently” appear close-by.
“You shall know a word by the company it keeps.” (John Rupert Firth) It essentially means that the meaning of a word can be understood better by examining the context in which it is used, the words it is commonly associated with, and the situations in which it is employed. In other words, the meaning of a word is influenced by the words that surround it and the way it is used in various contexts. This idea emphasizes the importance of considering language holistically rather than in isolation.
This is one of the most successful ideas of modern statistical NLP.
We build a dense vector for each word, chosen so that it is similar to vectors of words that appear in similar contexts.
Word vectors are also called word embeddings or (neural) word representations.
Idea:
Data likelihood:
is the parameters of the model. is the center word and is the context word. is the size of the context window.
Calculating the product of probabilities is hard, so we take the log and the negative to make it easier to calculate.
In order to calculate the , we use two vectors for each word :
Using a softmax function, we can calculate the probability of a context word given a center word:
where is the vocabulary of the corpus.
A softmax function
The softmax function maps arbitrary values to a probability distribution .
It is worth noting that the softmax function does not return a single value, but a distribution of probabilities over the entire vocabulary.
Since every word has two vectors, we can concatenate them to form a single vector. This is called a “word vector” or “word embedding”.
With d-dimensional word vectors, the model has parameters.
The result perfectly makes sense. The gradient of the loss function is the difference between the observed and expected values.
It’s important to be cognizant of the biases (gender, race, sexual orientation etc.) implicit in our word embeddings. Bias can be dangerous because it can reinforce stereotypes through applications that employ these models.
1 | pprint.pprint(wv_from_bin.most_similar( |
Running the above code gives the following results:
1 | [('reputation', 0.5250176787376404), |
The results show that the word vectors are biased. One explanation of how bias gets into the word vectors is that the word vectors are based on the prediction of the probability of a word given its context. Therefore, the bias in the context of the word gets into the word vectors. A real-world example that demonstrates this source of bias is that the word “doctor” is more associated with the word “he” than the word “she” in the word vectors. This is because the word “doctor” is more associated with the context of “he” than the context of “she” in the word vectors.
One way to debias the word vectors is to remove the bias in the context of the word vectors. This can be done by preset a group a potentially biased words and then neutralize and equalize the word vectors. Neutralizing the word vectors means removing the bias in the context of the word vectors. Equalizing the word vectors means making the word vectors of the group of words equal in the context of the word vectors. A real-world example that demonstrates this method is that the word “doctor” is equally associated with the word “he” and the word “she” in the debiased word vectors. This is because the bias in the context of the word is removed from the debiased word vectors.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。 rss订阅