Bird
0
0

You have this code snippet for domain-specific sentiment training:

medium📝 Debug Q14 of 15
NLP - Sentiment Analysis Advanced
You have this code snippet for domain-specific sentiment training:
texts = ['Good food', 'Bad service']
labels = [1, 0]
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)
model = LogisticRegression()
model.fit(X, labels)

new_text = ['Bad food']
X_new = vectorizer.transform(new_text)
pred = model.predict(X_new)
print(pred)

The output is always [1] even for negative phrases. What is the likely error?
ALabels are reversed in training data.
BThe vectorizer was not fit before transform.
CThe model was trained on too few examples.
DThe new text was not transformed correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check training data size

    Only two examples are used, which is too small for the model to learn properly.
  2. Step 2: Analyze model behavior

    With limited data, the model may predict the majority class or fail to distinguish negative phrases.
  3. Final Answer:

    The model was trained on too few examples. -> Option C
  4. Quick Check:

    Small training data causes poor predictions = A [OK]
Quick Trick: Too few training examples cause wrong predictions [OK]
Common Mistakes:
MISTAKES
  • Assuming vectorizer not fit causes this
  • Thinking labels are reversed
  • Believing transform step is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes