0
0
NLPml~20 mins

Pre-trained embedding usage in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pre-trained Embedding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of embedding vector shape
What is the shape of the output embedding vector when using a pre-trained embedding layer with input size 10 and embedding dimension 50 for a batch of 3 samples?
NLP
import torch
import torch.nn as nn

embedding = nn.Embedding(num_embeddings=10, embedding_dim=50)
input_indices = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
output = embedding(input_indices)
print(output.shape)
Atorch.Size([3, 3])
Btorch.Size([10, 50])
Ctorch.Size([3, 50])
Dtorch.Size([3, 3, 50])
Attempts:
2 left
💡 Hint
Think about the input shape and how embedding layers map indices to vectors.
Model Choice
intermediate
2:00remaining
Choosing pre-trained embeddings for sentiment analysis
You want to build a sentiment analysis model on movie reviews. Which pre-trained embedding is best suited to capture semantic meaning of words in this context?
APre-trained GloVe embeddings trained on Common Crawl
BPre-trained embeddings from a speech recognition model
COne-hot encoded vectors
DRandomly initialized embeddings trained from scratch
Attempts:
2 left
💡 Hint
Consider embeddings trained on large text corpora relevant to general language.
Hyperparameter
advanced
2:00remaining
Effect of freezing pre-trained embeddings
What is the effect of freezing the weights of a pre-trained embedding layer during training?
AThe embedding weights are randomly re-initialized at each epoch
BThe embedding weights are updated during training to adapt to the new task
CThe embedding weights remain fixed and are not updated during training
DThe embedding weights are discarded and replaced with one-hot vectors
Attempts:
2 left
💡 Hint
Freezing means preventing changes to the weights.
Metrics
advanced
2:00remaining
Evaluating embedding quality with downstream task accuracy
You compare two pre-trained embeddings by training the same classifier on a text classification task. Embedding A yields 85% accuracy, embedding B yields 78%. What can you conclude?
AEmbedding B is better because lower accuracy means less overfitting
BEmbedding A is better for this task because it leads to higher accuracy
CBoth embeddings are equally good because accuracy differences are insignificant
DEmbedding B is better because it has fewer parameters
Attempts:
2 left
💡 Hint
Higher accuracy usually means better feature representation for the task.
🔧 Debug
expert
3:00remaining
Identifying error when loading pre-trained embeddings
You try to load pre-trained embeddings into your model but get a size mismatch error. What is the most likely cause?
NLP
import torch
import torch.nn as nn

embedding = nn.Embedding(num_embeddings=1000, embedding_dim=300)
pretrained_weights = torch.randn(500, 300)
embedding.weight.data.copy_(pretrained_weights)
AThe pretrained weights have fewer embeddings (500) than the model expects (1000), causing size mismatch
BThe pretrained weights tensor is not a float tensor
CThe embedding dimension 300 does not match pretrained weights dimension 300
DThe model's embedding layer is not initialized before copying weights
Attempts:
2 left
💡 Hint
Check the shape of pretrained weights vs model embedding weights.