Bird
0
0

You want to analyze the sentiment of a list of sentences using VADER and return only those with a compound score above 0.5. Which code snippet correctly implements this?

hard📝 Application Q8 of 15
NLP - Sentiment Analysis Advanced
You want to analyze the sentiment of a list of sentences using VADER and return only those with a compound score above 0.5. Which code snippet correctly implements this?
Aresults = [analyzer.polarity_scores(s) > 0.5 for s in sentences]
Bresults = [s for s in sentences if analyzer.polarity_scores(s)['compound'] > 0.5]
Cresults = [s for s in sentences if analyzer.polarity_scores['compound'] > 0.5]
Dresults = [s for s in sentences if analyzer.polarity_scores(s)['neg'] > 0.5]
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering by compound score

    We want sentences where compound score > 0.5, so we call polarity_scores(s) and check ['compound'].
  2. Step 2: Check list comprehension syntax

    results = [s for s in sentences if analyzer.polarity_scores(s)['compound'] > 0.5] correctly filters sentences by compound score. Others have syntax or logic errors.
  3. Final Answer:

    results = [s for s in sentences if analyzer.polarity_scores(s)['compound'] > 0.5] -> Option B
  4. Quick Check:

    Filter sentences by compound > 0.5 [OK]
Quick Trick: Use polarity_scores(s)['compound'] in list comprehension [OK]
Common Mistakes:
MISTAKES
  • Using polarity_scores without calling it
  • Comparing dict to number
  • Filtering by wrong score like 'neg'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes