Downloads · 30 days
8
11% of all-time downloads
imranraad/toxishield
toxishield is a text classification model from imranraad. Use it when you need a label for a piece of text. It is set up for transformers.
A bert-base-uncased model fine-tuned for binary toxicity classification (TOXIC / NON-TOXIC) of GitHub pull request review comments.
Downloads · 30 days
8
11% of all-time downloads
All-time downloads
75
Public
Parameters
109M
438 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 100%
From the Hugging Face model README
A bert-base-uncased model fine-tuned for binary toxicity classification (TOXIC / NON-TOXIC) of GitHub pull request review comments.
This model classifies a single GitHub pull request comment as toxic or non-toxic. It was fine-tuned from google-bert/bert-base-uncased on 38,761 labelled PR comments (the "38k detection dataset") as part of the ToxiShield project, which studies and filters toxicity in software engineering communication. The model is evaluated with stratified 10-fold cross-validation and also exported to ONNX (INT8-quantized) for lightweight/in-browser inference.
google-bert/bert-base-uncased is released under Apache-2.0; license for the fine-tuned weights has not been set)google-bert/bert-base-uncasedhuggingface.co/imranraad/toxishieldClassifying individual GitHub PR/code-review comments as TOXIC or NON-TOXIC, e.g. via transformers.pipeline("text-classification", ...), to flag potentially toxic comments for human review.
Integration into CI bots, code-review dashboards, or moderation tooling that triages or surfaces potentially toxic PR comments before/alongside human moderators. The ONNX INT8 export is intended for low-latency or in-browser inference in such tooling.
Use as a triage/assistive signal rather than an automated blocking mechanism, particularly given the lower recall on the toxic class. Expect false positives on sarcastic, self-deprecating, or jargon-heavy comments, and route model decisions through human review before any moderation action.
Use the code below to get started with the model.
from transformers import pipeline
classifier = pipeline("text-classification", model="<path-or-hub-id-of-saved-model>")
classifier("this the stupidest code ever")[0]["label"]
38,761 labelled GitHub PR review comments (38k-detection-dataset, dataset handle [ANONYMIZED-ORG]/38k-dataset-labelled, not yet published): 28,641 NON-TOXIC (label 0) and 10,120 TOXIC (label 1). Comment length ranges from 5 to 998 characters (median ~80). Split into an 80% train / 10% test CSV for the single-run fine-tune; the full dataset is additionally used for stratified 10-fold cross-validation.
Comments are tokenized with the bert-base-uncased WordPiece tokenizer with truncation. The single-run fine-tune uses dynamic padding (DataCollatorWithPadding); the 10-fold cross-validation run uses fixed max_length=128 padding.
bert-base-uncased has ~110M parameters. The best checkpoint is additionally exported to ONNX and INT8-quantized for lighter-weight/in-browser inference. [More Information Needed] on wall-clock training time.
Stratified 10-fold cross-validation over the full 38,761-sample dataset (per-fold results in results/kfold-metrics/cross_validation_results.csv); the single-run fine-tune is additionally evaluated on the held-out 10% test split.
No subpopulation disaggregation performed; results are reported per cross-validation fold and averaged.
Accuracy, precision, recall, and F1 (binary, positive class = TOXIC), chosen to capture both overall correctness and toxic-class-specific performance given the class imbalance.
10-fold cross-validation (mean ± std over 10 folds):
| Metric | Mean | Std |
|---|---|---|
| Accuracy | 0.9818 | 0.0023 |
| Precision (toxic) | 0.9753 | 0.0033 |
| Recall (toxic) | 0.9543 | 0.0096 |
| F1 (toxic) | 0.9647 | 0.0047 |
Baseline comparison — GPT-4o, zero-shot prompted, on the held-out test split (comparison/openai-detection-inference/):
| Class | Precision | Recall | F1 |
|---|---|---|---|
| Non-toxic | 0.84 | 0.99 | 0.91 |
| Toxic | 0.96 | 0.49 | 0.65 |
| Accuracy | 0.86 |
The fine-tuned BERT model substantially outperforms zero-shot GPT-4o prompting on this task, most notably on toxic-class recall (0.95 vs. 0.49) — GPT-4o zero-shot misses roughly half of toxic comments, while the fine-tuned model catches the large majority at comparable or better precision.
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
bert-base-uncased (12-layer transformer encoder, 110M parameters) with a linear classification head over 2 labels (NON-TOXIC = 0, TOXIC = 1), fine-tuned with cross-entropy loss for binary sequence classification.
2× NVIDIA RTX 6000 Ada Generation (49 GB each).
Python 3.11, PyTorch 2.5.1 (CUDA 12.1 build), Transformers 4.57.6, Datasets 5.0.0, 🤗 Evaluate, scikit-learn, Optimum/ONNX Runtime (for INT8 export).
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]