detoxify multilingual_debiased β€” for softmax-only serving runtimes

Use this variant only if your serving runtime applies a softmax to a sequence classifier. For anything else, use the plain conversion gpillon/detoxify-multilingual-debiased.

This is the detoxify multilingual checkpoint (multilingual_debiased-0b549669.ckpt, release v0.4-alpha), converted to XLMRobertaForSequenceClassification (safetensors + tokenizer). The head has one extra output, sigmoid_reference, whose weights and bias are zero, so its logit is always 0. The 16 detoxify outputs, and every other tensor, are bit-identical to the plain conversion.

Why

detoxify is multi-label: each label gets its own sigmoid. Some runtimes always apply a softmax over all labels instead, whatever problem_type says. One example is the OpenShift AI guardrails detector HuggingFace runtime (process_sequence_classification). With a softmax the scores have to share a total of 1, so they no longer mean anything per label. For example, a sentence scored toxicity 0.973 and insult 0.919 by detoxify comes out of the runtime as toxicity 0.747 and insult 0.232.

Serving with a softmax runtime

The reference logit is always 0, so on the runtime's softmax p_i / p_ref = e^{z_i}, and the original sigmoid can be recovered exactly:

sigmoid(z_i) = p_i / (p_i + p_ref)        p_ref = score of "sigmoid_reference"

The client must:

  1. Get a score for every label, sigmoid_reference included. If the runtime only returns labels above a threshold, set that threshold to 0. Otherwise sigmoid_reference is dropped exactly when the text is toxic, because p_ref is then small.
  2. Convert each score with the formula above and discard sigmoid_reference.
  3. Calibrate thresholds on the recovered sigmoid scores. They are much higher than the raw softmax scores (0.973 vs 0.747 above).

Here is an example with the OpenShift AI guardrails detector runtime, which needs the SAFE_LABELS=[] env on the runtime because label 0 (toxicity) is "safe" by default:

POST /api/v1/text/contents
{"contents": ["<text>"], "detector_params": {"threshold": 0.0, "safe_labels": []}}

Labels

id label id label
0 toxicity 9 identity_homosexual_gay_or_lesbian
1 severe_toxicity 10 identity_christian
2 obscene 11 identity_jewish
3 identity_attack 12 identity_muslim
4 insult 13 identity_black
5 threat 14 identity_white
6 sexual_explicit 15 identity_psychiatric_or_mental_illness
7 identity_male 16 sigmoid_reference (constant logit 0)
8 identity_female

Labels 0–6 are the detoxify classes. Labels 7–15 are the identity sub-groups of the debiased head.

Usage with transformers

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

repo = "gpillon/detoxify-multilingual-debiased-softmax-ref"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()

with torch.no_grad():
    logits = model(**tok("Sei un idiota e ti odio.", return_tensors="pt", truncation=True)).logits
scores = torch.sigmoid(logits)[0][:16]  # drop sigmoid_reference
print({model.config.id2label[i]: round(s.item(), 4) for i, s in enumerate(scores)})

Provenance and checks

Source checkpoint https://github.com/unitaryai/detoxify/releases/download/v0.4-alpha/multilingual_debiased-0b549669.ckpt
Checkpoint SHA256 0b5496691403977207f24778695389494a412a76c2cb351e99f024f2a4e3f3ff
Base config / tokenizer FacebookAI/xlm-roberta-base @ e73636d4f797dec63c3081bb6ed5c7b0bb3f2089

convert.py is the exact conversion script. It ran inside the OpenShift AI guardrails detector runtime image, with transformers 4.57.3. It downloads the checkpoint and verifies its SHA256. It then checks the label set and the state dict, and appends the zero output. Finally it reloads the model and checks four sentences (two toxic Italian and English sentences, one obscene English sentence, one clean Italian sentence):

  • the 16 detoxify logits are unchanged and the reference logit is exactly 0;
  • p_i / (p_i + p_ref), computed on the 17-label softmax, equals the original sigmoid (atol 1e-5; measured max 6e-8);
  • the toxic and clean verdicts are as expected.
CKPT_URL=... CKPT_SHA256=... BASE_MODEL=FacebookAI/xlm-roberta-base \
BASE_REVISION=e73636d4f797dec63c3081bb6ed5c7b0bb3f2089 python convert.py ./out

verify.py is an independent check that needs the detoxify package:

  • every tensor is identical to the plain conversion, except the head, which has one extra zero row;
  • the sigmoid recovered from the softmax matches Detoxify('multilingual').predict on 8 sentences in 5 languages (measured max difference 8e-7).

SHA256SUMS lists the checksums of the published files.

License and credits

  • detoxify by Unitary AI: Apache-2.0. Laura Hanu and Unitary team, Detoxify, GitHub, 2020.
  • XLM-RoBERTa base (FacebookAI/xlm-roberta-base): MIT.

This repository redistributes the converted weights under Apache-2.0. All credit for training goes to the detoxify authors. See the detoxify README for the model's limitations and biases.

Downloads last month
24
Safetensors
Model size
0.3B params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for gpillon/detoxify-multilingual-debiased-softmax-ref

Finetuned
(4,335)
this model