T5Gemma2-Detox-RU

A text detoxification model for Russian and English: it rewrites toxic text into a neutral form while preserving the original meaning.

Fine-tuned in two stages on top of google/t5gemma-2-1b-1b:

  1. SFT — supervised fine-tuning on toxic-to-neutral text pairs.
  2. DPO/ORPO — further alignment on synthetic preference pairs (chosen/rejected) on top of the SFT checkpoint, trained with FSDP.

📦 Full training code (SFT + DPO/ORPO), data preprocessing, and checkpoint upload scripts are available in the vilovnok/detox-alignment repository.

Как пользоваться

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer


model_id = "r1char9/t5gemma2-detox-ru"
LANG_PROMPTS = {
    'ru': 'Детоксифицируй: ',
    'en': 'Detoxify: ',
}

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
model.to('cuda')
model.eval()

text = LANG_PROMPTS['ru'] + """Опять вы без спроса списали деньги с моей карты, блять, какое вам нужно моё разрешение?
Я уже третий раз звоню в эту вашу контору, а вместо толковых ответов мне подсунули какого-то мудака-оператора,
который только и умеет, что врать про «технические работы». Верните мои средства немедленно, иначе я разберусь
с вашим руководством и напишу заявление в ЦБ, а то у вас тут всё как в цирке, один сплошной позор.""".strip()

inputs = tokenizer(text, return_tensors="pt").to(model.device)

outputs = model.generate(
    **inputs,
    max_length=512,
    num_beams=5,
    no_repeat_ngram_size=3,
    repetition_penalty=1.2,
    early_stopping=True,
)

print(tokenizer.decode(outputs[0], skip_special_tokens=True))

# Опять вы без моего согласия списали средства с моей карты, какое вам нужно моё разрешение?
# Я уже третий раз обращаюсь в вашу службу поддержки, но вместо толковых ответов мне присылают шаблонные сообщения про «технические работы».
# Прошу немедленно вернуть деньги, иначе я буду вынужден обратиться в ЦБ и написать официальное обращение, так как текущая ситуация вызывает серьёзное недовольство.

The model expects input text with a language-specific prompt prefix:

Language Prompt
ru Детоксифицируй:
en Detoxify:

Training

Stage 1 — SFT

Base model google/t5gemma-2-1b-1b
Dataset r1char9/toxic-detox-pairs
Data format toxic_comment, neutral_comment, lang
Method Fine-tuning of attention projections (q_proj, k_proj, v_proj, o_proj)
Loss Cross-entropy (seq2seq)
Metric Cosine similarity of LaBSE embeddings between generation and reference

Stage 2 — DPO/ORPO

Starting model SFT checkpoint from stage 1
Dataset r1char9/detox-dpo-dataset
Data format toxic_text, chosen, rejected
Labeling source Preference pairs synthesized by Qwen/Qwen3.6-35B-A3B-FP8
Method ORPO (odds-ratio preference optimization, no separate reward model)
Distributed training FSDP (Fully Sharded Data Parallel)

The model was trained to increase the likelihood of the chosen detoxification variant relative to rejected for the same toxic_text, further aligning the style and quality of generations on top of the SFT baseline.

Hyperparameters

Parameter SFT DPO/ORPO
Batch size 16 8–32
Learning rate 5e-5 3e-6–5e-6
Optimizer AdamW AdamW
Scheduler Cosine Cosine
Weight decay 0.05 0.05
Precision bfloat16 bfloat16 (FSDP mixed precision)

Limitations

  • The model was trained primarily on Russian text; quality on other languages is not guaranteed.

Datasets

Downloads last month
189
Safetensors
Model size
2B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for r1char9/t5gemma2-detox-ru-en

Finetuned
(11)
this model

Datasets used to train r1char9/t5gemma2-detox-ru-en

Collection including r1char9/t5gemma2-detox-ru-en