0
0
NLPml~10 mins

Fine-grained sentiment (5-class) 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 dataset for fine-grained sentiment analysis.

NLP
from datasets import load_dataset

dataset = load_dataset('sst', '[1]')
Drag options to blanks, or click blank then click option'
Atrain
Btest
Call
Dvalidation
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' instead of 'train' to load training data.
Using 'all' which is not a valid split.
2fill in blank
medium

Complete the code to tokenize the input sentences for the model.

NLP
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased')
tokens = tokenizer([1], padding=True, truncation=True, return_tensors='pt')
Drag options to blanks, or click blank then click option'
Adataset['sentence']
Bdataset['label']
Cdataset['text']
Ddataset['input']
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to tokenize labels instead of sentences.
Using a wrong field name like 'text' or 'input' which may not exist.
3fill in blank
hard

Fix the error in the model output layer to match 5 sentiment classes.

NLP
from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained('distilbert-base-uncased', num_labels=[1])
Drag options to blanks, or click blank then click option'
A2
B4
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Setting num_labels to 2 or 3 which is for binary or ternary sentiment.
Using 4 which is incorrect for 5-class sentiment.
4fill in blank
hard

Fill both blanks to compute accuracy and macro F1 score for the 5-class sentiment model.

NLP
from sklearn.metrics import [1], [2]

accuracy = [1](true_labels, predictions)
macro_f1 = [2](true_labels, predictions, average='macro')
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bf1_score
Cprecision_score
Drecall_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using precision_score or recall_score instead of f1_score for F1 metric.
Not specifying average='macro' for multi-class F1.
5fill in blank
hard

Fill all three blanks to create a dictionary of predictions with labels and filter positive sentiments.

NLP
pred_dict = [1](label: pred for label, pred in zip(labels, predictions) if pred [2] [3])

# Filter only positive sentiments (labels 3 and 4)
Drag options to blanks, or click blank then click option'
Adict
B>=
C3
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of dict for comprehension.
Using wrong comparison operator like '<' or '==' instead of '>='.
Filtering with wrong threshold value.