Skip to content

codepath/ai110-module3tinker-themoodmachine-solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Mood Machine — Solution

This is the reference solution for the AI110 Module 3 Tinker The Mood Machine. The stubbed methods are implemented, the dataset is expanded, and the model card is filled in, so you can compare it against the classifier you built. It is one reasonable solution, not the only correct one — the goal of the lab is honest reasoning about model behavior, not a perfect accuracy score.

Starter repo: ai110-module3tinker-themoodmachine-starter

Run it

pip install -r requirements.txt
python main.py            # rule-based model + interactive loop
python ml_experiments.py  # scikit-learn model on the same data

What this solution implements

  • mood_analyzer.py
    • preprocess — lowercases, splits, strips edge punctuation, and preserves emoji/emoticon tokens.
    • score_text — ±1 per matched word, with negation handling: a negation word ("not", "never", …) flips the sign of the next few sentiment words, so "not happy" scores negative. (Negation is the required modeling enhancement.)
    • predict_label — returns mixed when both positive and negative signals fire, otherwise maps the score's sign to positive / negative / neutral.
    • explain — reports the score and the exact positive/negative tokens behind a prediction.
  • dataset.py — word lists expanded (incl. a few emojis/emoticons); SAMPLE_POSTS grown to 15 with slang, sarcasm, emojis, and mixed-feeling posts, all with aligned TRUE_LABELS.
  • model_card.md — filled in with grounded examples of correct and incorrect predictions.

What the results show (and why that's the point)

  • Rule-based accuracy ≈ 0.87. The two misses are both sarcasm — "I absolutely love getting stuck in traffic" and "wow amazing another meeting" — which token counting cannot detect. That failure is the lesson, and it's documented in the model card.
  • ML accuracy = 1.00 on the training set. That looks better, but it's only because the model memorized the 15 examples it was trained on. On genuinely new sarcastic text it would fail the same way. Small data → confident but fragile.

How to check your own work

If your rule-based model handles simple negation, returns a sensible label for obvious cases, and you can explain why it gets sarcasm wrong, you've hit the objectives. Matching this exemplar's exact accuracy is not the goal — being able to trace and document each prediction is.

About

Reference solution for the AI110 Module 3 Tinker: The Mood Machine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages