Views
No views yet
| Label | Description |
|---|---|
toxic | 有毒 |
severe_toxic | 严重有毒 |
obscene | 淫秽 |
threat | 威胁 |
insult | 侮辱 |
identity_hate | 身份仇恨 |
1import torch
2from transformers import AutoTokenizer, AutoModel
3from peft import PeftModel
4
5# Load base model
6base_model = AutoModel.from_pretrained(
7 "Qwen/Qwen3-0.6B-Base",
8 trust_remote_code=True
9)
10
11# Load LoRA adapters
12model = PeftModel.from_pretrained(
13 base_model,
14 "yingfeng64/QwenTox"
15)
16
17# Load tokenizer
18tokenizer = AutoTokenizer.from_pretrained(
19 "Qwen/Qwen3-0.6B-Base",
20 trust_remote_code=True
21)
22
23# Load classification head
24state_dict = torch.load("classifier_head.pt", map_location="cpu")
25model.classifier.load_state_dict(state_dict)
26
27model.eval()threat, severe_toxic, and identity_hate| Hyperparameter | Value |
|---|---|
| Precision | FP16 (mixed precision) |
| Optimizer | AdamW |
| Learning rate | 5e-5 |
| Epochs | 3 |
| Max sequence length | 384 |
| LoRA rank (r) | 128 |
| LoRA alpha | 256 |
| LoRA dropout | 0.3 |