Bird
0
0

Given the following Python code snippet using the 'nlptown/bert-base-multilingual-uncased-sentiment' model, what will be the output sentiment label for the input text "Je suis très content" (French for "I am very happy")?

medium📝 Predict Output Q13 of 15
NLP - Sentiment Analysis Advanced
Given the following Python code snippet using the 'nlptown/bert-base-multilingual-uncased-sentiment' model, what will be the output sentiment label for the input text "Je suis très content" (French for "I am very happy")?
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

tokenizer = AutoTokenizer.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')
model = AutoModelForSequenceClassification.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')

inputs = tokenizer("Je suis très content", return_tensors="pt")
outputs = model(**inputs)
probs = torch.nn.functional.softmax(outputs.logits, dim=1)
label = torch.argmax(probs).item() + 1  # labels 1 to 5
print(label)
A1 (Very Negative)
B5 (Very Positive)
C3 (Neutral)
D2 (Negative)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the input sentiment

    The French sentence "Je suis très content" means "I am very happy", which is a positive sentiment.
  2. Step 2: Interpret model output labels

    The model outputs labels from 1 (very negative) to 5 (very positive). Since the sentence is very positive, the highest probability label should be 5.
  3. Final Answer:

    5 (Very Positive) -> Option B
  4. Quick Check:

    Positive sentence = label 5 [OK]
Quick Trick: Happy words usually map to highest positive label [OK]
Common Mistakes:
MISTAKES
  • Confusing label numbers with sentiment polarity
  • Ignoring language and assuming English only
  • Not adding 1 to zero-based index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes