Challenge - 5 Problems
Embedding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput shape of embedding layer
What is the shape of the output tensor after passing input indices through this embedding layer?
TensorFlow
import tensorflow as tf embedding = tf.keras.layers.Embedding(input_dim=10, output_dim=4) input_indices = tf.constant([[1, 2, 3], [4, 5, 6]]) output = embedding(input_indices) print(output.shape)
Attempts:
2 left
💡 Hint
Remember the output shape is (batch_size, sequence_length, embedding_dim).
✗ Incorrect
The input has shape (2,3) representing 2 samples each with 3 indices. The embedding layer converts each index to a vector of size 4, so output shape is (2,3,4).
❓ Model Choice
intermediateChoosing embedding input dimension
You have a vocabulary of 5000 unique words. Which input_dim should you use for the embedding layer?
Attempts:
2 left
💡 Hint
input_dim should be at least the max index + 1.
✗ Incorrect
The input_dim parameter must be set to the size of the vocabulary, i.e. maximum integer index +1. For 5000 unique words indexed 0 to 4999, input_dim=5000.
❓ Hyperparameter
advancedEffect of embedding dimension size
What is the main effect of increasing the embedding output_dim size in a model?
Attempts:
2 left
💡 Hint
Think about how embedding size affects model complexity.
✗ Incorrect
Larger embedding dimensions allow the model to learn richer representations but increase parameters, which can lead to overfitting if not enough data is available.
🔧 Debug
advancedIdentify the error in embedding usage
What error will this code raise when run?
TensorFlow
import tensorflow as tf embedding = tf.keras.layers.Embedding(input_dim=5, output_dim=3) input_indices = tf.constant([[1, 2, 5]]) output = embedding(input_indices)
Attempts:
2 left
💡 Hint
Check if input indices are within the allowed range.
✗ Incorrect
The input_dim=5 means valid indices are 0 to 4. Index 5 is out of range and causes an IndexError.
🧠 Conceptual
expertWhy use embedding layers instead of one-hot encoding?
Which reason best explains why embedding layers are preferred over one-hot encoding for representing words in neural networks?
Attempts:
2 left
💡 Hint
Think about how embeddings represent meaning compared to one-hot vectors.
✗ Incorrect
Embedding layers learn dense vector representations that capture word meanings and relationships, unlike sparse one-hot vectors which treat words as unrelated.
