Bird
0
0

Examine the following code snippet:

medium📝 Debug Q6 of 15
NLP - Sequence Models for NLP
Examine the following code snippet:
embedding = tf.keras.layers.Embedding(input_dim=10000, output_dim=64)
input_data = tf.constant([[1, 2, 3], [4, 5, 10001]])
output = embedding(input_data)

What is the issue with this code?
AThe output dimension is too large for the input
BThe embedding layer parameters are reversed
CThe input data should be float type, not integer
DThe input contains an index (10001) that exceeds the vocabulary size (10000)
Step-by-Step Solution
Solution:
  1. Step 1: Check input indices against vocabulary size

    Embedding layers accept indices from 0 to input_dim-1. Here, input_dim=10000, so max index is 9999.
  2. Step 2: Identify invalid index

    Input contains 10001, which is out of range and will cause an error.
  3. Step 3: Verify other options

    Parameters are correctly ordered, input type should be integer, and output dimension size is valid.
  4. Final Answer:

    The input contains an index (10001) that exceeds the vocabulary size (10000) -> Option D
  5. Quick Check:

    Input indices must be within vocabulary range [OK]
Quick Trick: Input indices must be less than input_dim [OK]
Common Mistakes:
MISTAKES
  • Using indices outside vocabulary range
  • Passing float inputs instead of integers
  • Confusing input_dim with output_dim

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes