Bird
0
0

Given the code below, what is the shape of the output tensor after the embedding layer?

medium📝 Predict Output Q13 of 15
NLP - Sequence Models for NLP
Given the code below, what is the shape of the output tensor after the embedding layer?
import tensorflow as tf
embedding = tf.keras.layers.Embedding(input_dim=5000, output_dim=16)
input_seq = tf.constant([[1, 2, 3], [4, 5, 6]])
output = embedding(input_seq)
print(output.shape)
A(3, 16)
B(3, 2, 16)
C(2, 16)
D(2, 3, 16)
Step-by-Step Solution
Solution:
  1. Step 1: Understand input shape

    Input is a 2D tensor with shape (2, 3) representing 2 sequences each of length 3.
  2. Step 2: Embedding output shape

    Embedding converts each integer to a 16-dimensional vector, so output shape is (2, 3, 16).
  3. Final Answer:

    (2, 3, 16) -> Option D
  4. Quick Check:

    Output shape = (batch_size, sequence_length, embedding_dim) [OK]
Quick Trick: Output shape adds embedding dim to input shape [OK]
Common Mistakes:
MISTAKES
  • Mixing batch and sequence dimensions
  • Forgetting embedding dimension in output
  • Assuming output shape matches input shape exactly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes