CS 124 / LING 180 From Languages to Information
Dan Jurafsky, Winter 2020
Week 3: Group Exercises on Naive Bayes and Sentiment - Solutions
Jan 21, 2020
Part 1: Group Exercise
We want to build a naive bayes sentiment classifier using add-1 smoothing,
as described in the lecture (not binary naive bayes, regular naive bayes). Here is our training corpus:
- just plain boring
- entirely predictable and lacks energy
- no surprises and very few laughs
+ very powerful
+ the most fun film of the summer
Test Set:
predictable with no originality
- Compute the prior for the two classes + and -, and the likelihoods for each word given the class
(leave in the form of fractions).
- Then compute whether the sentence in the test set is of class positive or negative (you may need a computer for this final computation).
- Would using binary multinomial Naive Bayes change anything?
- Why do you add |V| to the denominator of add-1 smoothing, instead of just counting the words in one class?
In add-1 smoothing we assume we have seen each word once regardless of whether they appear in the original class or not and thus add |V| to the denominator. Note that words that do not appear in the training set are 'unk' and we just pretend they aren't there, and they are not included in the vocab.
Part 2: Challenge Problems
-
Ethics question: For discussion
-
Go to the Sentiment demo at
http://nlp.stanford.edu:8080/sentiment/rntnDemo.html.
Come up with 5 sentences that the classifier gets wrong.
Can you figure out what is causing the errors?
One example that the classifier gets wrong: "I don't not like you." The double negation is interpreted incorrectly.
- It is sometimes the case that more complex features (like trigrams or bigrams) perform better than simple features (like unigrams) on the training set, but perform worse than simple features
on the test set. This is a particular case of the phenomenon called `overfitting' in machine learning. Discuss why this might be. Can you create a tiny training set with 2 3-word documents and a test set with one document for which this overfitting situation holds?
In overfitting, your model is too complicated for the small amount of data you have,
and the model will fit to random patterns in the data. So a complex feature might just occur accidentally in the training set, but will give it a very high probability. Such a rare `accidental' feature might never occur in the test set, or if it does might simply randomly occur with the other class.
-
Binary multinomial NB seems to work better on some problems than full count NB,
but full count works better on others.
For what kinds of problems might binary NB be better, and why?
(There is no known right answer to this question, but
I'd like you to think about the possibilities.)
Binary NB works better when word occurrence is more important than word frequency, such as in sentiment classification.