1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4MODEL_ID = "AnxForever/chinese-ai-detector-bert"
5TEMPERATURE = 0.8165 # Temperature scaling, calibrated on 910 samples (ECE=0.0034)
6
7tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
9model.eval()
10
11text = "这是一段需要检测的中文文本。"
12inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
13
14with torch.no_grad():
15 logits = model(**inputs).logits
16 # Apply temperature scaling for calibrated confidence
17 probs = torch.softmax(logits / TEMPERATURE, dim=-1)[0]
18
19pred_idx = int(probs.argmax())
20label = model.config.id2label[pred_idx] # "human-written" or "AI-generated"
21print(f"{label} (confidence: {probs[pred_idx].item():.2%})")
-
Data-centric risk governance
The v11c model keeps the BERT backbone fixed and improves robustness through data cleaning, weak-domain supplementation, long-AI supplementation, and calibrated inference.
-
[SEP] boundary-marker experiment
In constructed C2-style mixed samples, [SEP] was used as an explicit boundary hint between known human and AI segments. This is an engineering experiment for mixed-text modeling, not a claim that [SEP] itself can identify authorship without labels.
-
Two-stage experimental extension
- Stage 1: this model — document-level Human / AI classification
- Stage 2: separate span detector — token-level Human / AI tagging on mixed-text samples
- See
AnxForever/chinese-ai-detector-span
-
Long-AI boundary-fix (v11c)
针对长 AI 段落在边界处易被误判的问题,补充 2,131 条长 AI 边界样本,使 256+ token 桶的准确率恢复到 V10 水平。
The boundary module was trained on a relatively small constructed mixed-text set. It is useful for demonstration, teaching, and secondary development, but it should be treated as an experimental prototype. For real business scenarios, mixed human/AI data from the target domain should be collected, labeled, retrained, and evaluated before deployment.
1@misc{anxforever2026chineseaidetectorbert,
2 title = {Chinese AI-Generated Text Detector with Boundary Markers (BERT v11c)},
3 author = {AnxForever},
4 year = {2026},
5 howpublished = {\url{https://huggingface.co/AnxForever/chinese-ai-detector-bert}},
6 note = {Undergraduate thesis project}
7}