NLP Lec 03
NLP Lec 03
(CS5803)
Lecture 3
(Word Representations)
Words as vectors: Word2Vec
● Training sentence:
● ... the algorithm’s asymptotic complexity
is quadratic...
● w-2 w-1 c w1 w2
● Considering words in a context window of
length 5
○ P(context|target)
○ P( [w-2 w-1 w1 w2]|c)= ?
Word2Vec Models: CBOW
● Training sentence:
● ... the algorithm’s asymptotic complexity
is quadratic...
● w-2 w-1 c w1 w2
● Considering words in a context window of
length 5
○ P(target|context)
○ P( c|w-2 w-1 w1 w2)= ?
Objective function
Ref: “Distributed Representations of Words and Phrases and their Compositionality”, by Mikolov (2013)
More examples of target and context
Ref: https://towardsdatascience.com/an-implementation-guide-to-word2vec-using-numpy-and-google-sheets-13445eebd281
Skip-gram
8
Steps with example
Input layer
0
1
0
0
…
V-dim 0 N will be the size of word vector
9
Learning the representations: Step by step
● Ref: https://towardsdatascience.com/an-implementation-guide-to-word2vec-using-numpy-and-google-sheets-13445eebd281
Learning the representations: Step by step
For more details regarding weight updates, you may visit the paper “word2vec Parameter Learning Explained”
Word2Vec: References
● Distributed Representations of Words and Phrases
and their Compositionality
● https://www.geeksforgeeks.org/python-word-embedding-usin
g-word2vec/
● https://radimrehurek.com/gensim/models/word2vec.html
Analogy: Embeddings capture relational
meaning!
vector(‘king’) - vector(‘man’) + vector(‘woman’) vector(‘queen’)
≈
WordSim353: http://www.cs.technion.ac.il/~gabr/resources/data/wordsim353/
Evaluation on semantic textual
Similarity Task
GloVE
● Stands for GloVe: Global Vectors for Word Representation
○ Emphasizes on co-occurrence with context/probe words
● Learns two representations (W, W ̃) for each word
Model F as exp(.)
Bolukbasi, Tolga, Kai-Wei Chang, James Y. Zou, Venkatesh Saligrama, and Adam T. Kalai. "Man is to computer
programmer as woman is to homemaker? debiasing word embeddings." In Advances in Neural Information
Processing Systems, pp. 4349-4357. 2016.
Embeddings
Embeddings Reflect
by w2vSocietal Bias News
on Google
Identifying and quantifying bias in word
embeddings
●Assumption: The aspect of bias is known. E.g. gender
●Find the “gender” dimension
○ Collect explicit gender-based word pairs (f, m): (woman, man),
(mother, father), (gal, guy), (girl, boy), (she, he)
○ Get the gender dimension as (f-m) [How?]
● Collect a set N of gender neutral words
Reference: Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddings NeurIPS 2016
Another version is here.