Skip to content

Commit 3c19282

Browse files
authored
feat: improve classification quality - 6 intents, reasoning examples, eval harness (#36)
Intent consolidation (9 -> 6): - engagement_bait absorbs reaction_farming (same action: hide, same framing) - hype absorbs clickbait (same action: tag, both = deceptive urgency) - genuine absorbs neutral (same action: pass, both = no manipulation) - Fewer overlapping categories = cleaner model decision boundaries Few-shot examples: - Increase prompt cap from 5 to 16 (MAX_FEW_SHOT_EXAMPLES constant) - Add reasoning field to all examples - teaches decision logic not just labels - Weight examples toward boundary cases (ragebait/divisive, hype/genuine, fearmongering/genuine, engagement_bait/divisive) where the model most errs - New intents.yaml has 16 examples with explicit reasoning for each Rules: - Explicitly state merged categories so the model doesn't try to use old labels - Sharper boundary rules: ragebait=anger, divisive=side-picking, facts+source=genuine - Remove dead rules (clickbait, reaction_farming specific rules now covered by hype/engagement_bait) Eval harness: - eval/test_set.yaml: 48 labeled examples, 8 per intent - 4-5 clear cases + 3-4 boundary cases per intent - Boundary cases annotated with notes explaining the confusion risk - eval/run_eval.py: async eval runner - Per-intent accuracy breakdown with visual bar - Full list of wrong classifications with reasoning for debugging - --verbose, --filter, --test-set flags - Run: python eval/run_eval.py Extension: - Remove dead intent labels (clickbait, reaction_farming, neutral) from formatIntent()
1 parent 8b9a321 commit 3c19282

5 files changed

Lines changed: 479 additions & 198 deletions

File tree

eval/run_eval.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/usr/bin/env python3
2+
"""
3+
IntentKeeper Classification Eval Harness
4+
5+
Runs the labeled test set through the classifier and reports accuracy.
6+
Use this to measure whether prompt/example/rule changes actually help.
7+
8+
Usage:
9+
python eval/run_eval.py
10+
python eval/run_eval.py --verbose # show every item
11+
python eval/run_eval.py --filter ragebait # one intent only
12+
python eval/run_eval.py --test-set path/to/other.yaml
13+
14+
Run from the repo root.
15+
"""
16+
17+
import argparse
18+
import asyncio
19+
import sys
20+
from collections import defaultdict
21+
from pathlib import Path
22+
23+
import yaml
24+
25+
# Allow importing server modules from the repo root
26+
sys.path.insert(0, str(Path(__file__).parent.parent))
27+
28+
from server.classifier import IntentClassifier # noqa: E402
29+
30+
31+
def load_test_set(path: str, filter_intent: str | None = None) -> list[dict]:
32+
with open(path) as f:
33+
items = yaml.safe_load(f)
34+
if filter_intent:
35+
items = [i for i in items if i["expected_intent"] == filter_intent]
36+
return items
37+
38+
39+
async def run(test_set: list[dict], verbose: bool) -> None:
40+
classifier = IntentClassifier()
41+
42+
total = len(test_set)
43+
correct = 0
44+
per_intent: dict[str, dict] = defaultdict(lambda: {"total": 0, "correct": 0})
45+
wrong: list[dict] = []
46+
47+
print(f"\nRunning {total} examples...\n")
48+
49+
for item in test_set:
50+
content = item["content"]
51+
expected = item["expected_intent"]
52+
note = item.get("note", "")
53+
54+
result = await classifier.classify(content)
55+
got = result.intent
56+
is_correct = got == expected
57+
58+
per_intent[expected]["total"] += 1
59+
if is_correct:
60+
correct += 1
61+
per_intent[expected]["correct"] += 1
62+
else:
63+
wrong.append(
64+
{
65+
"content": content,
66+
"expected": expected,
67+
"got": got,
68+
"confidence": result.confidence,
69+
"reasoning": result.reasoning,
70+
"note": note,
71+
}
72+
)
73+
74+
if verbose:
75+
status = "✓" if is_correct else "✗"
76+
print(f" {status} [{expected:>16}] -> [{got:<16}] {content[:60]}")
77+
78+
await classifier.close()
79+
80+
# ── Summary ──────────────────────────────────────────────────────────────
81+
82+
pct = correct / total * 100 if total else 0
83+
print(f"\n{'─' * 60}")
84+
print(f" Overall accuracy: {correct}/{total} ({pct:.0f}%)")
85+
print(f"{'─' * 60}\n")
86+
87+
# Per-intent breakdown
88+
print(f" {'Intent':<20} {'Correct':>7} {'Total':>5} {'Acc':>5}")
89+
print(f" {'─' * 20} {'─' * 7} {'─' * 5} {'─' * 5}")
90+
for intent, counts in sorted(per_intent.items()):
91+
t = counts["total"]
92+
c = counts["correct"]
93+
acc = c / t * 100 if t else 0
94+
bar = "█" * c + "░" * (t - c)
95+
print(f" {intent:<20} {c:>7} {t:>5} {acc:>4.0f}% {bar}")
96+
97+
# Wrong classifications
98+
if wrong:
99+
print(f"\n Wrong ({len(wrong)}):\n")
100+
for w in wrong:
101+
print(f" expected: {w['expected']}")
102+
print(f" got: {w['got']} (confidence {w['confidence']:.2f})")
103+
print(f" content: {w['content'][:80]}")
104+
if w["note"]:
105+
print(f" note: {w['note']}")
106+
print(f" reason: {w['reasoning']}")
107+
print()
108+
else:
109+
print("\n No wrong classifications. 🎉\n")
110+
111+
112+
def main() -> None:
113+
parser = argparse.ArgumentParser(description="Run IntentKeeper classification eval")
114+
parser.add_argument(
115+
"--test-set",
116+
default="eval/test_set.yaml",
117+
help="Path to labeled test set YAML (default: eval/test_set.yaml)",
118+
)
119+
parser.add_argument(
120+
"--verbose",
121+
action="store_true",
122+
help="Print every item as it's classified",
123+
)
124+
parser.add_argument(
125+
"--filter",
126+
metavar="INTENT",
127+
help="Only run examples for this intent",
128+
)
129+
args = parser.parse_args()
130+
131+
test_set = load_test_set(args.test_set, filter_intent=args.filter)
132+
if not test_set:
133+
print(f"No examples found (filter={args.filter!r})")
134+
sys.exit(1)
135+
136+
asyncio.run(run(test_set, verbose=args.verbose))
137+
138+
139+
if __name__ == "__main__":
140+
main()

eval/test_set.yaml

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# IntentKeeper Eval Test Set
2+
#
3+
# 48 labeled examples, 8 per intent.
4+
# Each intent has 4-5 clear cases and 3-4 boundary/tricky cases.
5+
# Boundary cases are marked with a note explaining why they might be confused.
6+
#
7+
# To add new examples: add to the appropriate intent section.
8+
# To run: python eval/run_eval.py
9+
10+
# ─── ragebait ───────────────────────────────────────────────────────────────
11+
12+
- content: "This is EXACTLY why I can't stand these people. Every. Single. Time."
13+
expected_intent: ragebait
14+
note: "clear - absolutist framing, tribal contempt"
15+
16+
- content: "Anyone who defends this after everything that's happened has no moral compass. Full stop."
17+
expected_intent: ragebait
18+
note: "clear - absolutist judgment designed to provoke anger"
19+
20+
- content: "The media LOVES burying this story. Wonder why? 🤔🤔"
21+
expected_intent: ragebait
22+
note: "clear - conspiracy insinuation with contemptuous tone"
23+
24+
- content: "I used to try to have good-faith debates online. Then I realised some people are just bad."
25+
expected_intent: ragebait
26+
note: "subtle - sounds reflective but the conclusion (some people are just bad) is designed to provoke contempt"
27+
28+
- content: "How is this person still employed? The absolute audacity."
29+
expected_intent: ragebait
30+
note: "clear - contemptuous outrage bait"
31+
32+
# boundary: divisive framing but anger is the primary signal
33+
- content: "People who vote for that party have decided they're fine with cruelty. They own that."
34+
expected_intent: ragebait
35+
note: "boundary ragebait/divisive - moral accusation designed to make you angry, not just sort you into a tribe"
36+
37+
# boundary: looks like fearmongering but anger is the driver
38+
- content: "They're actively trying to destroy this country and half the population is cheering it on. Wake up."
39+
expected_intent: ragebait
40+
note: "boundary ragebait/fearmongering - threat framing but the primary signal is contempt and anger at 'half the population'"
41+
42+
# boundary: sarcasm that reads politely
43+
- content: "Oh wow, another expert who's never worked a real job in their life telling us how things should be. So helpful."
44+
expected_intent: ragebait
45+
note: "boundary - polite sarcasm masking contempt designed to provoke class anger"
46+
47+
# ─── fearmongering ───────────────────────────────────────────────────────────
48+
49+
- content: "By the time most people realise what's happening it will be too late. The signs are already there."
50+
expected_intent: fearmongering
51+
note: "clear - vague ominous prediction with no facts"
52+
53+
- content: "Your water, your food, your air. They've been poisoning it for decades and nobody talks about it."
54+
expected_intent: fearmongering
55+
note: "clear - conspiracy fearmongering with vague 'they'"
56+
57+
- content: "The economy is about to completely implode. I've never been more certain of anything in my life."
58+
expected_intent: fearmongering
59+
note: "clear - doom prediction with false certainty and no evidence"
60+
61+
- content: "🚨 ALERT: Something is being quietly rolled out that will affect every household. Read before they delete this."
62+
expected_intent: fearmongering
63+
note: "clear - vague threat with alarm signals and false urgency"
64+
65+
- content: "Doctors are starting to speak out about what they've been told not to say. It's worse than you think."
66+
expected_intent: fearmongering
67+
note: "clear - false insider knowledge framing with vague threat"
68+
69+
# boundary: alarming but cites specific source and facts
70+
- content: "WHO data: global average temperatures are now 1.45°C above pre-industrial levels. The 1.5°C threshold could be crossed within 5 years."
71+
expected_intent: genuine
72+
note: "boundary fearmongering/genuine - alarming content but has specific source, specific number, specific timeframe. Facts with sources = genuine."
73+
74+
# boundary: sounds informational but is actually fearmongering
75+
- content: "Experts are warning about what's coming this winter. Most people aren't prepared. Are you?"
76+
expected_intent: fearmongering
77+
note: "boundary - vague 'experts warning' with no specifics. The question at the end is designed to trigger anxiety, not inform."
78+
79+
# boundary: genuine personal fear vs manufactured fearmongering
80+
- content: "Honestly worried about job security with all the layoffs happening. Anyone else feeling this?"
81+
expected_intent: genuine
82+
note: "boundary - genuine expression of personal anxiety. Not manufacturing fear in others - sharing an honest feeling."
83+
84+
# ─── hype ────────────────────────────────────────────────────────────────────
85+
86+
- content: "Drop everything. This thread is the most important thing you will read this year."
87+
expected_intent: hype
88+
note: "clear - manufactured urgency with zero substance"
89+
90+
- content: "I spent 6 months testing 47 productivity apps. This ONE changed everything. I should have found it sooner."
91+
expected_intent: hype
92+
note: "clear - classic hype formula: exhaustive effort + single magic solution"
93+
94+
- content: "The Truth About Sleep That Nobody Is Telling You (And Why They're Hiding It)"
95+
expected_intent: hype
96+
note: "clear - clickbait title with false conspiracy framing"
97+
98+
- content: "This is the skill that separates the 1% from everyone else. I'm giving it away for free. For now."
99+
expected_intent: hype
100+
note: "clear - false exclusivity + scarcity trigger ('for now')"
101+
102+
- content: "Big announcement next week that will change everything about how we work. Stay tuned."
103+
expected_intent: hype
104+
note: "clear - manufactured anticipation with no substance"
105+
106+
# boundary: looks like hype but is genuine product news
107+
- content: "We're shipping v2.0 next Tuesday. Full changelog here. Breaking change in the auth module - read before upgrading."
108+
expected_intent: genuine
109+
note: "boundary hype/genuine - announcement with specific date, specific details, and a warning. Substance makes it genuine."
110+
111+
# boundary: genuine enthusiasm that sounds like hype
112+
- content: "This new paper on LLM reasoning is fascinating. Section 4 specifically upends some assumptions I've had for years."
113+
expected_intent: genuine
114+
note: "boundary - enthusiastic but cites a specific source and a specific section. Enthusiasm backed by specifics = genuine."
115+
116+
# boundary: vague positive framing
117+
- content: "Something I've been working on for 2 years is finally ready. Can't wait to share it with you all soon."
118+
expected_intent: hype
119+
note: "boundary - vague teaser with no substance. Manufactured anticipation without any information = hype."
120+
121+
# ─── engagement_bait ─────────────────────────────────────────────────────────
122+
123+
- content: "Like if you agree. Retweet if you strongly agree."
124+
expected_intent: engagement_bait
125+
note: "clear - textbook metric farming"
126+
127+
- content: "Name a movie that defined your childhood. I'll go first: Home Alone. Your turn 👇"
128+
expected_intent: engagement_bait
129+
note: "clear - reply bait with no substance"
130+
131+
- content: "Comment your birth month and I'll tell you what your personality type is 🔮"
132+
expected_intent: engagement_bait
133+
note: "clear - comment farming disguised as fun"
134+
135+
- content: "Unpopular opinion incoming. I know this will divide people but I'm saying it anyway: [blank]"
136+
expected_intent: engagement_bait
137+
note: "clear - reaction farming setup with no actual opinion yet"
138+
139+
- content: "Marvel fans vs DC fans. Comment which side you're on. No switching allowed."
140+
expected_intent: engagement_bait
141+
note: "clear - manufactured tribal conflict for comment volume"
142+
143+
# boundary: divisive framing but the goal is comment volume
144+
- content: "Which generation had the best music? Boomers, Gen X, Millennials, or Gen Z? Drop your answer 👇"
145+
expected_intent: engagement_bait
146+
note: "boundary engagement_bait/divisive - generational framing but 'drop your answer 👇' reveals the goal is replies, not division"
147+
148+
# boundary: genuine question vs engagement bait
149+
- content: "Genuine question: what's the best way to handle burnout when you can't take time off? Have tried most standard advice."
150+
expected_intent: genuine
151+
note: "boundary - 'genuine question' signals authentic seeking. Specific constraint ('can't take time off') shows real situation, not bait."
152+
153+
# boundary: community engagement that isn't bait
154+
- content: "We're considering adding dark mode to the app. What would you actually use it for? Helps us prioritise."
155+
expected_intent: genuine
156+
note: "boundary - asking for input with a stated purpose ('helps us prioritise'). Informational intent makes it genuine, not engagement bait."
157+
158+
# ─── divisive ────────────────────────────────────────────────────────────────
159+
160+
- content: "Millennials ruined the housing market. It's really that simple."
161+
expected_intent: divisive
162+
note: "clear - generational group blame"
163+
164+
- content: "Real men don't ask for help. That's just the truth and people can't handle it."
165+
expected_intent: divisive
166+
note: "clear - identity tribal framing ('real men')"
167+
168+
- content: "Urban vs rural. Two completely different worlds that genuinely can't understand each other."
169+
expected_intent: divisive
170+
note: "clear - cultural binary framing"
171+
172+
- content: "If you're still using that platform after everything that's happened, that says everything about your values."
173+
expected_intent: divisive
174+
note: "clear - moral sorting by product/platform choice"
175+
176+
- content: "You can always tell the type of person someone is by how they treat service workers."
177+
expected_intent: divisive
178+
note: "clear - behavioural moral sorting"
179+
180+
# boundary: divisive vs engagement_bait (sorting vs farming)
181+
- content: "People who recline their airplane seat are inconsiderate. Change my mind."
182+
expected_intent: divisive
183+
note: "boundary - 'change my mind' sounds like engagement bait but the content is moral sorting. The judgment of a group is the primary frame."
184+
185+
# boundary: divisive vs ragebait (picking a side vs making you angry)
186+
- content: "The left and right have completely different visions for what this country should be. That divide is real and it isn't going away."
187+
expected_intent: divisive
188+
note: "boundary - observational framing about division without the anger/contempt of ragebait. Stating the divide exists vs weaponising it."
189+
190+
# boundary: strong opinion that isn't divisive
191+
- content: "I think remote work is genuinely better for most knowledge workers. Commutes are a massive waste of human time."
192+
expected_intent: genuine
193+
note: "boundary - strong opinion with a reasoned basis. Not sorting people into tribes - making an argument."
194+
195+
# ─── genuine ─────────────────────────────────────────────────────────────────
196+
197+
- content: "The library will be closed Monday for maintenance. Normal hours resume Tuesday at 9am."
198+
expected_intent: genuine
199+
note: "clear - pure informational announcement"
200+
201+
- content: "Python 3.13 released. Key changes: free-threaded mode, improved REPL, 15% faster interpreter."
202+
expected_intent: genuine
203+
note: "clear - factual technical update"
204+
205+
- content: "Lost my job today. Not sure what comes next but trying to stay calm and figure it out."
206+
expected_intent: genuine
207+
note: "clear - personal situation with no manipulation"
208+
209+
- content: "Tried making sourdough again. Still came out dense. The starter is probably the issue. Will try again next weekend."
210+
expected_intent: genuine
211+
note: "clear - personal update with specific detail and honest self-assessment"
212+
213+
- content: "After 10 years in finance I switched to teaching. Hardest and best decision I've made."
214+
expected_intent: genuine
215+
note: "clear - personal story with specifics"
216+
217+
# boundary: genuine that touches a divisive topic
218+
- content: "I've voted for both parties in different elections. Neither platform fits what I actually believe anymore."
219+
expected_intent: genuine
220+
note: "boundary - political but authentic personal reflection. Not sorting others into tribes."
221+
222+
# boundary: criticism that isn't ragebait
223+
- content: "The new policy is genuinely poorly designed - it penalises exactly the behaviour it's trying to encourage. Here's why."
224+
expected_intent: genuine
225+
note: "boundary - critical but reasoned. 'Here's why' signals argument-making not outrage-provoking."
226+
227+
# boundary: shares alarming information genuinely
228+
- content: "My friend was scammed last week through a fake job posting. Here's exactly how it worked so you can recognise it."
229+
expected_intent: genuine
230+
note: "boundary - alarming but specific, personal, and actionable. Teaching recognition = genuine."

extension/core/classifier.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ function formatIntent(intent) {
8888
engagement_bait: 'Engagement Bait',
8989
divisive: 'Divisive',
9090
genuine: 'Genuine',
91-
neutral: 'Neutral',
92-
clickbait: 'Clickbait',
93-
reaction_farming: 'Reaction Farming',
9491
};
9592
return labels[intent] || intent;
9693
}

0 commit comments

Comments
 (0)