Challenge - 5 Problems
GloVe Embedding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the shape of the embedding matrix after loading GloVe vectors?
Given a vocabulary size of 10000 and embedding dimension of 50, after loading GloVe embeddings into a TensorFlow Embedding layer, what will be the shape of the embedding matrix?
TensorFlow
import numpy as np import tensorflow as tf vocab_size = 10000 embedding_dim = 50 embedding_matrix = np.zeros((vocab_size, embedding_dim)) embedding_layer = tf.keras.layers.Embedding(input_dim=vocab_size, output_dim=embedding_dim, weights=[embedding_matrix], trainable=False) print(embedding_layer.weights[0].shape)
Attempts:
2 left
💡 Hint
Remember the embedding matrix shape is (vocab_size, embedding_dim).
✗ Incorrect
The embedding matrix has one row per word in the vocabulary and one column per embedding dimension. So shape is (10000, 50).
❓ Model Choice
intermediateWhich TensorFlow layer correctly uses pre-trained GloVe embeddings?
You want to use pre-trained GloVe embeddings in a TensorFlow model. Which layer setup correctly loads the embeddings and prevents them from updating during training?
Attempts:
2 left
💡 Hint
Embedding layer input_dim is vocab size, output_dim is embedding size.
✗ Incorrect
Option A correctly sets input_dim and output_dim, loads weights, and disables training to keep embeddings fixed.
❓ Hyperparameter
advancedWhat is the effect of setting trainable=True on a pre-trained GloVe embedding layer?
If you set trainable=True on a TensorFlow Embedding layer initialized with pre-trained GloVe embeddings, what happens during training?
Attempts:
2 left
💡 Hint
trainable=True means weights can change during backpropagation.
✗ Incorrect
Setting trainable=True allows the model to adjust the embeddings to better fit the training data.
🔧 Debug
advancedWhy does this code raise a ValueError when loading GloVe embeddings?
Consider this code snippet:
embedding_dim = 100
embedding_matrix = np.zeros((vocab_size, embedding_dim))
for word, i in word_index.items():
embedding_vector = embeddings_index.get(word)
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
It raises a ValueError: could not broadcast input array from shape (50,) into shape (100,). Why?
Attempts:
2 left
💡 Hint
Check the dimension of the loaded GloVe vectors vs embedding_matrix.
✗ Incorrect
The error occurs because the GloVe vectors have 50 dimensions but embedding_matrix expects 100 dimensions per vector.
🧠 Conceptual
expertWhy use pre-trained GloVe embeddings instead of training embeddings from scratch?
Which of the following is the best reason to use pre-trained GloVe embeddings in a natural language processing model?
Attempts:
2 left
💡 Hint
Think about what pre-trained embeddings capture from language data.
✗ Incorrect
Pre-trained embeddings capture semantic relationships from large text corpora, helping models generalize better especially when training data is small.
