
This is fine but one hot representation doesn’t captures one word's relationship to another word
Dense word representations

We want to learn these embedding of words (numbers)
Word embeddings: representing words using featureful vectors
Embedding dimensions
With a vocabulary of 10,000 words, a one-hot vector has 10,000 entries. A 300 × 10,000 embedding matrix maps it to a dense vector with 300 entries.
We can view embeddings in 2D/3D dimensions using t-SNE algorithm
Transfer learning and word embeddings
- Learn word embeddings from large text corpus (1-100B words) or download pre-trained embedding online
- Transfer embedding to new task with smaller training set
- (Optional) finetune word embeddings with new data
Cosine similarity

Embedding matrix

We np.dot embedding matrix against one hot vector to fetch Embedding vector
When predicting next word in the sequence, we need to feed model the context
Apart from using the last few words as context, there are alternative ways to define context:
- Using both preceding and succeeding words.
- Using just the immediate previous word.
- Using a random nearby word (Skip-Gram model).
Skip-gram model
The skip-gram model creates supervised learning problems using context-to-target pairs from sentences.
Rather than using a fixed number of words as context, a random word is selected from the sentence.
Another random word, within a specified window (e.g., +/- 5 or 10 words), is selected as the target.
Calculating the softmax requires summing over the entire vocabulary, which is computationally expensive, especially for large vocabularies.
Hierarchical softmax classifier: Instead of classifying among all words at once, a binary tree of classifiers is used to narrow down choices.
This reduces the computational cost from linear to logarithmic with respect to vocabulary size.
For training, context words aren’t always chosen uniformly from the corpus.
Some words appear more frequently than others, and sampling uniformly might bias the training towards these common words.
Various heuristics balance sampling common and less common words to ensure that embeddings are learned for both.
| Skip gram | CBOW |
|---|---|
| Predicts surrounding words given single context word | Predicts target word from set of context words |

Negative sampling
Reducing the cost of word prediction
Negative Sampling presents a new supervised learning problem. For any given pair of words (like “orange” and “juice”), aiming to predict if a given pair of words are contextually related (1) or not (0).“Orange” and “juice” would be a positive example (labeled 1), while “orange” and “king” is considered a negative example (labeled 0).
Visualized as a neural network, instead of a massive Softmax layer, it employs multiple logistic regression classifiers. Only a subset of these classifiers are trained in each iteration, keeping computational costs low.
For choosing negative examples
Rather than just randomly picking words, or picking based on empirical frequency (which would over-represent common words like “the”, “and”, etc.), the authors proposed a heuristic: sample words proportionally to the frequency of a word raised to the power of 3/4.
After training ends, we will take the model weights and pass it text pairs in the future to test if two words are related or not

GloVe word vectors
"Global vectors"

Actually word embedding vectors are not human understandable
Sentiment classification
A simple sentiment classification algorithm

Since soo many 'good' words, it may classify it as positive review
Alternatively we may use RNN for sentiment classification

Debiasing word embeddings


How to reduce bias in word embeddings?
- Identify bias direction

- Neutralize, for every word that is not definitional, project to get rid of bias
- Equalize pairs