Word Embeddings in NLP
- 44Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is the Euclidean distance between any two distinct one-hot vectors from the same vocabulary?
2
Or swipe the card
44 cards
What is the Euclidean distance between any two distinct one-hot vectors from the same vocabulary?
2
Why does the distance between one-hot vectors fail to capture word meaning?
All pairs of distinct words have the same distance (2), so there is no notion of semantic similarity or dissimilarity.
What computational problem arises from one-hot encoding large vocabularies?
Each token becomes a vector the length of the vocabulary, leading to high memory usage and many parameters to learn.
How can the computational burden of one-hot vectors be partially mitigated?
By using only the most frequent words, reducing vocabulary size.
What is the fundamental semantic shortcoming of one-hot vectors?
They do not capture any relationship between words; semantically similar words are as distant as unrelated ones.
What are word embeddings?
Dense, low-dimensional vectors learned from data that encode semantic similarity between words.
What is Firth's dictum and why is it important in NLP?
"You shall know a word by the company it keeps." It implies that words appearing in similar contexts have similar meanings.
What is a co-occurrence matrix in NLP?
A matrix where entry (i,j) counts the number of times word i and word j appear in the same sentence across a corpus.
How does the co-occurrence matrix capture context for words?
Two words that are interchangeable in many contexts will have similar co-occurrence vectors (rows or columns).
What is the difference between one-hot vectors and word embeddings in terms of density?
One-hot vectors are sparse (mostly zeros), while word embeddings are dense (all entries are non-zero learned values).
Why are word embeddings typically much lower-dimensional than the vocabulary size?
To capture semantic relationships compactly and avoid the curse of dimensionality and sparsity.
What does GloVe stand for?
Global Vectors for Word Representation.
What is the main idea behind the GloVe model?
Learn word embeddings by approximating the log of co-occurrence counts using a linear model with bias terms.
Write the basic GloVe model equation.
log(Xij)=wi⋅wj+bi+bj
Why do we take the logarithm of co-occurrence counts in GloVe?
To squash the widely varying counts into a narrower range, making regression more stable.
How does GloVe handle zero co-occurrence counts?
By adding 1 to all counts before taking the logarithm (i.e., log(1+Xij)).
What role do the bias terms bi and bj play in GloVe?
They capture the inherent frequency of each word, independent of its interaction with other words.
What loss function is minimized during GloVe training?
Mean squared error between log(Xij) and the predicted value wi⋅wj+bi+bj.
How are word embeddings and biases initialized in GloVe?
Randomly (e.g., using uniform or normal distributions).
After training GloVe, are the bias terms retained for use as word vectors?
No, only the embedding vectors wi are kept; biases are discarded.
What optimization algorithm is used to train GloVe?
Stochastic gradient descent (SGD) or a variant.
What property of word embeddings did the lecture demonstrate with 'brother', 'sister', 'man', 'woman'?
Word vector algebra: brother−man+woman≈sister.
What does it mean that word embeddings exhibit 'vector algebra'?
Semantic relationships (e.g., gender, verb tense) correspond to consistent vector offsets in the embedding space.
What technique is commonly used to visualize high-dimensional word embeddings in 2D?
t-SNE (t-distributed Stochastic Neighbor Embedding).
What risk arises from using too high a dimension for word embeddings?
Overfitting: the model may capture noise in the co-occurrence matrix rather than true semantic patterns.
Are individual dimensions of word embeddings interpretable?
No; dimensions typically do not correspond to human-understandable features like 'color' or 'size'.
How can we empirically verify that learned word embeddings are meaningful?
Check if similar words cluster together in the embedding space and if analogies hold (e.g., king - man + woman ≈ queen).
In Keras, how do you make the text vectorization layer output integer token indices instead of one-hot vectors?
Set
output_mode='int'in the TextVectorization layer.What is the purpose of an Embedding layer in Keras?
To map integer token indices to dense vector representations (embeddings).
How do you specify the vocabulary size and embedding dimension in a Keras Embedding layer?
Using
input_dim(vocabulary size) andoutput_dim(embedding dimension) arguments.Why do we pad and truncate sequences to a fixed length when using embeddings in Keras?
To create fixed-size input tensors required by neural networks (mini-batches need uniform dimensions).
What does GlobalAveragePooling1D do in a Keras model?
It computes the average of all token embedding vectors along the sequence dimension, producing a single vector per input.
How can you load pre-trained GloVe vectors into a Keras Embedding layer and prevent further training?
Initialize the layer's
weightswith the GloVe matrix and settrainable=False.What does the
mask_zeroparameter do in a Keras Embedding layer?It tells the layer to zero out padding tokens (index 0) so subsequent layers ignore them.
How do you make a Keras Embedding layer trainable after loading pre-trained weights?
Set
trainable=Trueon the layer (or leave default, which is True).What is the index used for padding tokens in Keras text vectorization?
0
What is the index used for unknown (OOV) tokens in Keras text vectorization?
1
When should you use pre-trained word embeddings like GloVe?
When you have a small dataset for the target task, so the model can leverage general linguistic knowledge.
What is a potential drawback of using pre-trained embeddings?
Domain mismatch: the corpus used for pre-training (e.g., Wikipedia) may differ in style from the target task (e.g., song lyrics).
What are the benefits of fine-tuning pre-trained embeddings?
The embeddings adapt to the specific task, often improving performance while still benefiting from the general knowledge.
When might it be better to train your own embeddings from scratch?
When you have a large dataset (e.g., 50,000+ examples) and a specific task, so the model can learn task-specific representations.
In the lecture's Colab, what accuracy was achieved with frozen GloVe embeddings on the song genre classification task?
Approximately 63%.
In the lecture's Colab, what accuracy was achieved with trainable GloVe embeddings?
Approximately 69%.
In the lecture's Colab, what accuracy was achieved with embeddings trained from scratch?
Approximately 72%.

Ask anything
We've read this whole study set, so questions about it get the best answers.