- LPU MCA Semester 1
- CAB107
- Unit 6
CAB107 · Unit 6: Natural language processing and vision
Sentiment analysis, text classification and chatbot concepts
10 practice questions · in the ETE syllabus
Key points
- Sentiment analysis finds opinion polarity
- Naive Bayes assumes conditional independence given the class
- Lexicon methods miss sarcasm and context
- Intent is the goal; entities are the details
Sentiment analysis determines the opinion expressed in a text, such as positive, negative or neutral. Text classification assigns a text to a category, for example spam or not spam, using features such as TF-IDF with a classifier like Naive Bayes.
Naive Bayes assumes that features are conditionally independent of each other given the class. This is rarely true but makes training fast and works well on text. Class priors can differ.
Lexicon-based methods such as VADER score text using a dictionary of words with sentiment values and a few rules. They need no training but add up word polarities, so they miss sarcasm and context: Great, another delay! may be scored positive although the writer is annoyed. Machine-learning classifiers learn from labelled examples instead.
A unigram bag-of-words classifier gives not good and good nearly the same evidence, because it treats words separately. Bigram features fix this.
Chatbots work with:
| Term | Meaning | Example: Book a flight to Delhi tomorrow |
|---|---|---|
| Intent | The user's goal | book flight |
| Entity | A detail needed for the goal | Delhi (place), tomorrow (date) |
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB().fit(X_train, y_train)
Exam trap: the intent is the goal, not a detail like a place or date; those are entities.
Try two questions
What assumption does the Naive Bayes classifier make?
- All of the features take identical values in every class of the dataset
- Every feature must be a continuous real number measured on a ratio scale
- Features are conditionally independent of each other given the class
- The classes always have an equal prior probability in the training data
Show the answer
C. Independence makes the likelihood a simple product of per-word probabilities.
Why not A: Features may differ across classes.
Why not B: Naive Bayes also works with counts and categories.
Why not D: Priors can differ.
What is a feature of a lexicon-based sentiment method such as VADER?
- It trains a deep network on millions of labelled images of faces and everyday objects
- It needs no words at all and works directly on the raw audio signal of speech
- It clusters the documents by topic without using any dictionary or lexicon of words
- It scores text using a dictionary of words with sentiment values and a few rules
Show the answer
D. Lexicon-based methods require no training data but rely on word lists.
Why not A: Lexicon methods use word lists, not images.
Why not B: It needs words as input.
Why not C: Clustering is a different technique.