Text Classification
Safetensors
Chinese
qwen2
File size: 2,670 Bytes
99c11c6
7ceed7b
 
2fcb21e
 
7ceed7b
2fcb21e
7ceed7b
99c11c6
7ceed7b
99c11c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ceed7b
 
 
 
99c11c6
 
7ceed7b
99c11c6
 
 
7ceed7b
99c11c6
 
 
 
 
 
 
 
 
7ceed7b
99c11c6
 
 
7ceed7b
99c11c6
7ceed7b
99c11c6
 
 
 
 
 
 
 
 
 
 
 
 
7ceed7b
 
 
 
 
 
 
 
 
 
 
99c11c6
 
7ceed7b
99c11c6
 
5154e62
 
 
 
 
 
 
 
 
7ceed7b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
datasets:
- zjunlp/ChineseHarm-bench
language:
- zh
license: cc-by-nc-4.0
pipeline_tag: text-classification
library_name: transformers
---

## 🚀Installation

1. Clone the repositories:

   ```bash
   git clone https://github.com/zjunlp/ChineseHarm-bench
   cd ChineseHarm-bench
   git clone https://github.com/hiyouga/LLaMA-Factory
   ```

2. Install dependencies:

   ```bash
   cd LLaMA-Factory
   pip install -e ".[torch,metrics]" 
   ```

## 📚Inference

We release the following variants of our harmful content detection model:

- [**ChineseGuard-1.5B**](https://huggingface.co/zjunlp/ChineseGuard-1.5B)
- [**ChineseGuard-3B**](https://huggingface.co/zjunlp/ChineseGuard-3B)
- [**ChineseGuard-7B**](https://huggingface.co/zjunlp/ChineseGuard-7B)

🔹 Single Inference (Example)

Run single-input inference using the ChineseGuard-1.5B model:

```
SCRIPT_PATH="../infer/single_infer.py"
model_name="zjunlp/ChineseGuard-1.5B"
text="代发短信,有想做的联系我,无押金"

python $SCRIPT_PATH \
    --model_name $model_name \
    --text $text
```

🔸 Batch Inference (Multi-NPU or Multi-GPU)

To run inference on the entire ChineseHarm-Bench using ChineseGuard-1.5B and 8 NPUs:

```
SCRIPT_PATH="../infer/batch_infer.py"
model_name="zjunlp/ChineseHarm-1.5B"
file_name="../benchmark/bench.json"
output_file="../benchmark/bench_ChineseHarm-1.5B.json"

python $SCRIPT_PATH \
    --model_name $model_name \
    --file_name $file_name \
    --output_file $output_file \
    --num_npus 8

```

> For more configuration options (e.g., batch size, device selection, custom prompt templates), please refer to `single_infer.py` and `batch_infer.py`.
>
> **Note:** The inference scripts support both NPU and GPU devices.

**Evaluation: Calculating F1 Score**

After inference, evaluate the predictions by computing the F1 score with the following command:

```
python ../calculate_metrics.py \
    --file_path "../benchmark/bench_ChineseHarm-1.5B.json" \
    --true_label_field "标签" \
    --predicted_label_field "predict_label"
```

## 🚩Citation

Please cite our repository if you use ChineseHarm-bench in your work. Thanks!

```bibtex
@misc{liu2025chineseharmbenchchineseharmfulcontent,
      title={ChineseHarm-Bench: A Chinese Harmful Content Detection Benchmark}, 
      author={Kangwei Liu and Siyuan Cheng and Bozhong Tian and Xiaozhuan Liang and Yuyang Yin and Meng Han and Ningyu Zhang and Bryan Hooi and Xi Chen and Shumin Deng},
      year={2025},
      eprint={2506.10960},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2506.10960}, 
}
```

Codebase: https://github.com/zjunlp/ChineseHarm-bench