Text Classification
Safetensors
Chinese
gpt2
Edit model card

AI文本检测器

本模型是gpt2的微调模型,用于文本分类。

本模型支持三个类别:AI,zhihu,other. 它们分别表示AI生成的文本,知乎用户回答文本和其他文本。

使用方式

通过 transformers.pipeline 预设的文本分类管线即可轻松使用:

from transformers import pipeline
classifier = pipeline("text-classification",model="./checkpoints",device="cuda")
text = "加密通信助长犯罪的说法并不成立,理由如下:隐私权的基本保障:加密技术保障了个人和组织的隐私权,这是基本人权的一部分。无论是个人的日常通信、商业机密,还是新闻记者的来源保护,加密通信都在确保合法和正当的隐私需求不被侵犯。"
print(classifier(text))

输出结果为

[{'label': 'AI', 'score': 0.9951270818710327}]

使用模型本身进行推理的方法:

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("hugfaceguy0001/AITextDetector")
model = AutoModelForSequenceClassification.from_pretrained("hugfaceguy0001/AITextDetector").to("cuda")

def detect_text(text):
    with torch.no_grad():
        inputs = tokenizer(text, return_tensors="pt").to("cuda")
        logits = model(**inputs).logits
        predicted_class_id = logits.argmax().item()
    return model.config.id2label[predicted_class_id]

text = "黑神话这个游戏,你喷它优化、喷它地图、喷它空气墙、喷它战斗、喷它剧情;这些东西不管我自己觉得有没有喷一下的必要,可也都或多或少的能理解它为什么被喷的原因。"
print(detect_text(text))

输出结果为

zhihu

训练数据

使用 alpaca-data-gpt4-chinese 中的约52000条回答文本作为AI生成文本,Zhihu-KOL 中随机选择的约52000条回答文本作为知乎用户回答文本,SkyPile-150B 中随机选择的约52000条文本作为其他文本。

共约15.6万条分类文本,组成数据集,其中80%用于训练,20%用于测试。

在测试集上的性能

分类准确率 accuracy = 0.9802627363024672.

各样本真实标签和检测结果组成的混淆矩阵为

AI zhihu other
AI 10325 326 18
zhihu 143 9969 87
other 0 42 10300
Downloads last month
28
Safetensors
Model size
124M params
Tensor type
F32
·
Inference Examples
Inference API (serverless) is not available, repository is disabled.

Model tree for hugfaceguy0001/AITextDetector

Finetuned
this model

Datasets used to train hugfaceguy0001/AITextDetector

Space using hugfaceguy0001/AITextDetector 1