1. Home
  2. Explore
  3. Computer Science
  4. Word Embeddings in NLP

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Word Embeddings in NLP

  • 20Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Word Embedding Fundamentals

What is the Euclidean distance between any two distinct one-hot vectors in a vocabulary of size VVV?

20 questions

  1. 1

    What is the Euclidean distance between any two distinct one-hot vectors in a vocabulary of size VVV?

    1. A

      000

    2. B

      111

    3. C

      2\sqrt{2}2​

    4. D

      VVV

    Correct answer
    C

    2\sqrt{2}2​

    Explanation

    Two distinct one-hot vectors have a 1 in different positions, so the squared differences sum to 12+12=21^2 + 1^2 = 212+12=2, giving distance 2\sqrt{2}2​.

  2. 2

    What is a major shortcoming of one-hot encoding for representing word meaning?

    1. A

      Vectors are too short to capture meaning.

    2. B

      They inherently capture contextual relationships between words.

    3. C

      The distance between any two distinct word vectors is identical.

    4. D

      They produce dense vectors that are hard to store.

    Correct answer
    C

    The distance between any two distinct word vectors is identical.

    Explanation

    Any two distinct one-hot vectors have the same Euclidean distance (2\sqrt{2}2​), so they fail to encode semantic similarity.

  3. 3

    In the context of one-hot vectors, what is the Euclidean distance between the vectors for 'good' and 'bad'?

    1. A

      111

    2. B

      000

    3. C

      2\sqrt{2}2​

    4. D

      It depends on the vocabulary size.

    Correct answer
    C

    2\sqrt{2}2​

    Explanation

    The vectors are one-hot, so regardless of the words, the distance is always 2\sqrt{2}2​.

  4. 4

    What does the co-occurrence matrix XXX in GloVe represent?

    1. A

      The frequency of each word in the corpus.

    2. B

      The pointwise mutual information between words.

    3. C

      The number of times each pair of words appears in the same sentence across the corpus.

    4. D

      The TF-IDF score for each word pair.

    Correct answer
    C

    The number of times each pair of words appears in the same sentence across the corpus.

    Explanation

    Each entry XijX_{ij}Xij​ counts how many times word iii and word jjj co-occur in the same sentence in the entire corpus.

  5. 5

    According to the GloVe model, how is the logarithm of the co-occurrence count log⁡Xij\log X_{ij}logXij​ modeled?

    1. A

      wi+wj\mathbf{w}_i + \mathbf{w}_jwi​+wj​

    2. B

      bi+bjb_i + b_jbi​+bj​

    3. C

      wi⋅wj+bi+bj\mathbf{w}_i \cdot \mathbf{w}_j + b_i + b_jwi​⋅wj​+bi​+bj​

    4. D

      wi⋅wj\mathbf{w}_i \cdot \mathbf{w}_jwi​⋅wj​

    Correct answer
    C

    wi⋅wj+bi+bj\mathbf{w}_i \cdot \mathbf{w}_j + b_i + b_jwi​⋅wj​+bi​+bj​

    Explanation

    The GloVe model posits log⁡Xij=wi⋅wj+bi+bj\log X_{ij} = \mathbf{w}_i \cdot \mathbf{w}_j + b_i + b_jlogXij​=wi​⋅wj​+bi​+bj​, where w\mathbf{w}w are embedding vectors and bbb are bias terms.

  6. 6

    Why is the logarithm of co-occurrence counts used in the GloVe model?

    1. A

      To avoid the problem of zero counts.

    2. B

      To squash the wide range of counts and make regression better behaved.

    3. C

      To ensure all values are positive.

    4. D

      To make the data normally distributed.

    Correct answer
    B

    To squash the wide range of counts and make regression better behaved.

    Explanation

    Co-occurrence counts have a long-tailed distribution; taking the logarithm compresses the range, making the regression model more stable and effective.

  7. 7

    In GloVe, what do the bias terms bib_ibi​ represent?

    1. A

      The total number of co-occurrences of word iii with all other words.

    2. B

      The embedding vector for word iii.

    3. C

      The inherent popularity or natural frequency of word iii.

    4. D

      The dot product of the embedding of word iii with itself.

    Correct answer
    C

    The inherent popularity or natural frequency of word iii.

    Explanation

    The bias bib_ibi​ captures the overall frequency of word iii, independent of its relationship to other words.

  8. 8

    How are the embedding vectors in GloVe learned?

    1. A

      By applying singular value decomposition to the co-occurrence matrix.

    2. B

      By maximizing the likelihood of word sequences in a corpus.

    3. C

      By minimizing the mean squared error between predicted and actual log co-occurrence counts.

    4. D

      By solving a system of linear equations.

    Correct answer
    C

    By minimizing the mean squared error between predicted and actual log co-occurrence counts.

    Explanation

    GloVe treats the model as a regression problem: it minimizes the sum of squared differences between log⁡Xij\log X_{ij}logXij​ and wi⋅wj+bi+bj\mathbf{w}_i \cdot \mathbf{w}_j + b_i + b_jwi​⋅wj​+bi​+bj​.

  9. 9

    What optimization algorithm is commonly used to learn GloVe embeddings?

    1. A

      Newton's method

    2. B

      Genetic algorithm

    3. C

      Gradient descent or stochastic gradient descent

    4. D

      Expectation-Maximization

    Correct answer
    C

    Gradient descent or stochastic gradient descent

    Explanation

    Gradient descent (often stochastic) is used because the objective function is differentiable and the problem is large-scale.

  10. 10

    What is a key advantage of word embeddings over one-hot vectors?

    1. A

      They are sparse and memory efficient.

    2. B

      They are high-dimensional and preserve all information.

    3. C

      They are easier to compute for large vocabularies.

    4. D

      They capture semantic relationships between words via vector geometry.

    Correct answer
    D

    They capture semantic relationships between words via vector geometry.

    Explanation

    Word embeddings are dense and learned so that similar words have similar vectors, enabling semantic operations like analogy solving.

  11. 11

    The embedding analogy 'king - man + woman ≈ queen' demonstrates what property?

    1. A

      Embeddings are only capable of representing nouns.

    2. B

      Embeddings are random and unpredictable.

    3. C

      Embeddings capture analogical relationships through vector arithmetic.

    4. D

      Embeddings are linearly separable.

    Correct answer
    C

    Embeddings capture analogical relationships through vector arithmetic.

    Explanation

    Such analogies show that the learned embedding space encodes meaningful semantic directions, e.g., gender, royalty.

  12. 12

    When is it most beneficial to use pre-trained word embeddings like GloVe?

    1. A

      When you have a small dataset and want to leverage general language knowledge.

    2. B

      When you have a very large dataset for your specific task.

    3. C

      Only when you cannot train your own embeddings.

    4. D

      When you do not care about domain-specific vocabulary.

    Correct answer
    A

    When you have a small dataset and want to leverage general language knowledge.

    Explanation

    Pre-trained embeddings provide a good starting point learned from massive corpora, which helps when task-specific data is limited.

  13. 13

    What is a potential drawback of using pre-trained GloVe embeddings for a medical text classification task?

    1. A

      They may not accurately capture domain-specific medical jargon.

    2. B

      They require more training data than available.

    3. C

      They cannot be fine-tuned for the specific task.

    4. D

      The embeddings are too large to load.

    Correct answer
    A

    They may not accurately capture domain-specific medical jargon.

    Explanation

    Pre-trained embeddings are trained on general text (e.g., Wikipedia) and may not represent specialized terminology well.

  14. 14

    How does the choice of embedding dimension (e.g., 100 vs 300) affect model capacity?

    1. A

      Lower dimension is always better to avoid overfitting.

    2. B

      Higher dimension always reduces capacity.

    3. C

      Higher dimension increases capacity but also the risk of overfitting.

    4. D

      Dimension has no effect on capacity.

    Correct answer
    C

    Higher dimension increases capacity but also the risk of overfitting.

    Explanation

    Increasing the embedding dimension adds more parameters, increasing capacity to capture nuances but also the risk of overfitting, especially with limited data.

  15. 15

    In Keras, after applying the TextVectorization layer with output_mode='int', what does the Embedding layer do?

    1. A

      It converts integers back to one-hot vectors.

    2. B

      It applies a linear transformation to the integers.

    3. C

      It averages the input sequence of integers.

    4. D

      It looks up the embedding vector for each integer token from a learned table.

    Correct answer
    D

    It looks up the embedding vector for each integer token from a learned table.

    Explanation

    The Embedding layer is a lookup table that maps each integer index to a dense vector (the embedding).

  16. 16

    What is the purpose of padding sequences in natural language processing?

    1. A

      To add contextual information to each token.

    2. B

      To remove stop words from the input.

    3. C

      To reduce the size of the vocabulary.

    4. D

      To ensure all input sequences have the same length for batch processing.

    Correct answer
    D

    To ensure all input sequences have the same length for batch processing.

    Explanation

    Neural networks expect fixed-size inputs; padding (and truncation) standardizes sequence lengths so they can be processed together in batches.

  17. 17

    In a Keras Embedding layer, what does the max_tokens parameter specify?

    1. A

      The number of training epochs.

    2. B

      The size of the vocabulary (number of rows in the embedding matrix).

    3. C

      The maximum length of input sequences.

    4. D

      The dimensionality of each embedding vector.

    Correct answer
    B

    The size of the vocabulary (number of rows in the embedding matrix).

    Explanation

    max_tokens sets the vocabulary size, i.e., the number of distinct tokens for which the layer will store an embedding vector.

  18. 18

    What is the effect of setting trainable=False on an Embedding layer initialized with pre-trained weights?

    1. A

      The pre-trained weights will be randomly reinitialized.

    2. B

      The embeddings will be used only for testing.

    3. C

      The embeddings will not be updated during backpropagation.

    4. D

      The layer will be removed from the model.

    Correct answer
    C

    The embeddings will not be updated during backpropagation.

    Explanation

    Setting trainable=False freezes the weights, so they remain fixed during training, preserving the pre-trained values.

  19. 19

    What does a GlobalAveragePooling1D layer do to a sequence of embedding vectors?

    1. A

      It concatenates all vectors into one long vector.

    2. B

      It computes the average of each feature dimension across all time steps.

    3. C

      It reduces the sequence length by half.

    4. D

      It applies a 1D convolutional filter over the sequence.

    Correct answer
    B

    It computes the average of each feature dimension across all time steps.

    Explanation

    GlobalAveragePooling1D takes the mean over the time axis, producing a single vector that is the element-wise average of all embedding vectors in the sequence.

  20. 20

    In the lecture, why did training the whole model (including embeddings) from scratch outperform using frozen GloVe embeddings on the song lyrics dataset?

    1. A

      The dataset was large enough to learn domain-specific representations from scratch.

    2. B

      GloVe embeddings are inherently low quality.

    3. C

      The vocabulary size was too small for GloVe.

    4. D

      The model began to overfit with frozen embeddings.

    Correct answer
    A

    The dataset was large enough to learn domain-specific representations from scratch.

    Explanation

    With 50,000 examples, the model could learn embeddings tailored to the lyrics domain, whereas frozen GloVe embeddings (trained on Wikipedia) were less suited for the task.

Question 1 of 20
Question 1 of 20

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent