Bird
0
0

Given this code snippet for sentiment prediction, what is the output?

medium📝 Predict Output Q13 of 15
NLP - Sentiment Analysis Advanced
Given this code snippet for sentiment prediction, what is the output?
def predict_sentiment(text):
    # returns dict with sentiment scores
    return {'positive': 0.4, 'neutral': 0.5, 'negative': 0.1}

result = predict_sentiment('I like the movie but the ending was sad')
print(max(result, key=result.get))
Aneutral
Bnegative
Cpositive
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function output

    The function returns a dictionary with sentiment scores: positive=0.4, neutral=0.5, negative=0.1.
  2. Step 2: Determine which sentiment has the highest score

    Using max with key=result.get finds the key with the highest value, which is 'neutral' with 0.5.
  3. Final Answer:

    neutral -> Option A
  4. Quick Check:

    Highest score sentiment = neutral [OK]
Quick Trick: max with key=result.get returns sentiment with highest score [OK]
Common Mistakes:
MISTAKES
  • Choosing positive because it appears first
  • Thinking the function returns a string
  • Expecting an error due to dictionary usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes