Views
No views yet

| Challenge | Year | Goal | Original Data Source | Detoxify Model Name | Top Kaggle Leaderboard Score | Detoxify Score |
|---|---|---|---|---|---|---|
| Toxic Comment Classification Challenge | 2018 | build a multi-headed model that’s capable of detecting different types of of toxicity like threats, obscenity, insults, and identity-based hate. | Wikipedia Comments | original | 0.98856 | 0.98636 |
| Jigsaw Unintended Bias in Toxicity Classification | 2019 | build a model that recognizes toxicity and minimizes this type of unintended bias with respect to mentions of identities. You'll be using a dataset labeled for identity mentions and optimizing a metric designed to measure unintended bias. | Civil Comments | unbiased | 0.94734 | 0.93639 |
| Jigsaw Multilingual Toxic Comment Classification | 2020 | build effective multilingual models | Wikipedia Comments + Civil Comments | multilingual | 0.9536 | 0.91655* |
multilingual model has been trained on 7 different languages so it should only be tested on: english, french, spanish, italian, portuguese, turkish or russian.1# install detoxify
2
3pip install detoxify
41
2from detoxify import Detoxify
3
4# each model takes in either a string or a list of strings
5
6results = Detoxify('original').predict('example text')
7
8results = Detoxify('unbiased').predict(['example text 1','example text 2'])
9
10results = Detoxify('multilingual').predict(['example text','exemple de texte','texto de ejemplo','testo di esempio','texto de exemplo','örnek metin','пример текста'])
11
12# optional to display results nicely (will need to pip install pandas)
13
14import pandas as pd
15
16print(pd.DataFrame(results, index=input_text).round(5))
17toxicsevere_toxicobscenethreatinsultidentity_hatetoxicitysevere_toxicityobscenethreatinsultidentity_attacksexual_explicitmalefemalehomosexual_gay_or_lesbianchristianjewishmuslimblackwhitepsychiatric_or_mental_illnesstoxicity1# clone project
2
3git clone https://github.com/unitaryai/detoxify
4
5# create virtual env
6
7python3 -m venv toxic-env
8source toxic-env/bin/activate
9
10# install project
11
12pip install -e detoxify
13cd detoxify
14
15# for training
16pip install -r requirements.txt
17| Model name | Transformer type | Data from |
|---|---|---|
original | bert-base-uncased | Toxic Comment Classification Challenge |
unbiased | roberta-base | Unintended Bias in Toxicity Classification |
multilingual | xlm-roberta-base | Multilingual Toxic Comment Classification |
1
2# load model via torch.hub
3
4python run_prediction.py --input 'example' --model_name original
5
6# load model from from checkpoint path
7
8python run_prediction.py --input 'example' --from_ckpt_path model_path
9
10# save results to a .csv file
11
12python run_prediction.py --input test_set.txt --model_name original --save_to results.csv
13
14# to see usage
15
16python run_prediction.py --help
17toxic_bertunbiased_toxic_robertamultilingual_toxic_xlm_rmodel = torch.hub.load('unitaryai/detoxify','toxic_bert')1
2from detoxify import Detoxify
3
4results = Detoxify('original').predict('some text')
5
6results = Detoxify('unbiased').predict(['example text 1','example text 2'])
7
8results = Detoxify('multilingual').predict(['example text','exemple de texte','texto de ejemplo','testo di esempio','texto de exemplo','örnek metin','пример текста'])
9
10# to display results nicely
11
12import pandas as pd
13
14print(pd.DataFrame(results,index=input_text).round(5))
151
2# create data directory
3
4mkdir jigsaw_data
5cd jigsaw_data
6
7# download data
8
9kaggle competitions download -c jigsaw-toxic-comment-classification-challenge
10
11kaggle competitions download -c jigsaw-unintended-bias-in-toxicity-classification
12
13kaggle competitions download -c jigsaw-multilingual-toxic-comment-classification
141
2python create_val_set.py
3
4python train.py --config configs/Toxic_comment_classification_BERT.json1
2python train.py --config configs/Unintended_bias_toxic_comment_classification_RoBERTa.json
31
2# stage 1
3
4python train.py --config configs/Multilingual_toxic_comment_classification_XLMR.json
5
6# stage 2
7
8python train.py --config configs/Multilingual_toxic_comment_classification_XLMR_stage2.json
91
2tensorboard --logdir=./saved
31
2python evaluate.py --checkpoint saved/lightning_logs/checkpoints/example_checkpoint.pth --test_csv test.csv
31
2python evaluate.py --checkpoint saved/lightning_logs/checkpoints/example_checkpoint.pth --test_csv test.csv
3
4# to get the final bias metric
5python model_eval/compute_bias_metric.py
61
2python evaluate.py --checkpoint saved/lightning_logs/checkpoints/example_checkpoint.pth --test_csv test.csv
3@misc{Detoxify,
title={Detoxify},
author={Hanu, Laura and {Unitary team}},
howpublished={Github. https://github.com/unitaryai/detoxify},
year={2020}
}