DeepPragma / README.md
jamalinu's picture
Update README.md
677f869 verified
|
Raw
History Blame Contribute Delete
5.23 kB

A newer version of the Gradio SDK is available: 6.23.1

Upgrade
metadata
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:

  1. 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.
  2. 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.
  3. 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

  1. Clone the repository.
  2. Set the GROQ_API_KEY environment variable (as a Space secret, or in a local .env file).
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. 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 Review results are explicitly designed to route to a human reviewer rather than trigger automatic removal.

Author

Built by jamalinu β€” computational linguist and NLP engineer, Barcelona.