Coverage for narrative_harm_classifier/classifier/counter_narrative.py: 100%
7 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-20 13:25 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-20 13:25 +0000
1"""
2classifier/counter_narrative.py — General counter-narrative guidance per harm mechanism.
4Deliberately general, templated guidance grounded in the public
5"acknowledge -> redirect -> inform" counter-messaging framework (the
6methodology behind projects like Moonshot CVE and the Redirect Method), not
7auto-generated bespoke rebuttal text for the specific input. Generating
8custom rebuttal text is a materially harder, riskier text-generation problem
9(prone to tone-deaf or factually wrong output) and is out of scope here —
10this gives a human moderator/responder a starting frame, not a script to
11paste verbatim.
12"""
14from typing import Optional
16_GUIDANCE: dict[str, str] = {
17 "animalization": (
18 "Dehumanizing comparisons (to animals, vermin, disease) are a documented precursor to "
19 "real-world violence against targeted groups. Effective counter-messaging typically: "
20 "(1) avoids repeating or amplifying the dehumanizing frame itself, (2) affirms the "
21 "target group's humanity with specific, concrete facts rather than abstract appeals, "
22 "(3) redirects toward the underlying grievance being exploited, if any."
23 ),
24 "demonization": (
25 "Framing a group as evil or supernaturally malevolent shuts down empathy and factual "
26 "engagement. Counter-messaging typically works better by naming the rhetorical move "
27 "explicitly (\"this frames an entire group as inherently evil\") and redirecting to "
28 "specific, falsifiable claims rather than arguing the moral framing directly."
29 ),
30 "objectification": (
31 "Reducing a group to objects or property strips away agency and interiority. "
32 "Counter-messaging typically centers first-person voices from the affected group and "
33 "concrete examples of agency, rather than abstract arguments against the framing."
34 ),
35 "criminalization": (
36 "Blanket criminal framing of a group is usually contradicted by the actual data. "
37 "Effective counter-messaging leads with accurate, sourced statistics and specific "
38 "counterexamples rather than general appeals not to stereotype."
39 ),
40 "direct_call_to_violence": (
41 "Explicit calls to violence should typically be escalated for human review and, where "
42 "applicable, reported to platform trust & safety or law enforcement channels rather than "
43 "countered by automated messaging alone. If counter-messaging is used at all, prioritize "
44 "de-escalation and directing at-risk viewers toward support resources over debating the "
45 "claim itself."
46 ),
47 "false_attribution": (
48 "Claims about a group's supposed hidden agenda are typically unfalsifiable by design. "
49 "Counter-messaging tends to work better by asking what specific, checkable evidence is "
50 "being offered (usually none) rather than trying to disprove an unfalsifiable claim "
51 "directly."
52 ),
53}
55_DEFAULT_GUIDANCE = (
56 "Consider whether a direct rebuttal, a redirect to factual information, or escalation to "
57 "human review is the most appropriate response before responding automatically."
58)
61def guidance_for(harm_mechanism: Optional[str]) -> Optional[str]:
62 """Return general counter-narrative guidance for a harm mechanism, or None if harmless."""
63 if not harm_mechanism:
64 return None
65 return _GUIDANCE.get(harm_mechanism, _DEFAULT_GUIDANCE)