0
0
NLPml~10 mins

Why advanced sentiment handles nuance in NLP - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a pre-trained sentiment analysis model.

NLP
from transformers import pipeline
sentiment_analyzer = pipeline([1])
Drag options to blanks, or click blank then click option'
A'text-classification'
B'translation_en_to_fr'
C'ner'
D'sentiment-analysis'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text-classification' which is more general and may not handle nuance well.
Choosing unrelated pipelines like 'ner' or translation.
2fill in blank
medium

Complete the code to analyze sentiment of the sentence.

NLP
result = sentiment_analyzer([1])[0]
print(result)
Drag options to blanks, or click blank then click option'
A['I love this movie!']
B'I love this movie!'
CI love this movie!
D('I love this movie!')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a plain string instead of a list causes errors.
Using parentheses creates a tuple, which is not accepted.
3fill in blank
hard

Fix the error in the code to get the sentiment label.

NLP
label = result[1]['label']
print(label)
Drag options to blanks, or click blank then click option'
A.
B{
C[
D(
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation causes AttributeError.
Using parentheses or curly braces causes syntax errors.
4fill in blank
hard

Fill both blanks to create a function that returns sentiment label and score.

NLP
def analyze_sentiment(text):
    result = sentiment_analyzer([text])[[1]]
    return result[2]
Drag options to blanks, or click blank then click option'
A0
B'label'
C['label']
D'score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string '0' instead of integer 0 for indexing.
Using dot notation instead of square brackets for dictionary keys.
5fill in blank
hard

Fill all three blanks to create a function that returns both label and score from sentiment analysis.

NLP
def analyze_sentiment_details(text):
    result = sentiment_analyzer([text])[[1]]
    label = result[2]
    score = result[3]
    return label, score
Drag options to blanks, or click blank then click option'
A0
B['label']
C['score']
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for indexing causes IndexError.
Using dot notation instead of square brackets for dictionary keys.