Bird
0
0

What is wrong with this code snippet that tries to find the embedding for the word 'apple'?

medium📝 Debug Q7 of 15
NLP - Word Embeddings
What is wrong with this code snippet that tries to find the embedding for the word 'apple'? ```python embedding = glove.get('Apple', None) if embedding is None: print('Word not found') else: print('Embedding found') ```
AThe variable glove is not defined
BThe key 'Apple' has incorrect capitalization
CThe get method does not accept a default value
DEmbedding should be accessed with glove['apple'] without get
Step-by-Step Solution
Solution:
  1. Step 1: Check key case sensitivity

    GloVe keys are lowercase by default, so 'Apple' won't match 'apple'.
  2. Step 2: Understand dictionary get method

    get accepts default value; glove variable assumed defined.
  3. Final Answer:

    The key 'Apple' has incorrect capitalization -> Option B
  4. Quick Check:

    Dictionary keys are case sensitive [OK]
Quick Trick: Use lowercase keys when accessing GloVe embeddings [OK]
Common Mistakes:
MISTAKES
  • Assuming get() lacks default argument
  • Ignoring case sensitivity
  • Confusing dictionary access methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes