Awareness-Enhanced Guidance for Iterative Safeguard
AEGIS is an exploratory framework for studying span-guided multilingual text detoxification across English, Mandarin Chinese, and Korean. It separates a span-level detector from frozen generator backbones so that the effect of harmful-span, intensity, and target guidance can be examined without treating the framework as a state-of-the-art claim.
| Resource | Status |
|---|---|
| Paper | arXiv:2607.17713 |
| Code | Detector training and guided-generation pipeline available |
| Data | Use the official upstream datasets described in DATA.md |
| License | MIT for code; upstream terms apply to data and models |
Research code for multilingual span-level hate-speech detection and controlled detoxification across English, Chinese, and Korean. The project connects token classification, guided generation, and evaluator diagnostics while keeping the trade-off between toxicity reduction and meaning preservation explicit.
| Component | Scope |
|---|---|
| Detection | XLM-R token classification with harmful-span BIO labels |
| Generation | Guided and unguided multilingual rewriting pipelines |
| Evaluation | Automatic metrics, sensitivity analyses, and model comparisons |
| Reproducibility | Audited code, configuration guidance, and compact metrics |
The detector is optimized with harmful-token precision, recall, and Non-O
F1 rather than relying on majority-dominated token accuracy.
| Language | Dataset | Non-O F1 | BIO F1 | Intensity F1 | Target F1 (macro) |
|---|---|---|---|---|---|
| Chinese | STATE ToxiCN | 69.89% | 95.42% | 78.69% | 59.75% |
| English | HateXplain | 73.65% | 94.69% | 68.70% | 67.32% |
| Korean | K-HATERS | 67.56% | 97.27% | 66.14% | 68.45% |
These are recorded results from the included experiment configuration, not a claim that the datasets or languages are directly comparable.
Python 3.8 or newer is recommended. CUDA is useful for training and generation.
git clone https://github.com/cosmic4dev/multilingual-hate-detection.git
cd multilingual-hate-detection
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .envProvide gated-model and API credentials through environment variables or the relevant provider CLI. Never place credentials directly in scripts.
Train the detector variants:
python backend/training/chinese_xlmr_train.py --epochs 8 --patience 3
python backend/training/english_xlmr_train.py --epochs 8 --patience 3
python backend/training/korean_xlmr_train.py --epochs 8 --patience 3Generate guided and unguided rewrites from a locally obtained evaluation file:
python human_eval/run_multi_generator.py \
--input_csv /path/to/local/evaluation_input.csv \
--out_dir /path/to/local/outputInspect the available evaluation entry points:
python experiments/auto_evaluate_from_csv.py --help
python experiments/run_multi_model_auto_eval.py --helpbackend/
├── datasets/ Dataset loaders and detector integration
├── training/ Language-specific XLM-R training
└── results/ Compact detector metrics
human_eval/ Generation and evaluation utilities
experiments/ Automatic evaluation and sensitivity analyses
Raw datasets, row-level human evaluations, generated-text pools, model weights,
and manuscript or submission materials are intentionally excluded. See
DATA.md and PUBLIC.md for the release boundary.
Obtain datasets from their official releases and configure local paths in the loaders:
The included code and metrics support inspection and reproduction of the documented pipeline. They do not establish that one guidance policy is universally optimal, that automatic toxicity scores replace human judgment, or that performance transfers unchanged across languages and domains.
See CONTRIBUTING.md. Contributions are especially useful
for portable configuration, dataset adapters, multilingual evaluation, and
audits of toxicity–meaning trade-offs.