Bird
0
0

Identify the error in the following embedding layer usage:

medium📝 Debug Q14 of 15
NLP - Sequence Models for NLP
Identify the error in the following embedding layer usage:
embedding = tf.keras.layers.Embedding(input_dim=1000, output_dim=64)
input_seq = tf.constant([[0, 1, 2], [999, 1000, 500]])
output = embedding(input_seq)
AThe input sequence contains an index equal to input_dim, which is invalid
BThe output_dim is too large for the input_dim
CEmbedding layer requires input_dim and output_dim to be equal
DThe input sequence must be a list, not a tensor
Step-by-Step Solution
Solution:
  1. Step 1: Check input indices validity

    Embedding indices must be in [0, input_dim-1]. Here, input_dim=1000, so max index is 999.
  2. Step 2: Identify invalid index

    Input sequence contains 1000, which is out of range and causes an error.
  3. Final Answer:

    The input sequence contains an index equal to input_dim, which is invalid -> Option A
  4. Quick Check:

    Indices must be less than input_dim [OK]
Quick Trick: Indices must be less than input_dim [OK]
Common Mistakes:
MISTAKES
  • Using index equal to input_dim
  • Confusing output_dim size limits
  • Thinking input must be list, not tensor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes