Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sentiment-analysis' instead of 'aspect-based-sentiment-analysis'.
Using 'ner' which is for named entity recognition.
✗ Incorrect
The pipeline type for aspect-based sentiment analysis is 'aspect-based-sentiment-analysis'.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'label' which usually indicates sentiment polarity.
Using 'score' which is the confidence value.
✗ Incorrect
The key 'aspect' holds the aspect term extracted from the text.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The sentiment label is stored under the key 'label' in each result item.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sentiment' which is not a valid key.
Using 'score' which is a confidence value, not a label.
✗ Incorrect
The dictionary keys are aspect terms ('aspect') and values are sentiment labels ('label').
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' instead of 'label' for sentiment filtering.
Using 'sentiment' which is not a valid key.
✗ Incorrect
We select the 'aspect' terms where the 'label' equals 'positive'.