Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.23.1
title: DeepPragma Classifier
emoji: π‘οΈ
colorFrom: blue
colorTo: gray
sdk: gradio
sdk_version: 4.40.0
app_file: app.py
pinned: false
license: mit
π‘οΈ DeepPragma Classifier
DeepPragma is an NLP system for detecting hate speech in social media text β including the forms that traditional lexical classifiers consistently miss: sarcasm, irony, and coded/dogwhistle references.
Most hate speech detectors rely on keyword matching or sentiment polarity. This works for direct insults, but fails precisely where bad actors adapt: when hate is expressed through ironic false compliments, or through culturally coded euphemisms that appear neutral out of context. DeepPragma addresses both failure modes.
The problem
Standard approaches (lexicon-based sentiment analysis, keyword blocklists, simple syntactic pattern matching) break down on real-world examples like:
- "Oh sure, because people from your country are always SO trustworthy." β positive-sounding words, hateful intent.
- "The Austrian painter" or "those who don't eat pork" β semantically neutral phrases used within specific communities as indirect, deniable references to a targeted group or figure.
Neither case contains an obvious "hate word." Detecting them requires reasoning about pragmatic context, not just surface-level lexical features.
Approach
DeepPragma uses a hybrid pipeline:
- Primary classification via LLM (Groq / Llama 3.3 70B) β the core classifier reasons about tone, contrast between literal and intended meaning, and structural cues typical of coded speech. This is the component actually capable of resolving irony and dogwhistles, since it can model context the way lexical tools cannot.
- Auxiliary lexical/syntactic signals (spaCy + NLTK VADER) β sentiment scores and dependency-parse patterns are computed as supporting signals, not as gatekeepers. They inform but never block the LLM classification.
- Curated knowledge retrieval β a maintained, source-cited knowledge base of documented coded speech patterns is retrieved and passed as context to the classifier when relevant, grounding its reasoning instead of relying purely on the model's guesswork.
Classification labels
| Label | Meaning |
|---|---|
Direct Hate Speech |
Explicit insults or slurs, no irony involved. |
Sarcastic Hate Speech |
Literal wording is neutral/positive, but tone and context reveal a hateful or discriminatory attack. |
Coded/Dogwhistle Hate β Needs Review |
Surface-neutral phrase that may function as an indirect, community-specific reference to a targeted group or figure. Flagged for human review, not treated as a final verdict β false positives here have real costs (e.g. censoring legitimate discussion of religion or history). |
Sarcastic/Ironic (Non-Hateful) |
Irony is present, but there is no hate target. |
Neutral |
No hate, no irony, no coding detected. |
Project structure
.
βββ app.py # Gradio interface
βββ src/
β βββ engine.py # Auxiliary lexical/syntactic signal extraction (spaCy + VADER)
β βββ llm_client.py # Groq API wrapper β primary classifier
β βββ knowledge_retriever.py # Keyword-based retrieval over the curated knowledge base
β βββ knowledge_base.json # Curated, source-cited dogwhistle/coded-speech patterns
βββ requirements.txt
βββ README.md
Setup
- Clone the repository.
- Set the
GROQ_API_KEYenvironment variable (as a Space secret, or in a local.envfile). - Install dependencies:
pip install -r requirements.txt - Run locally:
python app.py
On Hugging Face Spaces, dependencies and model downloads (en_core_web_sm, vader_lexicon) are handled automatically on first startup.
Extending the knowledge base
src/knowledge_base.json is intentionally kept empty of unverified entries by default. Each entry should include:
{
"id": "unique_id",
"surface_pattern": "the neutral-sounding phrase",
"category": "type of coding (e.g. religious/ethnic dogwhistle)",
"note": "what community uses it, and why, in your own words",
"source": "citation β academic paper, ADL Hate Symbols Database, documented observation, etc."
}
Only add entries you have personally verified against a credible source. This file is meant to improve detection accuracy and give the model grounded context β not to serve as a general reference for coded terminology.
Known limitations
- Coded/dogwhistle detection depends entirely on the coverage and quality of the curated knowledge base β it will not catch patterns that haven't been documented yet.
- Dogwhistles evolve quickly and vary by platform and community; the knowledge base requires ongoing maintenance.
- The system is a decision-support tool, not an automated moderation action-taker.
Coded/Dogwhistle Hate β Needs Reviewresults are explicitly designed to route to a human reviewer rather than trigger automatic removal.
Author
Built by jamalinu β computational linguist and NLP engineer, Barcelona.