prann-ab commited on
Commit
115e6b1
·
verified ·
1 Parent(s): 42873d4

Toxicity-Lens v1.0

Browse files
.dockerignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ *
2
+ !server.py
3
+ !config.json
4
+ !tokenizer.json
5
+ !tokenizer_config.json
6
+ !onnx/model_int8_block32.onnx
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ figures/perspective_thresholds.png filter=lfs diff=lfs merge=lfs -text
37
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CPU server image: 8-bit ONNX (block-wise; about 0.001 from float32 on average, on any CPU), no PyTorch. Build it from a download of this repository:
2
+ # hf download abacusai/Toxicity-Lens --local-dir toxicity-lens --include "*.json" --include server.py \
3
+ # --include Dockerfile --include .dockerignore --include onnx/model_int8_block32.onnx
4
+ # docker build -t toxicity-lens toxicity-lens && docker run -p 8080:8080 toxicity-lens
5
+ FROM python:3.12-slim
6
+ RUN pip install --no-cache-dir fastapi==0.138.1 uvicorn==0.49.0 onnxruntime==1.31.1 tokenizers==0.22.2 "numpy<3"
7
+ WORKDIR /app
8
+ COPY server.py config.json tokenizer.json tokenizer_config.json ./
9
+ COPY onnx/model_int8_block32.onnx onnx/
10
+ ENV MODEL_DIR=/app BACKEND=onnx MODEL_NAME=toxicity-lens
11
+ EXPOSE 8080
12
+ CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]
LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
NOTICE ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Toxicity-Lens
2
+ Copyright 2026 Abacus.AI
3
+
4
+ This model is a finetune of jhu-clsp/mmBERT-base, trained with the data listed in README.md section 7.
5
+
6
+ Perspective is a trademark of Google LLC. This project is not affiliated with or endorsed by Google or Jigsaw.
7
+
8
+ ------------------------------------------------------------------------
9
+ jhu-clsp/mmBERT-base (Marone et al., 2025): MIT License, as declared on its model card (the repository publishes no copyright line).
10
+ Its tokenizer is Gemma 2's; see the Gemma Terms of Use, https://ai.google.dev/gemma/terms.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ ------------------------------------------------------------------------
31
+ MLMA hate speech dataset (https://github.com/HKUST-KnowComp/MLMA_hate_speech): MIT License
32
+ Copyright (c) 2019 HKUST-KnowComp
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy
35
+ of this software and associated documentation files (the "Software"), to deal
36
+ in the Software without restriction, including without limitation the rights
37
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
+ copies of the Software, and to permit persons to whom the Software is
39
+ furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all
42
+ copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
+ SOFTWARE.
51
+
52
+ ------------------------------------------------------------------------
53
+ This model contains information from FineWeb-2 (https://huggingface.co/datasets/HuggingFaceFW/fineweb-2), which is made available under the ODC Attribution License (https://opendatacommons.org/licenses/by/1-0/), and from HPLT 2.0 (https://huggingface.co/datasets/HPLT/HPLT2.0_cleaned), whose packaging is CC0 1.0.
54
+
55
+ AfriHate (https://huggingface.co/datasets/afrihate/afrihate), Muhammad et al., NAACL 2025: Apache 2.0 on Hugging Face, CC BY on GitHub. The authors ask that models built with it not be used for automated removal.
56
+
57
+ Civil Comments (google/civil_comments) and Horizon-Labs/civil-comments-multilingual: CC0 1.0. Qwen/Qwen3.8-27B-FP8, used to translate and label training data: Apache 2.0.
58
+
59
+ RealToxicityPrompts (https://huggingface.co/datasets/allenai/real-toxicity-prompts), Gehman et al., 2020: Apache 2.0. PolygloToxicityPrompts (https://huggingface.co/datasets/ToxicityPrompts/PolygloToxicityPrompts), Jain et al., 2024: CC BY 4.0 per its card metadata; its card text names the AI2 ImpACT License - Low Risk Artifacts. Both carry scores from the Perspective API (Google LLC).
README.md ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: transformers
4
+ base_model: jhu-clsp/mmBERT-base
5
+ base_model_relation: finetune
6
+ pipeline_tag: text-classification
7
+ language:
8
+ - multilingual
9
+ - en
10
+ - ar
11
+ - am
12
+ - cs
13
+ - de
14
+ - es
15
+ - fr
16
+ - he
17
+ - hi
18
+ - id
19
+ - it
20
+ - ja
21
+ - ko
22
+ - nl
23
+ - pl
24
+ - pt
25
+ - ru
26
+ - sv
27
+ - tt
28
+ - uk
29
+ - zh
30
+ datasets:
31
+ - google/civil_comments
32
+ - Horizon-Labs/civil-comments-multilingual
33
+ - afrihate/afrihate
34
+ - HuggingFaceFW/fineweb-2
35
+ - allenai/real-toxicity-prompts
36
+ - ToxicityPrompts/PolygloToxicityPrompts
37
+ - HPLT/HPLT2.0_cleaned
38
+ metrics:
39
+ - roc_auc
40
+ - f1
41
+ tags:
42
+ - abacusai
43
+ - toxicity
44
+ - content-moderation
45
+ - trust-and-safety
46
+ - perspective-api
47
+ - hate-speech
48
+ - multilingual
49
+ - multi-label-classification
50
+ - onnx
51
+ - transformers.js
52
+ ---
53
+ <div align="center">
54
+ <picture>
55
+ <img src="https://cdn-avatars.huggingface.co/v1/production/uploads/63128dd099791aa61d180c72/dJ6uR23m09M-YEafBpmea.png" width="20%" alt="Toxicity-Lens">
56
+ </picture>
57
+ </div>
58
+ <hr>
59
+ <div align="center" style="line-height:1">
60
+ <a href="https://abacus.ai" target="_blank"><img alt="Homepage" src="https://img.shields.io/badge/Homepage-Abacus.AI-white?color=1783ff&logoColor=white"/></a>
61
+ <a href="https://huggingface.co/abacusai" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Abacus.AI-ffc107?color=ffc107&logoColor=white"/></a>
62
+ </div>
63
+ <div align="center" style="line-height: 1;">
64
+ <a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Apache_2.0-f5de53?&color=f5de53"/></a>
65
+ </div>
66
+
67
+ ## 1. Model Introduction
68
+
69
+ Toxicity-Lens is an open, multilingual toxicity classifier from Abacus.AI. It returns the seven attributes of Google's Perspective API (TOXICITY, SEVERE_TOXICITY, IDENTITY_ATTACK, INSULT, PROFANITY, THREAT, SEXUALLY_EXPLICIT) as calibrated probabilities, and it ships with a server that answers Perspective API requests in the same JSON format, so teams moving off the Perspective API before Google shuts it down on December 31, 2026 can keep their code and change one URL.
70
+
71
+ - **More accurate across languages.** On Horizon-Labs' own published benchmark (their evaluation code, their rows), it ranks toxic comments in 15 languages better than the general-purpose open classifiers from Horizon-Labs and Detoxify: TextDetox ROC AUC 89.0, against 85.4 for Horizon-Labs multilingual-toxicity-base and 67.8 for Detoxify multilingual. It is also more accurate at the usual 0.5 threshold (F1 65.2 vs 43.3).
72
+ - **Fewer false alarms than LLM guards.** It ranks toxic comments better than Qwen3Guard-Gen-8B, a safety LLM 27 times its size (AUC 88.4 vs 84.6), and flags 8.1% of clean comments against 38.8%. At the 0.5 threshold Qwen3Guard catches more of the toxic ones (88% against 59%) because it flags so much more.
73
+ - **Closest to the Perspective API.** Trained in part on the Perspective API's own published scores, it orders texts the way Perspective does more closely than any open model we tested, in English and in 17 languages (section 3). Swapped in at Perspective's 0.8 threshold (the default in Coral's documentation), it flags 95% of what Perspective flags in English text it never trained on, against 18% for Horizon-Labs base, and 85% on multilingual web text. It scores toxic text more decisively than Perspective, so at 0.8 it flags 1.2 times as many English texts and 1.9 times as many multilingual ones; section 6 gives the threshold that keeps your flag volume.
74
+ - **Runs anywhere, stays reproducible.** 22 ms per comment on 4 CPU threads with the 8-bit ONNX export, which agrees with float32 on 99.9% of decisions at 0.5; a CPU Docker image; about 2,200 comments per second on one H100; Apache 2.0, and every score is reproducible by pinning a commit.
75
+
76
+ This card describes the model, its evaluation against the Perspective API's own scores and the open alternatives, how to move from the Perspective API, and the known limitations. Training data are listed in section 7; training rows are not released.
77
+
78
+ ## 2. Model Summary
79
+
80
+ <div align="center">
81
+ <table>
82
+ <tbody>
83
+ <tr><td align="center"><strong>Task</strong></td><td align="center">Seven independent probabilities named after the Perspective API attributes</td></tr>
84
+ <tr><td align="center"><strong>Architecture</strong></td><td align="center">ModernBERT encoder: 22 layers, hidden size 768, 12 attention heads, local attention (128 tokens) with global attention every third layer</td></tr>
85
+ <tr><td align="center"><strong>Parameters</strong></td><td align="center">308M (307,535,623)</td></tr>
86
+ <tr><td align="center"><strong>Languages</strong></td><td align="center">Trained on English, Civil Comments translated into 30+ languages, natively written Arabic, Amharic and Tatar, and web text in 17 languages plus English prompts that carry the Perspective API's own scores; distilled on its teacher's scores for 374,000 natively written Hebrew, Hinglish, Tatar and Ukrainian web segments; evaluated in 21 languages plus Hinglish</td></tr>
87
+ <tr><td align="center"><strong>Input scored</strong></td><td align="center">256-token windows; the bundled server scores longer texts in overlapping windows</td></tr>
88
+ <tr><td align="center"><strong>Calibration</strong></td><td align="center">Per-attribute temperature, folded into the classification head</td></tr>
89
+ <tr><td align="center"><strong>Formats</strong></td><td align="center">safetensors (float32); ONNX float32 (exact), 8-bit (CPU default, near-exact) and dynamic int8 (transformers.js)</td></tr>
90
+ <tr><td align="center"><strong>Speed</strong></td><td align="center">22 ms per comment on 4 CPU threads (8-bit ONNX, Apple M5); about 2,200 comments per second on one H100 (bfloat16)</td></tr>
91
+ <tr><td align="center"><strong>Base model</strong></td><td align="center"><code>jhu-clsp/mmBERT-base</code></td></tr>
92
+ <tr><td align="center"><strong>Adaptation</strong></td><td align="center">Full finetune, distilled from an XLM-R-large teacher (560M) trained on the same data</td></tr>
93
+ <tr><td align="center"><strong>License</strong></td><td align="center">Apache 2.0</td></tr>
94
+ </tbody>
95
+ </table>
96
+ </div>
97
+
98
+ ## 3. Evaluation
99
+
100
+ ### Toxic comments in 15 languages
101
+
102
+ *ROC AUC on TextDetox, averaged over 15 languages, on the rows of Horizon-Labs' published benchmark. The other models show the values published on their model cards; rerunning Horizon-Labs' evaluation code reproduces each of them to within 0.2 points.*
103
+
104
+ <div align="center">
105
+ <img src="figures/hero_textdetox.png" width="100%" alt="TextDetox ROC AUC over 15 languages: Toxicity-Lens vs Horizon-Labs and Detoxify">
106
+ </div>
107
+
108
+ ### Against open toxicity classifiers
109
+
110
+ *Horizon-Labs' published toxicity benchmark: their evaluation code and row sampling (a 20,000-comment sample of the Civil Comments test split; TextDetox with up to 500 toxic and 500 non-toxic comments per language). Higher is better; x100.*
111
+
112
+ <div style="max-width:1100px;margin:0 auto">
113
+ <table style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px">
114
+ <thead><tr><th style="padding:10px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:30%"></th><th style="padding:10px 4px;text-align:center;font-weight:600;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;background:rgba(42,120,214,0.10);">Toxicity-Lens<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon base<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon small<div style="font-size:10px;font-weight:400;color:#6B6B6B">141M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify multilingual<div style="font-size:10px;font-weight:400;color:#6B6B6B">278M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify unbiased<div style="font-size:10px;font-weight:400;color:#6B6B6B">125M</div></th></tr></thead>
115
+ <tbody>
116
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Civil Comments: mean ROC AUC over 6 attributes</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>98.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">98.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">98.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">96.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">98.5</td></tr>
117
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Civil Comments: TOXICITY ROC AUC</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>97.5</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.35)">97.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">97.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">96.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.29)">96.9</td></tr>
118
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">TextDetox: ROC AUC, 15 languages</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>89.0</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.42)">85.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.39)">83.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.18)">67.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">58.8</td></tr>
119
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">TextDetox: F1 at the 0.5 threshold, 15 languages</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>65.2</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.31)">43.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.39)">54.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.25)">35.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">8.6</td></tr>
120
+ </tbody></table>
121
+ <div style="font-size:11.5px;color:#6B6B6B;margin-top:6px">Bold = best in the row; shading is relative within each row. Toxicity-Lens: our runs of Horizon-Labs' code. Other models: the values on the Horizon-Labs model cards (<a href="https://huggingface.co/Horizon-Labs/multilingual-toxicity-base">base</a>, <a href="https://huggingface.co/Horizon-Labs/multilingual-toxicity-small">small</a>), which our rerun reproduces to within 0.002. TextDetox's own classifiers are left out because they were trained on TextDetox (they score 98.7 and 96.0 on it, and 89.5 and 84.5 on Civil Comments). At 0.5 on all 71,374 TextDetox rows, Toxicity-Lens flags 58.2% of toxic comments and 7.2% of clean ones (Horizon base: 33.2% and 2.3%).</div>
122
+ </div>
123
+
124
+ ### Against LLM safety guards
125
+
126
+ *Horizon-Labs' guard benchmark: TextDetox in 14 languages, 200 toxic and 200 non-toxic comments each (5,600 texts), pooled; a text is flagged when its score is above 0.5. Qwen3Guard is scored by the probability of an Unsafe or Controversial verdict.*
127
+
128
+ <div style="max-width:1100px;margin:0 auto">
129
+ <table style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px">
130
+ <thead><tr><th style="padding:10px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:30%"></th><th style="padding:10px 4px;text-align:center;font-weight:600;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;background:rgba(42,120,214,0.10);">Toxicity-Lens<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Qwen3Guard-Gen-8B<div style="font-size:10px;font-weight:400;color:#6B6B6B">8.2B</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Qwen3Guard-Gen-0.6B<div style="font-size:10px;font-weight:400;color:#6B6B6B">0.6B</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon guard-base<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Vela Shield<div style="font-size:10px;font-weight:400;color:#6B6B6B">307M</div></th></tr></thead>
131
+ <tbody>
132
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">ROC AUC</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>88.4</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.33)">84.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">76.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.30)">83.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.18)">80.4</td></tr>
133
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">F1 at 0.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.19)">70.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>77.5</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.26)">72.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">66.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.26)">72.0</td></tr>
134
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Clean comments flagged, % (lower is better)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>8.1</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.13)">38.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">46.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.43)">11.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td></tr>
135
+ </tbody></table>
136
+ <div style="font-size:11.5px;color:#6B6B6B;margin-top:6px">Our runs of Horizon-Labs' guard code for every model except Vela Shield, whose numbers come from the <a href="https://huggingface.co/Horizon-Labs/content-safety-guard-base">Horizon-Labs guard card</a>; our runs reproduce the AUCs that card publishes for Qwen3Guard and Horizon's guard. LLM guards are built to judge chatbot prompts and responses, so toxic comments are outside their intended use; the table answers the question "why not just use an LLM guard?". On a half-toxic set, flagging everything already scores F1 66.7, which is why ROC AUC and the clean-comment flag rate are the fairer measures.</div>
137
+ </div>
138
+
139
+ ### Agreement with the Perspective API
140
+
141
+ *RealToxicityPrompts, held-out quarter: 49,810 English prompts and continuations with Perspective's own TOXICITY scores (2020) that Toxicity-Lens never trained on. Each model replaces Perspective at the same threshold t; the line shows, of the texts Perspective scores at t or above, the share the model also scores at t or above. Toxicity-Lens keeps 88 to 95% at every threshold, while also flagging 3.4 to 4.8% of the texts Perspective scores below t (Horizon-Labs base: at most 0.6%).*
142
+
143
+ <div align="center">
144
+ <img src="figures/perspective_thresholds.png" width="100%" alt="Share of the Perspective API's flags kept at the same threshold, English">
145
+ </div>
146
+
147
+ <div style="max-width:1100px;margin:0 auto">
148
+ <table style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px">
149
+ <thead><tr><th style="padding:10px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:30%"></th><th style="padding:10px 4px;text-align:center;font-weight:600;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;background:rgba(42,120,214,0.10);">Toxicity-Lens<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon base<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon small<div style="font-size:10px;font-weight:400;color:#6B6B6B">141M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify multilingual<div style="font-size:10px;font-weight:400;color:#6B6B6B">278M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify unbiased<div style="font-size:10px;font-weight:400;color:#6B6B6B">125M</div></th></tr></thead>
150
+ <tbody>
151
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Rank agreement with Perspective's scores (Spearman)</td></tr>
152
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English, RealToxicityPrompts (held-out): TOXICITY</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>93.3</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.26)">87.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.23)">86.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">81.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.15)">84.7</td></tr>
153
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English, RealToxicityPrompts (held-out): mean of the 7 attributes</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>85.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.22)">76.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.19)">75.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">69.5</td></tr>
154
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages, PolygloToxicityPrompts: TOXICITY, mean over languages</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>95.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.40)">85.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">83.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.21)">62.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">40.4</td></tr>
155
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages: one ranking over all 85,000 texts</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>94.1</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.40)">81.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">79.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.26)">59.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">23.9</td></tr>
156
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Swapped in at the same threshold: Perspective's flags kept</td></tr>
157
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English at 0.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>94.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">17.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td></tr>
158
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages at 0.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>86.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.33)">62.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.33)">62.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.21)">42.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">15.9</td></tr>
159
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages at 0.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>85.0</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.06)">14.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.07)">15.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.17)">33.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">12.4</td></tr>
160
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Swapped in at the same threshold: extra flags (lower is better)</td></tr>
161
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English at 0.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.05)">3.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>0.0</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;color:#9aa0a6">n/a</td></tr>
162
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages at 0.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.43)">2.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.28)">3.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.11)">4.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">5.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>2.3</strong></td></tr>
163
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages at 0.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.07)">12.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>2.4</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>2.4</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">12.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">4.7</td></tr>
164
+ </tbody></table>
165
+ <div style="font-size:11.5px;color:#6B6B6B;margin-top:6px">x100. Our runs on identical rows for every model. Perspective's scores come from the published datasets: <a href="https://huggingface.co/datasets/allenai/real-toxicity-prompts">RealToxicityPrompts</a> (scored by Perspective in 2020) and <a href="https://huggingface.co/datasets/ToxicityPrompts/PolygloToxicityPrompts">PolygloToxicityPrompts</a> (ptp-small, 5,000 web texts per language, scored in 2024). Toxicity-Lens trained on three quarters of the RealToxicityPrompts prompts and on PolygloToxicityPrompts texts outside ptp-small, with Perspective's scores: RealToxicityPrompts rows here are the held-out quarter (Horizon small and Detoxify: the full set, which they never trained on; where we have per-row runs the two agree to within 0.001), and every ptp-small text was removed from training. Extra flags = share of the texts Perspective scored below the threshold that the model flags. Detoxify multilingual has a TOXICITY output only; n/a = no such output, or no per-row run on that set.</div>
166
+ </div>
167
+
168
+ ### Natively written comments the released model never trained on
169
+
170
+ *ROC AUC x100 on each dataset's main label, on datasets written natively in each language (not translated) that the released model did not train on. Earlier experimental versions trained on GAHD, COLD, HED-COLD, SWSR and LLM-jp and were rejected partly on these sets, so they informed data choices.*
171
+
172
+ <div style="max-width:1100px;margin:0 auto">
173
+ <table style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px">
174
+ <thead><tr><th style="padding:10px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:30%"></th><th style="padding:10px 4px;text-align:center;font-weight:600;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;background:rgba(42,120,214,0.10);">Toxicity-Lens<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon base<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon small<div style="font-size:10px;font-weight:400;color:#6B6B6B">141M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify multilingual<div style="font-size:10px;font-weight:400;color:#6B6B6B">278M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify unbiased<div style="font-size:10px;font-weight:400;color:#6B6B6B">125M</div></th></tr></thead>
175
+ <tbody>
176
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Not in the released model's training data</td></tr>
177
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">GAHD (German, identity attacks)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>81.2</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.42)">78.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">77.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.15)">62.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">56.6</td></tr>
178
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">COLD (Chinese, offensive language)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>81.7</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.46)">80.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.44)">79.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">50.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">50.7</td></tr>
179
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">HED-COLD (Chinese)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>80.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)">80.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">79.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">49.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.06)">49.5</td></tr>
180
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">SWSR (Chinese, sexism)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>81.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">80.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.44)">79.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">51.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.14)">57.7</td></tr>
181
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">LLM-jp toxicity (Japanese)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>91.3</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">85.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.35)">80.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.16)">62.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">52.9</td></tr>
182
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">TextDetox Tatar, 4,000 rows never trained on (a release gate)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>86.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">81.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.39)">79.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.20)">61.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">47.2</td></tr>
183
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Test splits of datasets used in training</td></tr>
184
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">AfriHate (Amharic, Algerian and Moroccan Arabic)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>88.8</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.27)">73.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.18)">67.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">57.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.12)">62.9</td></tr>
185
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">MLMA (Arabic)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>78.3</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.28)">64.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.29)">64.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">46.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.10)">50.7</td></tr>
186
+ <tr><td colspan="6" style="padding:7px 10px;font-weight:600;color:#2a78d6;background:rgba(42,120,214,0.08);border-bottom:1px solid rgba(42,120,214,0.2)">Identity-group bias</td></tr>
187
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">CivilComments-WILDS: Jigsaw bias score (higher = less biased)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.39)">93.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.27)">92.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.31)">92.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">91.2</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.47)"><strong>93.9</strong></td></tr>
188
+ </tbody></table>
189
+ <div style="font-size:11.5px;color:#6B6B6B;margin-top:6px">Our runs on identical rows; Detoxify multilingual's TOXICITY output is used for every set. Single-purpose models score higher on single sets: Horizon-Labs' hate-speech model on GAHD (86.3) and SWSR (83.0), and its content-safety guard on LLM-jp (95.4). Sources: GAHD (Goldzycher et al., 2024), COLD (Deng et al., 2022), HED-COLD, SWSR (Jiang et al., 2022), LLM-jp toxicity dataset v2, TextDetox, AfriHate (Muhammad et al., 2025), MLMA (Ousidhoum et al., 2019), CivilComments-WILDS (Koh et al., 2021).</div>
190
+ </div>
191
+
192
+ ### TextDetox, per language
193
+
194
+ *ROC AUC x100 on Horizon-Labs' published TextDetox rows. Toxicity-Lens leads Horizon-Labs base in 15 of 15 languages.*
195
+
196
+ <div style="max-width:1100px;margin:0 auto">
197
+ <table style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px">
198
+ <thead><tr><th style="padding:10px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:28%"></th><th style="padding:10px 4px;text-align:center;font-weight:600;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;background:rgba(42,120,214,0.10);">Toxicity-Lens<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon base<div style="font-size:10px;font-weight:400;color:#6B6B6B">308M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Horizon small<div style="font-size:10px;font-weight:400;color:#6B6B6B">141M</div></th><th style="padding:10px 4px;text-align:center;font-weight:500;border-bottom:2px solid #2a78d6;color:#2a78d6;font-size:13px;">Detoxify multilingual<div style="font-size:10px;font-weight:400;color:#6B6B6B">278M</div></th></tr></thead>
199
+ <tbody>
200
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Amharic</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>84.4</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.29)">71.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.17)">63.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">54.8</td></tr>
201
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Arabic</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>81.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.44)">78.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.37)">72.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">41.4</td></tr>
202
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">German</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>87.0</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">85.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">85.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">66.2</td></tr>
203
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>99.6</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.26)">99.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">99.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.19)">99.2</td></tr>
204
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Spanish</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>92.2</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">90.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">89.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">81.9</td></tr>
205
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">French</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>99.5</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.23)">98.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.14)">98.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">98.1</td></tr>
206
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Hebrew</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>84.0</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">78.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.39)">77.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">50.3</td></tr>
207
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Hindi</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>92.4</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.45)">91.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.43)">89.7</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">64.5</td></tr>
208
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Hinglish (romanised Hindi)</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>78.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">76.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.36)">74.9</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">63.0</td></tr>
209
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Italian</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>88.1</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.43)">87.5</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.20)">84.0</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">81.8</td></tr>
210
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Japanese</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>89.7</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.42)">84.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.40)">83.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">50.6</td></tr>
211
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Russian</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>99.7</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.42)">97.3</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.38)">95.6</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">80.7</td></tr>
212
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Tatar</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>85.2</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.41)">81.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.39)">80.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">62.6</td></tr>
213
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Ukrainian</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>91.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.27)">80.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.27)">80.8</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">68.1</td></tr>
214
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">Chinese</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;font-weight:600;background:rgba(42,120,214,0.47)"><strong>79.9</strong></td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.43)">77.4</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.42)">77.1</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2;background:rgba(42,120,214,0.05)">54.7</td></tr>
215
+ </tbody></table>
216
+ <div style="font-size:11.5px;color:#6B6B6B;margin-top:6px">Horizon-Labs: per-language values published on their cards. Detoxify multilingual: our rerun of Horizon-Labs' code.</div>
217
+ </div>
218
+
219
+ <details>
220
+ <summary><b>Notes on the evaluation</b></summary>
221
+
222
+ Training texts that also appear in an evaluation set were removed: exact matches after normalising case and whitespace, plus near-duplicates for the natively written training sets. Two evaluation sources also supplied training text with the Perspective API's scores: RealToxicityPrompts, where the model trained on three quarters of the prompts (with their continuations) and every number here uses the remaining quarter, split by a hash of the prompt index; and PolygloToxicityPrompts, where it trained on ptp-full texts and every ptp-small (evaluation) text was removed. The TextDetox Tatar row uses 4,000 Tatar rows that were never trained on and were kept out of the Tatar label check; they served as a release gate.
223
+
224
+ Horizon-Labs publish their evaluation code with their models. We copied their toxicity evaluation with two label aliases added so it reads our attribute names, and reduced their guard evaluation to its TextDetox benchmark; our reruns reproduce every headline number we cite from their cards (mean ROC AUC and F1 per model, guard ROC AUC and F1) to within 0.002, so the published values and ours compare directly. On all 71,374 TextDetox rows instead of Horizon-Labs' sample the order is the same: Toxicity-Lens 89.9, Horizon base 86.1, Horizon small 84.5, Detoxify multilingual 68.8, Detoxify unbiased 58.4.
225
+
226
+ PolygloToxicityPrompts mixes languages inside some splits (its Polish split holds 952 Japanese pages), so read single languages with care. RealToxicityPrompts carries Perspective's 2020 scores and PolygloToxicityPrompts its 2024 scores; Perspective changed its models in between. Detoxify multilingual and unbiased are the Hugging Face checkpoints unitary/multilingual-toxic-xlm-roberta and unitary/unbiased-toxic-roberta (Unitary notes they currently give different results from the detoxify library); Detoxify multilingual was trained on seven languages and Detoxify unbiased on English only, so most rows here are outside their training languages.
227
+
228
+ </details>
229
+
230
+ ## 4. Training Approach
231
+
232
+ **What the scores mean.** Each output is the probability that a typical rater would apply the label, following the Perspective API's attribute definitions and the Civil Comments annotation guidelines:
233
+
234
+ - TOXICITY: rude, disrespectful or unreasonable language likely to make someone leave a discussion.
235
+ - SEVERE_TOXICITY: very hateful, aggressive or disrespectful language; much less sensitive to mild profanity than TOXICITY.
236
+ - IDENTITY_ATTACK: negative or hateful language aimed at someone because of an identity such as religion, ethnicity, nationality, gender, sexual orientation or disability.
237
+ - INSULT: insulting, inflammatory or demeaning language towards a person or group.
238
+ - PROFANITY: swear words, curse words and other obscene language.
239
+ - THREAT: an intention to inflict pain, injury or violence on a person or group.
240
+ - SEXUALLY_EXPLICIT: references to sexual acts, sexual body parts or other lewd content.
241
+
242
+ **Method.** Seven sigmoid outputs trained with binary cross-entropy on the fraction of human raters who chose each label, so a comment half the raters found toxic targets 0.5. Attributes a dataset does not label are left out of the loss rather than set to 0. Non-toxic comments that mention an identity group count double, to reduce false flags on identity mentions. Two epochs, maximum length 256 tokens, learning rate 5e-5, batch 64. Each target is the mean of the label and a teacher's score (an XLM-R-large model with 560M parameters, trained on the same data, the Perspective-scored texts below also counted twice); on 374,000 unlabelled native web segments in Hebrew, Hinglish, Tatar and Ukrainian (FineWeb-2, HPLT 2.0) the teacher's scores alone are the targets.
243
+
244
+ **The Perspective API's own scores.** About 530,000 training texts carry the Perspective API's published scores instead of rater fractions: web text in 17 languages from PolygloToxicityPrompts (ptp-full without the evaluation texts; scored in 2024) and three quarters of the RealToxicityPrompts prompts with their continuations (scored in 2020). They count twice in the loss. On German and Portuguese pages the target is the mean of Perspective's score and an earlier version's, because Perspective gives many harmless pages there 0.5 to 0.75 (section 5); PolygloToxicityPrompts has no SEXUALLY_EXPLICIT score, so that target comes from the earlier version too.
245
+
246
+ **Calibration.** One temperature per attribute, fitted on held-out Civil Comments rater fractions (TOXICITY T = 0.885) and folded into the final layer, so the published weights need no post-processing.
247
+
248
+ **Versions.** Scores change only when you change the model. Pin a commit of this repository (`revision=` in transformers, `MODEL_REVISION` for the server) and every score stays reproducible; later releases will go out as new commits with their evaluation in this card.
249
+
250
+ ## 5. Known Behaviors and Limitations
251
+
252
+ - **High thresholds flag more texts than Perspective.** This model scores toxic text more decisively than Perspective does: at 0.9 it flags 1.8 times as many held-out English texts as Perspective and 2.9 times as many multilingual web texts, whose 2024 Perspective scores rarely exceed 0.9. If you act automatically at 0.8 or 0.9, start from the volume-matched threshold in section 6, or measure it on your own traffic with `compare_with_perspective.py`.
253
+ - **German and Portuguese web pages: Perspective is only partly reproduced, on purpose.** Perspective gives many harmless German and Portuguese web pages 0.5 to 0.75 in PolygloToxicityPrompts (a health-forum question about a pill, a parenting forum, a paintbrush product page). Training on those scores alone copied the habit, so for these two languages the training target blends Perspective's score with an earlier version's. This model flags 47.5% (German) and 50.0% (Portuguese) of Perspective's flags there; in blind reads of the German and Portuguese pages that it flags and the earlier version does not, 37 to 57 of every 100 were harmless pages that Perspective also flags. If a false flag on a German or Portuguese web page costs you more than a missed one, use a higher threshold for them.
254
+ - **Long texts.** The model reads 256 tokens at a time. The bundled server scores longer texts in overlapping windows and reports the highest window score per attribute; the transformers pipeline with `truncation=True` scores only the first 256 tokens.
255
+ - **Only the seven production attributes.** Perspective's experimental attributes (such as FLIRTATION) and its bridging attributes (such as REASONING or CURIOSITY) are not provided, and there is no language detection.
256
+ - **Automated removal.** The AfriHate authors ask that models built with their data not be used for automated removal. We pass that request on: use the scores to prioritise human review, not to remove content without a person in the loop.
257
+ - Like every toxicity model, it can over-flag identity mentions and reclaimed or quoted language and miss sarcasm or implicit abuse; labels are subjective and culture-dependent. Do not use it as the only basis for decisions about people.
258
+
259
+ ## 6. Deployment
260
+
261
+ ### Quickstart
262
+
263
+ Try it in the browser first: the [demo Space](https://huggingface.co/spaces/abacusai/Toxicity-Lens) scores text in any language, answers requests in the Perspective API's format and works as an MCP tool for agents.
264
+
265
+ ```python
266
+ from transformers import pipeline
267
+
268
+ clf = pipeline("text-classification", model="abacusai/Toxicity-Lens", top_k=None)
269
+ print(clf("You are a complete idiot and nobody wants you here.", truncation=True))
270
+ # [[{'label': 'TOXICITY', 'score': 0.95}, {'label': 'INSULT', 'score': 0.95}, ...]]
271
+ ```
272
+
273
+ The config marks the task as multi-label, so the pipeline applies a sigmoid per attribute; `truncation=True` scores the first 256 tokens. Tested with transformers 4.57 and 5.14.
274
+
275
+ ### Moving off the Perspective API
276
+
277
+ **1. Run the server.** `server.py` in this repository answers the Perspective API's requests. On a GPU or CPU with PyTorch:
278
+
279
+ ```bash
280
+ pip install fastapi uvicorn tokenizers huggingface_hub transformers torch
281
+ hf download abacusai/Toxicity-Lens server.py --local-dir .
282
+ MODEL_DIR=abacusai/Toxicity-Lens uvicorn server:app --host 0.0.0.0 --port 8080
283
+ ```
284
+
285
+ Or on any CPU, without PyTorch, with the 8-bit ONNX export in Docker:
286
+
287
+ ```bash
288
+ hf download abacusai/Toxicity-Lens --local-dir toxicity-lens \
289
+ --include "*.json" --include server.py --include Dockerfile --include .dockerignore --include onnx/model_int8_block32.onnx
290
+ docker build -t toxicity-lens toxicity-lens && docker run -p 8080:8080 toxicity-lens
291
+ ```
292
+
293
+ **2. Point your client at it.** The request and response JSON are the same as the Perspective API's, so only the address changes.
294
+
295
+ ```bash
296
+ # was: https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key=YOUR_KEY
297
+ curl -s localhost:8080/v1alpha1/comments:analyze -H 'Content-Type: application/json' \
298
+ -d '{"comment": {"text": "You are an idiot"}, "requestedAttributes": {"TOXICITY": {}, "INSULT": {}}}'
299
+ ```
300
+
301
+ Code that uses Google's client library, as in the Perspective API documentation, changes only the discovery URL:
302
+
303
+ ```python
304
+ from googleapiclient import discovery
305
+
306
+ client = discovery.build(
307
+ "commentanalyzer", "v1alpha1", developerKey="unused",
308
+ # was https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1
309
+ discoveryServiceUrl="http://localhost:8080/$discovery/rest?version=v1alpha1",
310
+ static_discovery=False)
311
+ body = {"comment": {"text": "You are an idiot"}, "requestedAttributes": {"TOXICITY": {}}}
312
+ resp = client.comments().analyze(body=body).execute()
313
+ print(resp["attributeScores"]["TOXICITY"]["summaryScore"]["value"])
314
+ ```
315
+
316
+ Coral: in its Perspective settings, set the endpoint to `http://<your-host>:8080/v1alpha1` (the default is `https://commentanalyzer.googleapis.com/v1alpha1`). Coral's `doNotStore` and feedback (`comments:suggestscore`) calls are accepted.
317
+
318
+ **3. Check your thresholds.** Toxicity-Lens uses Perspective's 0-to-1 scale, and most of Perspective's flags carry over at the same threshold. Because it scores toxic text more decisively, it flags more texts than Perspective at high thresholds, most on multilingual web text; the rows "threshold that flags as many" give the threshold that keeps your flag volume. Swapped in at your threshold on Perspective's own scores (English: the held-out quarter of RealToxicityPrompts):
319
+
320
+ <div style="max-width:900px;margin:0 auto">
321
+ <table style="width:100%;border-collapse:collapse;font-size:13px">
322
+ <thead><tr><th style="padding:8px 6px;text-align:left;border-bottom:2px solid #2a78d6;width:52%">Your Perspective threshold</th><th style="padding:8px 4px;text-align:center;border-bottom:2px solid #2a78d6;color:#2a78d6;font-weight:600">0.5</th><th style="padding:8px 4px;text-align:center;border-bottom:2px solid #2a78d6;color:#2a78d6;font-weight:600">0.7</th><th style="padding:8px 4px;text-align:center;border-bottom:2px solid #2a78d6;color:#2a78d6;font-weight:600">0.8</th><th style="padding:8px 4px;text-align:center;border-bottom:2px solid #2a78d6;color:#2a78d6;font-weight:600">0.9</th></tr></thead><tbody>
323
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English (RealToxicityPrompts): Perspective's flags kept</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">88%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">92%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">95%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">94%</td></tr>
324
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English: extra flags</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">3.7%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">3.4%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">3.8%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">4.8%</td></tr>
325
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">English: threshold that flags as many comments as Perspective</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.48</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.74</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.86</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.94</td></tr>
326
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages (PolygloToxicityPrompts): Perspective's flags kept</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">87%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">91%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">85%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">80%</td></tr>
327
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages: extra flags</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">2.6%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">7.9%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">12.4%</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">2.8%</td></tr>
328
+ <tr><td style="padding:8px 6px;padding-left:16px;border-bottom:1px solid rgba(128,128,128,0.15);font-size:14px;font-weight:600">17 languages: threshold that flags as many texts as Perspective</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.40</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.74</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.85</td><td style="padding:8px 6px;text-align:center;border-bottom:1px solid rgba(128,128,128,0.15);vertical-align:middle;font-size:14px;line-height:1.2">0.93</td></tr>
329
+ </tbody></table>
330
+ </div>
331
+
332
+ To get these numbers for your own traffic, run `compare_with_perspective.py` (in this repository) on comments you already scored with Perspective: it prints, per attribute, the rank agreement, the flags kept and added at your threshold, and the threshold that keeps your flag volume.
333
+
334
+ ```bash
335
+ python compare_with_perspective.py logged_scores.csv --threshold 0.8 # columns: text, TOXICITY, INSULT, ...
336
+ ```
337
+
338
+ **4. What stays the same, and what differs.**
339
+
340
+ - Same: `POST /v1alpha1/comments:analyze` with `comment.text`, `requestedAttributes` (with `scoreThreshold`), `spanAnnotations` (per-sentence `spanScores`), `languages`, `clientToken` and `doNotStore`; the seven attribute names; scores as `{"value": p, "type": "PROBABILITY"}`; the 20,480-byte limit; Google-style error bodies; `comments:suggestscore` (accepted, and stored only if you set `FEEDBACK_FILE`); and the discovery document that Google's client libraries read.
341
+ - Different: other attributes (experimental, bridging) return an error; there is no language detection, so any language is accepted and `languages` echoes your request; there are no quotas or rate limits; API keys are optional (`API_KEYS=key1,key2`); scores are close to Perspective's but not identical (section 3); and your text never leaves your servers.
342
+
343
+ ### More ways to run it
344
+
345
+ - **OpenAI-style moderation.** `POST /v1/moderations` with `{"input": ["..."]}` returns OpenAI's moderation shape, filling the categories these attributes support honestly (harassment, harassment/threatening, hate, sexual, violence, plus toxicity), for gateways that expect it.
346
+ - **LiteLLM guardrail.** The server implements LiteLLM's Generic Guardrail API:
347
+
348
+ ```yaml
349
+ litellm_settings:
350
+ guardrails:
351
+ - guardrail_name: toxicity-lens
352
+ litellm_params:
353
+ guardrail: generic_guardrail_api
354
+ mode: pre_call # or post_call
355
+ api_base: http://localhost:8080
356
+ additional_provider_specific_params:
357
+ threshold: 0.8 # BLOCKED when any attribute reaches it
358
+ ```
359
+
360
+ - **Browser and Node.js (transformers.js).** The int8 export runs with transformers.js 3 (tested with 3.8.1 on Node.js):
361
+
362
+ ```js
363
+ import { pipeline } from "@huggingface/transformers";
364
+
365
+ const clf = await pipeline("text-classification", "abacusai/Toxicity-Lens", { dtype: "int8" });
366
+ console.log(await clf("You are a complete idiot and nobody wants you here.", { top_k: 7 }));
367
+ ```
368
+
369
+ transformers.js runs `onnx/model_int8.onnx` (a 309 MB download), plain dynamic int8 (its bundled ONNX Runtime 1.21 cannot load the 8-bit file the server uses), so its scores are close to the server's but not identical: it moves scores by 0.014 on average (99th percentile 0.09) and flips 1.4% of decisions at 0.5, and it tokenizes runs of two or more spaces differently (float32 scores up to 0.02 apart on such texts). Use the server or Python where exact scores matter.
370
+
371
+ - **ONNX.** `onnx/model.onnx` is float32 and matches PyTorch to 1.8e-07. `onnx/model_int8_block32.onnx` (322 MB; 8-bit block-wise weights with int8 compute; the default of the server and the Docker image) moves scores by 0.0008 on average (maximum 0.013) and changes 0.08% of decisions at 0.5 on 2,200 multilingual texts with ONNX Runtime's standard CPU kernels. With ONNX Runtime's generic CPU kernels (x86, Graviton, Apple M1 to M3) it is about 2.1 times as fast as float32 (23 vs 49 ms per comment on 4 threads of an Apple M5); on Apple M4 or newer, float32 is at least as fast (19 ms) and exact. It needs an ONNX Runtime with 8-bit MatMulNBits (tested with 1.31). `onnx/model_int8.onnx` (309 MB) is plain dynamic int8 for transformers.js and older runtimes. It quantizes activations per tensor, so on most CPUs and in browsers it moves scores by 0.014 on average (99th percentile 0.09) and flips 1.4% of decisions at 0.5; only on Apple M4 or newer, where ONNX Runtime's KleidiAI kernels quantize per row, does it stay much closer to float32. The server runs any of them with `BACKEND=onnx` (`ONNX_FILE` picks the file).
372
+
373
+ ## 7. License
374
+
375
+ Apache 2.0; see LICENSE, and NOTICE for the third-party notices. Training data and licences:
376
+
377
+ - Civil Comments (Jigsaw; Borkan et al., 2019), [google/civil_comments](https://huggingface.co/datasets/google/civil_comments), CC0 1.0.
378
+ - [RealToxicityPrompts](https://huggingface.co/datasets/allenai/real-toxicity-prompts) (Gehman et al., 2020), English prompts and continuations with the Perspective API's 2020 scores, Apache 2.0; three quarters of the prompts were used for training.
379
+ - [PolygloToxicityPrompts](https://huggingface.co/datasets/ToxicityPrompts/PolygloToxicityPrompts) (Jain et al., 2024), web text in 17 languages with the Perspective API's 2024 scores; its card lists CC BY 4.0 in its metadata and the AI2 ImpACT License (Low Risk Artifacts) in its text. Texts outside the ptp-small evaluation split were used for training.
380
+ - [Horizon-Labs/civil-comments-multilingual](https://huggingface.co/datasets/Horizon-Labs/civil-comments-multilingual), Civil Comments translated by Qwen3.8-27B, CC0 1.0.
381
+ - Further Civil Comments translated by us into Hinglish, Chinese, Arabic, Japanese, German and Italian with [Qwen/Qwen3.8-27B-FP8](https://huggingface.co/Qwen/Qwen3.8-27B-FP8) (Apache 2.0).
382
+ - [AfriHate](https://huggingface.co/datasets/afrihate/afrihate) (Muhammad et al., NAACL 2025), Amharic and Arabic; Apache 2.0 on Hugging Face, CC BY on [GitHub](https://github.com/AfriHate/AfriHate); labels remapped. The authors ask that models built with it not be used for automated removal.
383
+ - [MLMA](https://github.com/HKUST-KnowComp/MLMA_hate_speech) (Ousidhoum et al., 2019), Arabic, MIT, Copyright (c) 2019 HKUST-KnowComp; labels remapped.
384
+ - Tatar web text labelled by us with Qwen3.8-27B-FP8. Contains information from [FineWeb-2](https://huggingface.co/datasets/HuggingFaceFW/fineweb-2), which is made available under the [ODC Attribution License](https://opendatacommons.org/licenses/by/1-0/), and from [HPLT 2.0](https://huggingface.co/datasets/HPLT/HPLT2.0_cleaned) (CC0 packaging).
385
+ - Unlabelled Hebrew, Hinglish, Tatar and Ukrainian text from the same corpora, scored by the teacher model (section 4).
386
+ - Base model [jhu-clsp/mmBERT-base](https://huggingface.co/jhu-clsp/mmBERT-base), MIT; Gemma 2 tokenizer ([Gemma Terms of Use](https://ai.google.dev/gemma/terms)).
387
+
388
+ Perspective is a trademark of Google LLC. This project is not affiliated with or endorsed by Google or Jigsaw.
389
+
390
+ ## 8. Citation
391
+
392
+ ```bibtex
393
+ @misc{abacusai2026toxicitylens,
394
+ title = {Toxicity-Lens: open multilingual toxicity scoring compatible with the Perspective API},
395
+ author = {Abacus.AI},
396
+ year = {2026},
397
+ url = {https://huggingface.co/abacusai/Toxicity-Lens}
398
+ }
399
+ ```
400
+
401
+ The base model:
402
+
403
+ ```bibtex
404
+ @article{marone2025mmbert,
405
+ title = {mmBERT: A Modern Multilingual Encoder with Annealed Language Learning},
406
+ author = {Marone, Marc and Weller, Orion and Fleshman, William and Yang, Eugene and Lawrie, Dawn and Van Durme, Benjamin},
407
+ journal = {arXiv preprint arXiv:2509.06888},
408
+ year = {2025}
409
+ }
410
+ ```
411
+
412
+ ## 9. Contact Us
413
+
414
+ If you have any questions, please reach out at [Abacus.AI](https://abacus.ai).
415
+
calibration.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "TOXICITY": {
3
+ "T": 0.8929122997947895,
4
+ "bce_before": 0.2646329700946808,
5
+ "bce_after": 0.26298128362363515
6
+ },
7
+ "SEVERE_TOXICITY": {
8
+ "T": 0.9684695112553057,
9
+ "bce_before": 0.029446441680192947,
10
+ "bce_after": 0.0293868485471177
11
+ },
12
+ "IDENTITY_ATTACK": {
13
+ "T": 0.9416118377733703,
14
+ "bce_before": 0.0882946103811264,
15
+ "bce_after": 0.08797500147598228
16
+ },
17
+ "INSULT": {
18
+ "T": 0.9132882619547547,
19
+ "bce_before": 0.22088435292243958,
20
+ "bce_after": 0.21989169516100351
21
+ },
22
+ "PROFANITY": {
23
+ "T": 0.9623579977360014,
24
+ "bce_before": 0.06163929030299187,
25
+ "bce_after": 0.061528299611246236
26
+ },
27
+ "THREAT": {
28
+ "T": 0.9517709032739821,
29
+ "bce_before": 0.04334240034222603,
30
+ "bce_after": 0.043189824877234925
31
+ },
32
+ "SEXUALLY_EXPLICIT": {
33
+ "T": 0.9538984371826521,
34
+ "bce_before": 0.028525903820991516,
35
+ "bce_after": 0.02842793206334935
36
+ }
37
+ }
compare_with_perspective.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Check Toxicity-Lens against Perspective scores you already logged, before you switch.
2
+
3
+ Input: a CSV or JSONL file with a `text` column and one column per Perspective attribute you logged, named TOXICITY, INSULT, ...
4
+ (or perspective_TOXICITY, ...). For each attribute it prints rank agreement and, at your threshold, how many of Perspective's
5
+ flags this model keeps, how many extra texts it flags, and the threshold that flags the same share of texts as Perspective did.
6
+ Run: python compare_with_perspective.py logged.csv [--model abacusai/Toxicity-Lens] [--backend onnx] [--threshold 0.7]
7
+ """
8
+ import argparse
9
+ import csv
10
+ import json
11
+
12
+ import numpy as np
13
+
14
+ from server import ATTRS, Scorer
15
+
16
+
17
+ def rank(x):
18
+ r = np.empty(len(x))
19
+ r[np.argsort(x, kind="stable")] = np.arange(len(x))
20
+ return r
21
+
22
+
23
+ def main():
24
+ ap = argparse.ArgumentParser()
25
+ ap.add_argument("file")
26
+ ap.add_argument("--model", default="abacusai/Toxicity-Lens")
27
+ ap.add_argument("--backend", default="onnx", choices=["onnx", "torch"])
28
+ ap.add_argument("--threshold", type=float, default=0.5, help="the threshold you use with Perspective")
29
+ a = ap.parse_args()
30
+ with open(a.file, encoding="utf-8", newline="") as f:
31
+ rows = [json.loads(line) for line in f if line.strip()] if a.file.endswith(".jsonl") else list(csv.DictReader(f))
32
+ scorer = Scorer(a.model, a.backend)
33
+ ours = [s for i in range(0, len(rows), 256) for s, _ in scorer([str(r["text"]) for r in rows[i:i + 256]])]
34
+ t = a.threshold
35
+ print(f"{len(rows)} texts, threshold {t}\n{'attribute':<18}{'n':>7}{'spearman':>10}{'persp flags':>13}{'our flags':>11}"
36
+ f"{'kept':>8}{'extra':>8}{'same-rate threshold':>21}")
37
+ for attr in ATTRS:
38
+ col = next((c for c in (attr, f"perspective_{attr}", attr.lower(), f"perspective_{attr.lower()}") if c in rows[0]), None)
39
+ keep = [i for i, r in enumerate(rows) if col and r.get(col) not in (None, "")]
40
+ if len(keep) < 2:
41
+ continue
42
+ p = np.array([float(rows[i][col]) for i in keep])
43
+ o = np.array([ours[i][attr] for i in keep])
44
+ flag = p >= t
45
+ rho = np.corrcoef(rank(p), rank(o))[0, 1]
46
+ kept = f"{(o[flag] >= t).mean():.1%}" if flag.any() else "-"
47
+ extra = f"{(o[~flag] >= t).mean():.1%}" if (~flag).any() else "-"
48
+ same = f"{np.quantile(o, 1 - flag.mean()):.3f}" if 0 < flag.mean() < 1 else "-"
49
+ print(f"{attr:<18}{len(keep):>7}{rho:>10.3f}{flag.mean():>13.1%}{(o >= t).mean():>11.1%}{kept:>8}{extra:>8}{same:>21}")
50
+ print("\nkept = share of Perspective's flags this model also flags; extra = share of texts Perspective left below the threshold "
51
+ "that this model flags; same-rate threshold = the threshold at which this model flags as many texts as Perspective did.")
52
+
53
+
54
+ if __name__ == "__main__":
55
+ main()
config.json ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ModernBertForSequenceClassification"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 2,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 1,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 1,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 768,
22
+ "id2label": {
23
+ "0": "TOXICITY",
24
+ "1": "SEVERE_TOXICITY",
25
+ "2": "IDENTITY_ATTACK",
26
+ "3": "INSULT",
27
+ "4": "PROFANITY",
28
+ "5": "THREAT",
29
+ "6": "SEXUALLY_EXPLICIT"
30
+ },
31
+ "initializer_cutoff_factor": 2.0,
32
+ "initializer_range": 0.02,
33
+ "intermediate_size": 1152,
34
+ "label2id": {
35
+ "IDENTITY_ATTACK": 2,
36
+ "INSULT": 3,
37
+ "PROFANITY": 4,
38
+ "SEVERE_TOXICITY": 1,
39
+ "SEXUALLY_EXPLICIT": 6,
40
+ "THREAT": 5,
41
+ "TOXICITY": 0
42
+ },
43
+ "layer_norm_eps": 1e-05,
44
+ "layer_types": [
45
+ "full_attention",
46
+ "sliding_attention",
47
+ "sliding_attention",
48
+ "full_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "full_attention",
52
+ "sliding_attention",
53
+ "sliding_attention",
54
+ "full_attention",
55
+ "sliding_attention",
56
+ "sliding_attention",
57
+ "full_attention",
58
+ "sliding_attention",
59
+ "sliding_attention",
60
+ "full_attention",
61
+ "sliding_attention",
62
+ "sliding_attention",
63
+ "full_attention",
64
+ "sliding_attention",
65
+ "sliding_attention",
66
+ "full_attention"
67
+ ],
68
+ "local_attention": 128,
69
+ "mask_token_id": 4,
70
+ "max_position_embeddings": 8192,
71
+ "mlp_bias": false,
72
+ "mlp_dropout": 0.0,
73
+ "model_type": "modernbert",
74
+ "norm_bias": false,
75
+ "norm_eps": 1e-05,
76
+ "num_attention_heads": 12,
77
+ "num_hidden_layers": 22,
78
+ "pad_token_id": 0,
79
+ "position_embedding_type": "sans_pos",
80
+ "problem_type": "multi_label_classification",
81
+ "rope_parameters": {
82
+ "full_attention": {
83
+ "rope_theta": 160000,
84
+ "rope_type": "default"
85
+ },
86
+ "sliding_attention": {
87
+ "rope_theta": 160000,
88
+ "rope_type": "default"
89
+ }
90
+ },
91
+ "sep_token_id": 1,
92
+ "sparse_pred_ignore_index": -100,
93
+ "sparse_prediction": false,
94
+ "tie_word_embeddings": true,
95
+ "transformers_version": "5.14.1",
96
+ "vocab_size": 256000,
97
+ "global_rope_theta": 160000,
98
+ "local_rope_theta": 160000
99
+ }
figures/hero_textdetox.png ADDED
figures/perspective_thresholds.png ADDED

Git LFS Details

  • SHA256: df4dde1eec594fa213d5eca0053119e7acf80570ae9f040ba78b471e9e1b1321
  • Pointer size: 131 Bytes
  • Size of remote file: 116 kB
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b26a45f35664bd2d02dc5e4ef7baf5cb0c52007a7584565aae0651e9edd65b5
3
+ size 1230156812
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:169c2b864a5bc655fe795483e44d4dd468ca700a2e20ca35bb553e46f4b261af
3
+ size 1230745760
onnx/model_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:531ab587f1376e0f59e3c156a200ab74156562fa92d0840f4eb9945a381ff2e1
3
+ size 308570220
onnx/model_int8_block32.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f2a46b441d6f5a815e6c472275e5778497d58402df4efe15a9a6a2e1b4362bb
3
+ size 322277980
server.py ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scoring server for Toxicity-Lens, compatible with the Perspective API.
2
+
3
+ POST /v1alpha1/comments:analyze the Perspective API's request and response JSON (also served at /v1/comments:analyze)
4
+ POST /v1alpha1/comments:suggestscore accepted so clients that send feedback keep working; stored only if FEEDBACK_FILE is set
5
+ GET /$discovery/rest discovery document, so Google API client libraries can be pointed at this server
6
+ POST /v1/moderations OpenAI-style moderation shape, from the same scores
7
+ POST /beta/litellm_basic_guardrail_api LiteLLM's Generic Guardrail API (guardrail: generic_guardrail_api, api_base: this server)
8
+ GET /health
9
+
10
+ GPU or CPU (PyTorch): MODEL_DIR=abacusai/Toxicity-Lens uvicorn server:app --host 0.0.0.0 --port 8080
11
+ CPU without PyTorch: MODEL_DIR=abacusai/Toxicity-Lens BACKEND=onnx uvicorn server:app --host 0.0.0.0 --port 8080
12
+ Optional: ONNX_FILE (default onnx/model_int8_block32.onnx, 8-bit, about 0.001 from float32 on average on any CPU; onnx/model.onnx is
13
+ the exact float32 export; onnx/model_int8.onnx is plain dynamic int8 for transformers.js), API_KEYS=k1,k2 (requests must
14
+ carry one as ?key=, x-goog-api-key or a Bearer token), PUBLIC_URL (rootUrl in the discovery document, for use behind a proxy),
15
+ MODEL_REVISION (a commit hash of the model repo: pinning it keeps every score reproducible), ORT_THREADS (caps onnxruntime's
16
+ threads; set it to the container's CPU count, for example 2 on a Hugging Face cpu-basic Space).
17
+ """
18
+ import json
19
+ import os
20
+ import re
21
+ import threading
22
+ import uuid
23
+
24
+ import numpy as np
25
+ from fastapi import FastAPI, Request
26
+ from fastapi.concurrency import run_in_threadpool
27
+ from fastapi.responses import JSONResponse
28
+
29
+ ATTRS = ["TOXICITY", "SEVERE_TOXICITY", "IDENTITY_ATTACK", "INSULT", "PROFANITY", "THREAT", "SEXUALLY_EXPLICIT"]
30
+ MAX_BYTES = 20480 # Perspective's documented per-comment limit
31
+ MAX_TOKENS, STRIDE, BATCH = 256, 32, 32 # training, calibration and every evaluation scored 256-token windows
32
+ SENTENCE = re.compile(r"\S[^.!?。!?\n]*[.!?。!?]*") # spanAnnotations: Perspective returns per-sentence spans
33
+ # OpenAI moderation categories we can fill honestly from our attributes (plus our own "toxicity").
34
+ OPENAI_MAP = {"harassment": "INSULT", "harassment/threatening": "THREAT", "hate": "IDENTITY_ATTACK",
35
+ "sexual": "SEXUALLY_EXPLICIT", "violence": "THREAT", "toxicity": "TOXICITY"}
36
+
37
+
38
+ class Scorer:
39
+ """Scores texts with a saved Toxicity-Lens model. A text longer than one 256-token window is scored in overlapping
40
+ windows and each attribute keeps its highest window score, so an insult deep inside a long comment still counts."""
41
+
42
+ def __init__(self, path: str, backend: str = "torch", onnx_file: str = "onnx/model_int8_block32.onnx", logits_fn=None, revision=None):
43
+ from tokenizers import Tokenizer
44
+ if not os.path.isdir(path):
45
+ from huggingface_hub import snapshot_download
46
+ weights = ["model.safetensors"] if backend == "torch" else [onnx_file, onnx_file + ".data"]
47
+ path = snapshot_download(path, revision=revision, allow_patterns=["config.json", "tokenizer.json", "tokenizer_config.json", *weights])
48
+ labels = json.load(open(f"{path}/config.json"))["id2label"]
49
+ assert [labels[str(i)] for i in range(len(labels))] == ATTRS, f"model labels {labels} are not the Perspective attribute set"
50
+ self.tok = Tokenizer.from_file(f"{path}/tokenizer.json")
51
+ self.tok.enable_truncation(MAX_TOKENS, stride=STRIDE)
52
+ self.tok.no_padding()
53
+ self.pad_id = self.tok.token_to_id(json.load(open(f"{path}/tokenizer_config.json"))["pad_token"])
54
+ self.lock = threading.Lock() # ponytail: one forward pass at a time; add micro-batching if one GPU must serve >200 requests/s
55
+ self.logits = logits_fn or (self._onnx(path, onnx_file) if backend == "onnx" else self._torch(path))
56
+
57
+ @staticmethod
58
+ def _onnx(path, onnx_file):
59
+ import onnxruntime as ort
60
+ so = ort.SessionOptions()
61
+ so.intra_op_num_threads = int(os.environ.get("ORT_THREADS", "0")) # 0 = onnxruntime's default, one thread per core it detects
62
+ sess = ort.InferenceSession(f"{path}/{onnx_file}", so, providers=["CPUExecutionProvider"])
63
+ return lambda ids, mask: sess.run(None, {"input_ids": ids, "attention_mask": mask})[0]
64
+
65
+ @staticmethod
66
+ def _torch(path):
67
+ import torch
68
+ from transformers import AutoModelForSequenceClassification
69
+ dev = "cuda" if torch.cuda.is_available() else "cpu"
70
+ dtype = torch.bfloat16 if dev == "cuda" else torch.float32
71
+ model = AutoModelForSequenceClassification.from_pretrained(path, dtype=dtype).to(dev).eval()
72
+
73
+ def run(ids, mask):
74
+ with torch.no_grad():
75
+ out = model(input_ids=torch.from_numpy(ids).to(dev), attention_mask=torch.from_numpy(mask).to(dev))
76
+ return out.logits.float().cpu().numpy()
77
+ return run
78
+
79
+ def __call__(self, texts):
80
+ """One (summary {attribute: probability}, [(begin, end, {attribute: probability}) per window]) per text."""
81
+ wins, owner = [], []
82
+ for i, enc in enumerate(self.tok.encode_batch(list(texts))):
83
+ for w in [enc, *enc.overflowing]:
84
+ wins.append(w)
85
+ owner.append(i)
86
+ probs = []
87
+ with self.lock:
88
+ for b in range(0, len(wins), BATCH):
89
+ part = wins[b:b + BATCH]
90
+ ids = np.full((len(part), max(len(w.ids) for w in part)), self.pad_id, dtype=np.int64)
91
+ mask = np.zeros_like(ids)
92
+ for j, w in enumerate(part):
93
+ ids[j, :len(w.ids)], mask[j, :len(w.ids)] = w.ids, 1
94
+ probs.append(1 / (1 + np.exp(-self.logits(ids, mask).astype(np.float64))))
95
+ out = [[None, []] for _ in texts]
96
+ for w, i, p in zip(wins, owner, np.concatenate(probs)):
97
+ offs = [o for o, special in zip(w.offsets, w.special_tokens_mask) if not special] or [(0, 0)]
98
+ out[i][1].append((offs[0][0], offs[-1][1], dict(zip(ATTRS, p.tolist()))))
99
+ out[i][0] = p if out[i][0] is None else np.maximum(out[i][0], p)
100
+ return [(dict(zip(ATTRS, s.tolist())), spans) for s, spans in out]
101
+
102
+
103
+ def error(code: int, message: str, status: str = "INVALID_ARGUMENT"):
104
+ return JSONResponse(status_code=code, content={"error": {"code": code, "message": message, "status": status}})
105
+
106
+
107
+ def discovery_doc(root: str) -> dict:
108
+ """Just enough of a discovery document for googleapiclient / googleapis to build a commentanalyzer v1alpha1 client."""
109
+ def method(name, request, response):
110
+ return {"id": f"commentanalyzer.comments.{name}", "path": f"v1alpha1/comments:{name}", "flatPath": f"v1alpha1/comments:{name}",
111
+ "httpMethod": "POST", "parameters": {}, "parameterOrder": [], "request": {"$ref": request}, "response": {"$ref": response}}
112
+ names = ["AnalyzeCommentRequest", "AnalyzeCommentResponse", "SuggestCommentScoreRequest", "SuggestCommentScoreResponse"]
113
+ return {"kind": "discovery#restDescription", "discoveryVersion": "v1", "id": "commentanalyzer:v1alpha1", "name": "commentanalyzer",
114
+ "version": "v1alpha1", "title": "Toxicity-Lens (compatible with the Perspective API)", "protocol": "rest",
115
+ "rootUrl": root, "servicePath": "", "baseUrl": root, "batchPath": "batch",
116
+ "parameters": {"key": {"type": "string", "location": "query"}, "alt": {"type": "string", "location": "query", "default": "json"}},
117
+ "schemas": {n: {"id": n, "type": "object"} for n in names},
118
+ "resources": {"comments": {"methods": {"analyze": method("analyze", *names[:2]), "suggestscore": method("suggestscore", *names[2:])}}}}
119
+
120
+
121
+ def create_app(scorer, model_name: str = "toxicity-lens") -> FastAPI:
122
+ app = FastAPI(title="Toxicity-Lens scorer, compatible with the Perspective API")
123
+ keys = {k for k in os.environ.get("API_KEYS", "").split(",") if k}
124
+ feedback = os.environ.get("FEEDBACK_FILE")
125
+
126
+ def denied(request: Request):
127
+ if not keys:
128
+ return None
129
+ auth = request.headers.get("authorization", "")
130
+ key = request.query_params.get("key") or request.headers.get("x-goog-api-key") or (auth[7:] if auth.lower().startswith("bearer ") else None)
131
+ if not key:
132
+ return error(403, "The request is missing a valid API key.", "PERMISSION_DENIED")
133
+ return None if key in keys else error(400, "API key not valid. Please pass a valid API key.")
134
+
135
+ async def read_json(request: Request):
136
+ try:
137
+ body = await request.json()
138
+ except Exception:
139
+ return None
140
+ return body if isinstance(body, dict) else None
141
+
142
+ @app.get("/health")
143
+ def health():
144
+ return {"status": "ok", "model": model_name}
145
+
146
+ @app.get("/$discovery/rest")
147
+ def discovery(request: Request):
148
+ return discovery_doc(os.environ.get("PUBLIC_URL", str(request.base_url)).rstrip("/") + "/")
149
+
150
+ async def analyze(request: Request):
151
+ if (refused := denied(request)) is not None:
152
+ return refused
153
+ body = await read_json(request)
154
+ if body is None:
155
+ return error(400, "Invalid JSON payload received.")
156
+ comment = body.get("comment")
157
+ text = comment.get("text") if isinstance(comment, dict) else None
158
+ if not isinstance(text, str) or not text.strip():
159
+ return error(400, "Comment must be non-empty.")
160
+ if comment.get("type", "PLAIN_TEXT") != "PLAIN_TEXT":
161
+ return error(400, "Only PLAIN_TEXT comments are supported.")
162
+ if len(text.encode("utf-8")) > MAX_BYTES:
163
+ return error(400, f"Comment text too long. Must be at most {MAX_BYTES} bytes.")
164
+ requested = body.get("requestedAttributes")
165
+ if not isinstance(requested, dict) or not requested:
166
+ return error(400, "Must specify at least one requestedAttribute.")
167
+ for attr, opts in requested.items():
168
+ if attr not in ATTRS:
169
+ return error(400, f"Attribute {attr} is not supported by this server.")
170
+ if isinstance(opts, dict) and opts.get("scoreType", "PROBABILITY") != "PROBABILITY":
171
+ return error(400, f"Score type {opts['scoreType']} is not supported.")
172
+ summary = (await run_in_threadpool(scorer, [text]))[0][0]
173
+ spans = [(0, len(text), summary)]
174
+ if body.get("spanAnnotations"):
175
+ sents = [m.span() for m in SENTENCE.finditer(text)]
176
+ spans = [(b, e, s) for (b, e), (s, _) in zip(sents, await run_in_threadpool(scorer, [text[b:e] for b, e in sents]))]
177
+ out = {}
178
+ for attr, opts in requested.items():
179
+ threshold = opts.get("scoreThreshold") if isinstance(opts, dict) else None
180
+ if threshold is not None and summary[attr] < float(threshold):
181
+ continue # Perspective omits attributes scored below the requested threshold
182
+ out[attr] = {"spanScores": [{"begin": b, "end": e, "score": {"value": s[attr], "type": "PROBABILITY"}} for b, e, s in spans],
183
+ "summaryScore": {"value": summary[attr], "type": "PROBABILITY"}}
184
+ resp = {"attributeScores": out, "languages": body.get("languages") or ["und"]} # no language detection: echoes the request
185
+ if "clientToken" in body:
186
+ resp["clientToken"] = body["clientToken"]
187
+ return resp
188
+
189
+ app.post("/v1alpha1/comments:analyze")(analyze)
190
+ app.post("/v1/comments:analyze")(analyze)
191
+
192
+ @app.post("/v1alpha1/comments:suggestscore")
193
+ async def suggest_score(request: Request):
194
+ if (refused := denied(request)) is not None:
195
+ return refused
196
+ body = await read_json(request)
197
+ if body is None or not isinstance(body.get("comment"), dict) or not isinstance(body.get("attributeScores"), dict):
198
+ return error(400, "Request must include comment and attributeScores.")
199
+ if feedback:
200
+ with open(feedback, "a", encoding="utf-8") as f:
201
+ f.write(json.dumps(body, ensure_ascii=False) + "\n")
202
+ resp = {"requestedLanguages": body.get("languages") or []}
203
+ if "clientToken" in body:
204
+ resp["clientToken"] = body["clientToken"]
205
+ return resp
206
+
207
+ @app.post("/v1/moderations")
208
+ async def moderations(request: Request):
209
+ if (refused := denied(request)) is not None:
210
+ return refused
211
+ body = await read_json(request)
212
+ inp = body.get("input") if body else None
213
+ texts = [inp] if isinstance(inp, str) else inp
214
+ if not isinstance(texts, list) or not texts or not all(isinstance(t, str) and t for t in texts):
215
+ return JSONResponse(status_code=400, content={"error": {"message": "input must be a non-empty string or list of strings",
216
+ "type": "invalid_request_error"}})
217
+ results = []
218
+ for summary, _ in await run_in_threadpool(scorer, texts):
219
+ cs = {cat: summary[attr] for cat, attr in OPENAI_MAP.items()}
220
+ results.append({"flagged": any(v >= 0.5 for v in cs.values()), "categories": {k: v >= 0.5 for k, v in cs.items()},
221
+ "category_scores": cs})
222
+ return {"id": f"modr-{uuid.uuid4().hex[:24]}", "model": body.get("model") or model_name, "results": results}
223
+
224
+ @app.post("/beta/litellm_basic_guardrail_api")
225
+ async def litellm_guardrail(request: Request):
226
+ """LiteLLM's Generic Guardrail API: BLOCKED when any text reaches the threshold on any chosen attribute. Set
227
+ additional_provider_specific_params {threshold, attributes} in the LiteLLM guardrail config to change the defaults."""
228
+ if (refused := denied(request)) is not None:
229
+ return refused
230
+ body = await read_json(request) or {}
231
+ texts = [t for t in body.get("texts") or [] if isinstance(t, str) and t.strip()]
232
+ params = body.get("additional_provider_specific_params") or {}
233
+ threshold = float(params.get("threshold", 0.8))
234
+ attrs = [a for a in params.get("attributes") or ATTRS if a in ATTRS]
235
+ hits = sorted({a for s, _ in await run_in_threadpool(scorer, texts) for a in attrs if s[a] >= threshold}) if texts else []
236
+ if hits:
237
+ return {"action": "BLOCKED", "blocked_reason": f"{model_name}: {', '.join(hits)} at or above {threshold}"}
238
+ return {"action": "NONE"}
239
+
240
+ return app
241
+
242
+
243
+ if os.environ.get("MODEL_DIR"):
244
+ app = create_app(Scorer(os.environ["MODEL_DIR"], os.environ.get("BACKEND", "torch"), os.environ.get("ONNX_FILE", "onnx/model_int8_block32.onnx"),
245
+ revision=os.environ.get("MODEL_REVISION")), os.environ.get("MODEL_NAME", "toxicity-lens"))
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a5069feab370ece9f452dcda41c0ba2c216eebf6cb49b06893698f53cdc2b0b
3
+ size 34363441
tokenizer_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<bos>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "cls_token": "<bos>",
6
+ "eos_token": "<eos>",
7
+ "mask_token": "<mask>",
8
+ "model_input_names": [
9
+ "input_ids",
10
+ "attention_mask"
11
+ ],
12
+ "model_max_length": 256,
13
+ "pad_token": "<pad>",
14
+ "padding_side": "right",
15
+ "sep_token": "<eos>",
16
+ "spaces_between_special_tokens": false,
17
+ "tokenizer_class": "PreTrainedTokenizerFast",
18
+ "unk_token": "<unk>"
19
+ }