AI: sentiment analysis logic
This course covers the logic behind sentiment and tone classification, set around the app's Community::Comment model and using invented feedback examples. A classifier picks one label from a fixed set chosen in advance. A confidence score reports how strong the classifier's signal was and makes no promise about correctness. The lessons show why negation and sarcasm break keyword matching and cover the gains Anthropic's classification guide measures for retrieved examples and chain-of-thought. A naive rule-based classifier is built in plain Ruby and implemented in a graded challenge.
What you'll learn
- ✓Where Community::Comment stores comment text and how to read it as plain text
- ✓Why a classifier's output is one label from a fixed category set
- ✓What a confidence score reports and how it helps with triage
- ✓How negation and sarcasm break keyword matching
- ✓How retrieved examples and chain-of-thought raised accuracy in Anthropic's classification guide
- ✓How to build a rule-based sentiment classifier in plain Ruby
Community::Comment: where tone would matter
app/models/community/comment.rb backs every comment a student leaves on a lesson. Here is the top of the class, without the deleted? helper and the two private validation methods:
Read the full lesson free →Curriculum
7 lessonsCommunity::Comment: where tone would matter
Introduces Community::Comment, where comment text lives in Action Text, and why it suits a tone classifier.
What a classifier outputs: one label from a fixed set
A classifier picks one label from a fixed category set that a person chooses in advance.
Confidence scores, and what they don't promise
A confidence score describes the strength of the classifier's own signal and works as a triage tool.
Sarcasm and negation break simple keyword matching
Invented comments show how negation and sarcasm defeat keyword counting, and why only negation has a mechanical signal.
Retrieved examples and chain-of-thought raise accuracy
Anthropic's classification guide measures accuracy rising from 74% to 94% with retrieved examples and 97% adding chain-of-thought.
Building a rule-based classifier in Ruby, naive on purpose
Builds a plain Ruby classifier that scores keywords, flips them after negators, and maps totals to labels and confidence.
Putting it together: what a keyword classifier can and can't do
Reviews what the keyword classifier handles and what it leaves out, then sets up the classify_feedback challenge.