M2: Qwen3-4B fine-tuned as a toxicity moderator
M2 of the CS 769 (UW–Madison) project Auditing Social Bias in Language Models: Metrics & a
Category-Aware Framework (Natarajan, Ethiraj, Venkatesan). It is Qwen/Qwen3-4B (M0) after
full fine-tuning on cleaned ETHOS and ToxicCommons posts, trained to answer whether a post is toxic. The project
compares the base model (M0), plain fine-tuning (M2) and fine-tuning with a counterfactual loss (M4), with
and without few-shot prompting, using a counterfactual bias test:
how much the answer moves when only the gender or disability a post refers to is swapped, beyond how
much it moves under matched neutral rewordings (Yang et al., 2026).
How to use
The model is read as a classifier: the probability of the first answer token after the prompt it was trained on.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "gayathri-er/kqv-m2-qwen3-4b-v1"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype="auto", device_map="auto")
def p_toxic(post):
messages = [
{"role": "system", "content": 'You are a content moderator.'},
{"role": "user", "content": 'Is the following social media post toxic?' + "\n\nPost: " + post
+ "\n\nAnswer with exactly one of: No, Yes."},
]
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
ids = tok(text, return_tensors="pt", add_special_tokens=False).to(model.device)
logits = model(**ids).logits[0, -1]
options = [tok('No', add_special_tokens=False).input_ids[0], tok('Yes', add_special_tokens=False).input_ids[0]]
return torch.softmax(logits[options].float(), dim=-1)[1].item()
print(p_toxic("My deaf cousin keeps texting me about the game tonight."))
In the project's bias framework (bias-compare-poc) it is an hf-causal-lm model; m2_prompt.yaml in
this repo is the prompt to score it with.
Training
| Base model (M0) | Qwen/Qwen3-4B |
| Method | full fine-tuning, lr 1e-05, adamw_bnb_8bit, bfloat16 |
| Objective | cross-entropy on the first token of the correct answer ('Yes' = toxic, 'No' = not toxic) after the prompt above. |
| Data | 20,000 training rows from the project's train split (Civil Comments + ETHOS, English, deduplicated), oversampled: disability=0.1 |
| Epochs / effective batch | 1.0 / 32 |
| Max prompt length | 1024 tokens (cut from the left) |
| Selection | none: the weights after the last step (no early stopping); validation loss logged every 100 steps |
| Steps / time | 625 steps, 34.2 min on NVIDIA A100-SXM4-80GB |
Evaluation (M0 = base model, M2 = this model)
Scored with the bias framework's LLM adapter on held-out posts. FPR is the share of benign posts flagged toxic; "mentions gender/disability" counts every post that mentions the category.
| split | group | acc M0 | acc M2 | macro-F1 M0 | macro-F1 M2 | AUROC M0 | AUROC M2 | FPR M0 | FPR M2 | FNR M0 | FNR M2 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| val | overall | 0.533 | 0.922 | 0.428 | 0.922 | 0.617 | 0.978 | 0.899 | 0.094 | 0.010 | 0.061 |
| val | mentions gender | 0.568 | 0.904 | 0.427 | 0.903 | 0.588 | 0.967 | 0.921 | 0.137 | 0.017 | 0.062 |
| val | mentions disability | 0.522 | 0.904 | 0.412 | 0.904 | 0.603 | 0.964 | 0.913 | 0.136 | 0.004 | 0.053 |
| val | mentions none | 0.510 | 0.934 | 0.424 | 0.934 | 0.634 | 0.986 | 0.888 | 0.073 | 0.005 | 0.057 |
| test | overall | 0.546 | 0.934 | 0.455 | 0.934 | 0.627 | 0.981 | 0.868 | 0.078 | 0.009 | 0.053 |
| test | mentions gender | 0.580 | 0.935 | 0.464 | 0.935 | 0.620 | 0.981 | 0.878 | 0.089 | 0.013 | 0.044 |
| test | mentions disability | 0.546 | 0.932 | 0.457 | 0.932 | 0.621 | 0.980 | 0.864 | 0.090 | 0.006 | 0.043 |
| test | mentions none | 0.514 | 0.935 | 0.437 | 0.934 | 0.636 | 0.981 | 0.870 | 0.066 | 0.007 | 0.064 |
These are error rates on labelled data.
Counterfactual gap on lexicon/adjective swaps of held-out posts: mean |P(toxic) original − P(toxic) swapped| (also on benign posts only), direction = the women's / disabled version minus the other (positive = scored as more toxic), and the share of answers that flip. This is the raw gap, without the paraphrase baseline. The project's bias result (Δ, which subtracts that baseline) is reported separately.
| split | axis | pairs | gap M0 | gap M2 | gap benign M0 | gap benign M2 | direction M0 | direction M2 | flips M0 | flips M2 |
|---|---|---|---|---|---|---|---|---|---|---|
| val | gender | 300 | 0.009 | 0.004 | 0.006 | 0.005 | 0.003 | 0.002 | 0.007 | 0.003 |
| val | disability | 142 | 0.013 | 0.025 | 0.019 | 0.029 | -0.005 | 0.019 | 0.021 | 0.035 |
| test | gender | 300 | 0.009 | 0.005 | 0.019 | 0.008 | 0.008 | 0.004 | 0.010 | 0.000 |
| test | disability | 210 | 0.024 | 0.020 | 0.045 | 0.027 | 0.024 | 0.016 | 0.024 | 0.024 |
Data and limitations
- ETHOS (Mollas et al., 2020): YouTube and Reddit comments with crowd-sourced hate labels; GPL-3.0 licence.
- ToxicCommons (Arnett et al., 2024), via
tcapelle/ToxicCommons-balanced(no licence stated on the dataset card): mostly OCR'd public-domain books and newspapers, labelled by Llama-3.1-8B, so the domain is not social media and the labels are model-made. - English only. A research artefact for studying moderation bias, not a production moderator.
- Check the data licences before redistributing this model; the licence field above is the base model's.