Update README.md
Browse files
README.md
CHANGED
|
@@ -17,6 +17,42 @@ tags:
|
|
| 17 |
|
| 18 |
本模型支持三个类别:AI,zhihu,other. 它们分别表示AI生成的文本,知乎用户回答文本和其他文本。
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
## 训练数据
|
| 21 |
|
| 22 |
使用 `alpaca-data-gpt4-chinese` 中的约52000条回答文本作为AI生成文本,`Zhihu-KOL` 中随机选择的约52000条回答文本作为知乎用户回答文本,`SkyPile-150B` 中随机选择的约52000条文本作为其他文本。
|
|
|
|
| 17 |
|
| 18 |
本模型支持三个类别:AI,zhihu,other. 它们分别表示AI生成的文本,知乎用户回答文本和其他文本。
|
| 19 |
|
| 20 |
+
# 使用方式
|
| 21 |
+
通过 `transformers.pipeline` 预设的文本分类管线即可轻松使用:
|
| 22 |
+
```python
|
| 23 |
+
from transformers import pipeline
|
| 24 |
+
classifier = pipeline("text-classification",model="./checkpoints",device="cuda")
|
| 25 |
+
text = "加密通信助长犯罪的说法并不成立,理由如下:隐私权的基本保障:加密技术保障了个人和组织的隐私权,这是基本人权的一部分。无论是个人的日常通信、商业机密,还是新闻记者的来源保护,加密通信都在确保合法和正当的隐私需求不被侵犯。"
|
| 26 |
+
print(classifier(text))
|
| 27 |
+
```
|
| 28 |
+
输出结果为
|
| 29 |
+
```
|
| 30 |
+
[{'label': 'AI', 'score': 0.9951270818710327}]
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
使用模型本身进行推理的方法:
|
| 34 |
+
```python
|
| 35 |
+
import torch
|
| 36 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 37 |
+
|
| 38 |
+
tokenizer = AutoTokenizer.from_pretrained("hugfaceguy0001/AITextDetector")
|
| 39 |
+
model = AutoModelForSequenceClassification.from_pretrained("hugfaceguy0001/AITextDetector").to("cuda")
|
| 40 |
+
|
| 41 |
+
def detect_text(text):
|
| 42 |
+
with torch.no_grad():
|
| 43 |
+
inputs = tokenizer(text, return_tensors="pt").to("cuda")
|
| 44 |
+
logits = model(**inputs).logits
|
| 45 |
+
predicted_class_id = logits.argmax().item()
|
| 46 |
+
return model.config.id2label[predicted_class_id]
|
| 47 |
+
|
| 48 |
+
text = "黑神话这个游戏,你喷它优化、喷它地图、喷它空气墙、喷它战斗、喷它剧情;这些东西不管我自己觉得有没有喷一下的必要,可也都或多或少的能理解它为什么被喷的原因。"
|
| 49 |
+
print(detect_text(text))
|
| 50 |
+
```
|
| 51 |
+
输出结果为
|
| 52 |
+
```
|
| 53 |
+
zhihu
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
## 训练数据
|
| 57 |
|
| 58 |
使用 `alpaca-data-gpt4-chinese` 中的约52000条回答文本作为AI生成文本,`Zhihu-KOL` 中随机选择的约52000条回答文本作为知乎用户回答文本,`SkyPile-150B` 中随机选择的约52000条文本作为其他文本。
|