0
0
NLPml~10 mins

Multilingual sentiment 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 multilingual sentiment dataset using Hugging Face datasets.

NLP
from datasets import load_dataset

dataset = load_dataset([1], 'multilingual')
Drag options to blanks, or click blank then click option'
A'imdb'
B'squad'
C'glue'
D'amazon_reviews_multi'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'imdb' which is English only.
Using 'glue' which is for English language understanding tasks.
Selecting 'squad' which is for question answering.
2fill in blank
medium

Complete the code to tokenize the input text for multilingual sentiment analysis using a pretrained tokenizer.

NLP
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained([1])
tokens = tokenizer(text, padding=True, truncation=True, return_tensors='pt')
Drag options to blanks, or click blank then click option'
A'bert-base-uncased'
B'xlm-roberta-base'
C'distilbert-base-uncased'
D'roberta-base'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bert-base-uncased' which is English only.
Choosing 'distilbert-base-uncased' which is English only.
Selecting 'roberta-base' which is English only.
3fill in blank
hard

Fix the error in the model loading code for multilingual sentiment classification.

NLP
from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained([1], num_labels=3)
Drag options to blanks, or click blank then click option'
A'bert-base-multilingual-cased'
B'xlm-roberta-base'
C'bert-base-uncased'
D'distilbert-base-uncased'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bert-base-uncased' which is English only.
Choosing 'xlm-roberta-base' without fine-tuning for classification.
Selecting 'distilbert-base-uncased' which is English only.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each review text to its sentiment label.

NLP
sentiment_dict = { [1]: [2] for example in dataset['train'] }
Drag options to blanks, or click blank then click option'
Aexample['review_body']
Bexample['star_rating']
Cexample['text']
Dexample['sentiment']
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'text' which does not exist in the dataset.
Using 'sentiment' which does not exist in this dataset.
5fill in blank
hard

Fill all three blanks to compute accuracy of the model predictions.

NLP
correct = sum(1 for pred, true in zip(predictions, labels) if pred [1] true)
accuracy = correct [2] len(labels)
print(f'Accuracy: {accuracy:.2f}')
Drag options to blanks, or click blank then click option'
A==
B/
C*
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causing wrong accuracy calculation.
Multiplying instead of dividing for accuracy.