Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' instead of 'train' to load training data.
Using 'all' which is not a valid split.
✗ Incorrect
The 'train' split is used to load the training data for fine-grained sentiment analysis.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The 'sentence' field contains the text to tokenize for sentiment analysis.
3fill in blank
hardFix 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'
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.
✗ Incorrect
Fine-grained sentiment analysis has 5 classes, so num_labels must be 5.
4fill in blank
hardFill 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'
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.
✗ Incorrect
Use accuracy_score for accuracy and f1_score with macro average for balanced F1 across classes.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use dict comprehension to map labels to predictions and filter predictions >= 3 for positive sentiments.