textdetox/multilingual_toxicity_dataset
Viewer • Updated • 71.4k • 2.34k • 37
How to use j-llm/toxic_v3 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="j-llm/toxic_v3") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("j-llm/toxic_v3")
model = AutoModelForSequenceClassification.from_pretrained("j-llm/toxic_v3", device_map="auto")短文日本語向け10 ラベルの有害コメント分類モデルです。
toxicity, harassment(中傷・嫌がらせ), obscene(性的), discrimination(差別), threat(脅し), spoiler(ネタバレ), instruction(※定義を記入), pigeon(※定義を記入), self_promotion(宣伝), spam
import torch, unicodedata
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "j-llm/toxic_v3"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
def predict(text):
text = unicodedata.normalize("NFKC", text)
x = tok(text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
p = torch.sigmoid(model(**x).logits)[0]
return {model.config.id2label[i]: float(v) for i, v in enumerate(p)}
openvino_int8/ に、OpenVINO の int8 量子化版(max_len 64)があります。fp16 (PyTorch, max_len 128) と比べた判断の食い違いは、実チャット 21,542 件で 0.24%、検証用チャット 11,052 件で 0.05% でした。
| 評価 | v2 | v3(unfinetune) | v3 |
|---|---|---|---|
| 無害な文の誤検出率 | 3.9% | 1.9% | 1.0% |
| 紛らわしい有害な文の検出率 | 71.3% | 73.6% | 83.1% |
| 紛らわしい文の誤検出率 | 8.7% | 14.5% | 5.8% |
| 有害な文の検出率 | 89.3% | 89.3% | 91.1% |
thresholds.json を下げてください。複数の公開データセットと、自作の合成データ・紛らわしい文の追加データを混ぜています(総数は約 45 万件)。
Base model
ku-nlp/deberta-v3-base-japanese