Rule By Example: Harnessing Logical Rules for Explainable Hate Speech Detection

Christopher Clarke, Matthew Hall, Gaurav Mittal, Ye Yu, Sandra Sajeev, Jason Mars, Mei Chen

Abstract

Rule By Example (RBE) is a framework introduced at ACL 2023 that bridges the gap between interpretable rule-based systems and high-performance deep learning models for hate speech detection. By employing a dual-encoder architecture and contrastive learning, RBE maps logical rules and representative "exemplars" into a shared embedding space with input text. This allows for robust detection that remains grounded in human-authored rules, offering both improved accuracy and verifiable explanations.

Introduction: The Transparency-Performance Trade-off

Current content moderation systems typically rely on either rule-based methods (e.g., regex, keyword lists) or deep learning models. Rule-based systems are transparent but "fragile," failing to handle linguistic nuances or slight variations. Conversely, deep learning models are robust but act as "black boxes," making their decisions difficult to trust or adapt without extensive retraining. RBE seeks to resolve this by treating rules as semantic anchors rather than rigid filters.

Methodology: Dual Encoders and Contrastive Learning

The core of the RBE framework is a dual-encoder architecture trained via contrastive learning to align text with logical rules.

The Rule By Example (RBE) dual-encoder architecture featuring text and rule encoders.
  1. Architecture: The system utilizes two BERT-like encoders. The Text Encoder processes input comments, while the Rule Encoder processes a "Ruleset" containing logical rules paired with textual exemplars.
  2. Contrastive Learning: During training, a contrastive loss function pulls embeddings of hateful comments toward the specific rule-exemplar clusters they should trigger, while pushing them away from non-matching rules.
  3. Rule-Grounding: At inference, the model identifies the most similar rule-exemplar cluster for a flagged comment, providing a clear justification for the prediction.
  4. Unsupervised Refinement: For unlabeled data, RBE uses distance-based strategies to identify and filter out over-generalized or "noisy" rules.

Experimental Evaluation

The authors evaluated RBE across three major benchmarks: HateXplain, which includes human-annotated rationales; Jigsaw, focusing on identity-based hate; and the Contextual Abuse Dataset (CAD), which covers Reddit-based identity abuse.

Key Results and Performance

RBE demonstrates significant improvements over both traditional rules and standard transformer-based classifiers.

Performance comparison of RBE against baseline models across HateXplain, Jigsaw, and CAD datasets.

In supervised settings, RBE outperformed state-of-the-art models like BERT and MPNet by 1.3% to 4.3% in F1-score across all datasets. Crucially, the model achieves these results using as few as one exemplar per rule, making it highly efficient for human moderators to maintain.

Discussion and Insights

  • Semantic Anchoring: By learning representations, RBE distinguishes between slurs used as attacks and those used in non-hateful, descriptive contexts.
  • Explainability: Unlike standard transformers, RBE offers "rule-grounding," allowing moderators to trace predictions back to specific human-authored logic.
  • Robustness: The model can "soften" rigid rules, catching lexically similar content that traditional regex would miss.

Limitations

While RBE reduces the need for massive labeled datasets, it still requires expert supervision to author initial rules and select exemplars. Furthermore, the dual-encoder setup introduces higher computational overhead compared to simple regex filters. Future work may focus on automating exemplar selection to further streamline the moderation workflow.

Summary updated

BibTeX
@inproceedings{clarke2023rule,
  author = {Christopher Clarke and Matthew Hall and Gaurav Mittal and Ye Yu and Sandra Sajeev and Jason Mars and Mei Chen},
  title = {{Rule By Example: Harnessing Logical Rules for Explainable Hate Speech Detection}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.22},
}
Figure