Bird
0
0

You run this code to analyze sentiment but get an error:

medium📝 Debug Q14 of 15
NLP - Sentiment Analysis Advanced
You run this code to analyze sentiment but get an error:
from transformers import AutoTokenizer, AutoModelForSequenceClassification

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

inputs = tokenizer('Das ist schlecht', return_tensors='pt')
outputs = model(inputs)
What is the cause of the error?
AMissing import for torch library.
BTokenizer is loaded after the model, causing mismatch.
CThe input text is in German, which the model cannot process.
DModel expects keyword arguments, but inputs passed as positional argument.
Step-by-Step Solution
Solution:
  1. Step 1: Check how model is called

    The model expects inputs as keyword arguments like model(**inputs), but here inputs are passed as a single positional argument.
  2. Step 2: Analyze other options

    Tokenizer order does not cause error. The model supports German. Missing torch import would cause a different error.
  3. Final Answer:

    Model expects keyword arguments, but inputs passed as positional argument. -> Option D
  4. Quick Check:

    Use model(**inputs) not model(inputs) [OK]
Quick Trick: Pass inputs with ** to model call [OK]
Common Mistakes:
MISTAKES
  • Passing inputs without unpacking as keyword args
  • Blaming language support incorrectly
  • Ignoring error message details

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes