0
0
NLPml~20 mins

Embedding layer usage in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Embedding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
Output of embedding layer with given input indices
What is the shape of the output tensor after passing the input indices through the embedding layer?
NLP
import torch
import torch.nn as nn

embedding = nn.Embedding(num_embeddings=10, embedding_dim=4)
input_indices = torch.tensor([1, 3, 7, 9])
output = embedding(input_indices)
output_shape = output.shape
print(output_shape)
Atorch.Size([1, 4])
Btorch.Size([4])
Ctorch.Size([4, 4])
Dtorch.Size([10, 4])
Attempts:
2 left
💡 Hint
The embedding layer converts each index into a vector of the embedding dimension.
Model Choice
intermediate
1:30remaining
Choosing embedding layer parameters for vocabulary size and embedding dimension
You want to create an embedding layer for a vocabulary of 5000 words, each represented by a 50-dimensional vector. Which is the correct way to initialize this embedding layer in PyTorch?
Ann.Embedding(num_embeddings=50, embedding_dim=5000)
Bnn.Embedding(num_embeddings=5000, embedding_dim=50)
Cnn.Embedding(num_embeddings=5000, embedding_dim=5000)
Dnn.Embedding(num_embeddings=50, embedding_dim=50)
Attempts:
2 left
💡 Hint
The first parameter is the vocabulary size, the second is the vector size.
Hyperparameter
advanced
1:30remaining
Effect of embedding dimension size on model performance
Increasing the embedding dimension size in a neural network model typically results in which of the following?
AHigher model capacity but increased risk of overfitting
BLower model capacity and faster training
CNo change in model capacity or training time
DGuaranteed better generalization on unseen data
Attempts:
2 left
💡 Hint
Think about how larger embeddings affect the number of parameters.
🔧 Debug
advanced
1:30remaining
Identifying error in embedding layer input
What error will this code raise when running the embedding layer with the given input? import torch import torch.nn as nn embedding = nn.Embedding(10, 3) input_indices = torch.tensor([1.0, 2.0, 3.0]) output = embedding(input_indices)
ANo error, runs successfully
BTypeError: embedding layer expects a list, not a tensor
CValueError: embedding dimension mismatch
DRuntimeError: 'input' must be a tensor of dtype torch.int64
Attempts:
2 left
💡 Hint
Embedding layers require integer indices, not floats.
🧠 Conceptual
expert
2:00remaining
Why use pretrained embeddings instead of training from scratch?
Which of the following is the main advantage of using pretrained word embeddings in a natural language processing model?
AThey provide rich semantic information learned from large corpora, improving model performance especially with limited data
BThey reduce the model size by compressing the vocabulary
CThey eliminate the need for any further training or fine-tuning
DThey guarantee 100% accuracy on all NLP tasks
Attempts:
2 left
💡 Hint
Think about what pretrained embeddings capture from language data.