File size: 4,652 Bytes
d90fd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
license: apache-2.0
library_name: transformers
pipeline_tag: text-classification
language:
- en
base_model: datalama/mmBERT-small
datasets:
- google/civil_comments
- Heliosoph/Jigsaw-Toxic-Comments
tags:
- toxicity
- content-moderation
- multi-label-classification
- modernbert
- multilingual
metrics:
- roc_auc
- f1
---

# Multilabel Toxic Comment Classifier

This model produces seven independent moderation scores for English comments:
`toxicity`, `severe_toxicity`, `obscene`, `threat`, `insult`,
`identity_attack`, and `sexual_explicit`. It is a fine-tune of
[`datalama/mmBERT-small`](https://huggingface.co/datalama/mmBERT-small), a
multilingual ModernBERT/mmBERT base model.

This is a multi-label classifier, not a mutually exclusive class classifier.
Every output is a sigmoid score and a comment can score highly on multiple
dimensions. `toxicity` is trained as its own target; it is not computed as an
OR of the other labels.

## Intended use

Use the scores as one input to a broader content-moderation workflow. Choose
and validate a separate decision threshold for every label and review decisions
in context. Do not use this model as the sole basis for high-impact decisions
about people.

## Usage

```python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

model_id = "wagesj45/multilabel-toxic-comment-classifier"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id).eval()

inputs = tokenizer(
    "Your text to score goes here.",
    return_tensors="pt",
    truncation=True,
    max_length=256,
)
with torch.no_grad():
    scores = torch.sigmoid(model(**inputs).logits[0]).tolist()

result = {
    model.config.id2label.get(index, model.config.id2label.get(str(index))): score
    for index, score in enumerate(scores)
}
print(result)
```

The model's saved label order is:

1. `toxicity`
2. `severe_toxicity`
3. `obscene`
4. `threat`
5. `insult`
6. `identity_attack`
7. `sexual_explicit`

Scores are model outputs, not calibrated probabilities. Thresholds should be
chosen for the target application and monitored after deployment.

## Training

The model was fine-tuned with `transformers` on
[`google/civil_comments`](https://huggingface.co/datasets/google/civil_comments)
and
[`Heliosoph/Jigsaw-Toxic-Comments`](https://huggingface.co/datasets/Heliosoph/Jigsaw-Toxic-Comments).
Civil Comments supplies all seven continuous annotation-fraction targets.
Jigsaw supplies binary targets for the first six dimensions; its unavailable
`sexual_explicit` label is masked from loss rather than treated as negative.

The combined corpus was shuffled and split deterministically 90/10 with seed
42. Training used three epochs, a learning rate of `2e-5`, batch sizes 16/32,
weight decay `0.01`, and a 256-token input limit. The exported weights are the
best checkpoint, selected by validation macro ROC-AUC at epoch 2.

## Evaluation

Evaluation used the held-out split described above. Metrics threshold soft
annotation targets at 0.5 for F1; ROC-AUC uses the continuous model scores.

| Label | ROC-AUC | F1 at 0.5 |
| --- | ---: | ---: |
| toxicity | 0.9744 | 0.6992 |
| severe_toxicity | 0.9991 | 0.4085 |
| obscene | 0.9936 | 0.7141 |
| threat | 0.9894 | 0.4847 |
| insult | 0.9802 | 0.6959 |
| identity_attack | 0.9873 | 0.3902 |
| sexual_explicit | 0.9967 | 0.5075 |
| **Macro average** | **0.9887** | **0.5571** |

These results are not a measure of performance on arbitrary production
comments or languages outside the evaluation data.

## Limitations and risks

- The training and evaluation comments are English. The multilingual base model
  does not establish validated performance for non-English text.
- Toxicity labels are subjective and noisy, and data may carry historical or
  cultural biases.
- Profanity, reclaimed language, identity terms, quotations, discussions of
  abuse, and strongly worded criticism can cause false positives.
- The model can miss implicit, coded, contextual, or adversarially written
  abuse.
- Use application-specific thresholds, appeals, human review, and monitoring
  for real moderation systems.

## Licensing and provenance

The fine-tuned model artifacts in this repository are released under the
[Apache License 2.0](LICENSE). The listed base model and both listed Hugging
Face training datasets use Apache-2.0 and CC0-1.0 licensing, respectively;
refer to their dataset cards for source attribution and terms. This repository
does not redistribute training rows. Any future hard-negative data must be
documented with its source and license before use in a released model.