0
0
NLPml~10 mins

Aspect-based sentiment analysis in NLP - Interactive Code Practice

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

Complete the code to load the aspect-based sentiment analysis model.

NLP
from transformers import pipeline

nlp = pipeline([1], model='nlptown/bert-base-multilingual-uncased-sentiment')
Drag options to blanks, or click blank then click option'
A'aspect-based-sentiment-analysis'
B'sentiment-analysis'
C'text-classification'
D'ner'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sentiment-analysis' instead of 'aspect-based-sentiment-analysis'.
Using 'ner' which is for named entity recognition.
2fill in blank
medium

Complete the code to extract aspect terms from the input text.

NLP
text = "The battery life of this phone is amazing but the screen is dull."
results = nlp(text)
aspects = [item['[1]'] for item in results]
Drag options to blanks, or click blank then click option'
Alabel
Baspect
Cscore
Dsentiment
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'label' which usually indicates sentiment polarity.
Using 'score' which is the confidence value.
3fill in blank
hard

Fix the error in the code to correctly get the sentiment label for each aspect.

NLP
for item in results:
    print(item['[1]'])
Drag options to blanks, or click blank then click option'
Alabel
Bsentiment
Caspect
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'aspect' which is the feature, not the sentiment.
Using 'sentiment' which is not a key in the result dictionary.
4fill in blank
hard

Fill both blanks to create a dictionary mapping each aspect to its sentiment label.

NLP
aspect_sentiments = {item[[1]]: item[[2]] for item in results}
Drag options to blanks, or click blank then click option'
A'aspect'
B'label'
C'sentiment'
D'score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sentiment' which is not a valid key.
Using 'score' which is a confidence value, not a label.
5fill in blank
hard

Fill all three blanks to filter aspects with positive sentiment and create a list of their terms.

NLP
positive_aspects = [item[[1]] for item in results if item[[2]] == [3]]
Drag options to blanks, or click blank then click option'
A'aspect'
B'label'
C'positive'
D'score'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' instead of 'label' for sentiment filtering.
Using 'sentiment' which is not a valid key.