Challenge - 5 Problems
Embedding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1: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)
Attempts:
2 left
💡 Hint
The embedding layer converts each index into a vector of the embedding dimension.
✗ Incorrect
The input tensor has 4 indices, and each index is converted into a vector of size 4, so the output shape is (4, 4).
❓ Model Choice
intermediate1: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?
Attempts:
2 left
💡 Hint
The first parameter is the vocabulary size, the second is the vector size.
✗ Incorrect
The embedding layer's first argument is the number of unique tokens (vocabulary size), and the second is the size of each embedding vector.
❓ Hyperparameter
advanced1: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?
Attempts:
2 left
💡 Hint
Think about how larger embeddings affect the number of parameters.
✗ Incorrect
Larger embedding dimensions increase the number of parameters, which can improve capacity but also risk overfitting if not managed.
🔧 Debug
advanced1: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)
Attempts:
2 left
💡 Hint
Embedding layers require integer indices, not floats.
✗ Incorrect
Embedding layers require input tensors of integer type (torch.int64). Passing floats causes a runtime error.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about what pretrained embeddings capture from language data.
✗ Incorrect
Pretrained embeddings capture semantic relationships from large datasets, helping models generalize better when training data is limited.