everk commited on
Commit
71df253
1 Parent(s): 1c9b36b

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ tags:
5
+ - pytorch
6
+ - zh
7
+ - Conversational
8
+
9
+ ---
10
+
11
+ [roberta-zh](https://github.com/brightmart/roberta_zh) fine-tuned on human-annotated conversational model self-chat data. It supports 2-class calssification for multi-turn dialogue sensible detection.
12
+ Usage example:
13
+
14
+ NOTE: it should be used under similar data distribution.
15
+
16
+ ```python
17
+ import torch
18
+ from transformers import BertTokenizer, BertForSequenceClassification
19
+
20
+ tokenizer = BertTokenizer.from_pretrained('thu-coai/roberta-zh-specific')
21
+ model = BertForSequenceClassification.from_pretrained('thu-coai/roberta-zh-specific', num_labels=2)
22
+ model.eva()
23
+
24
+ context = [
25
+ "你大爱的冷门古诗词是什么?\t一枝红艳露凝香,云雨巫山枉断肠",
26
+ "你大爱的冷门古诗词是什么?\t一枝红艳露凝香,云雨巫山枉断肠",
27
+ ]
28
+
29
+ response = [
30
+ "我也很喜欢,我觉得这句的意境很美",
31
+ "我也很喜欢",
32
+ ]
33
+
34
+ model_input = tokenizer(context, response, return_tensors='pt', padding=True)
35
+ with torch.no_grad():
36
+ model_output = model(**model_input, return_dict=True)
37
+ logits = model_output.logits
38
+ preds_all = torch.argmax(logits, dim=-1).cpu()
39
+ print(preds_all) # 1 for specific response else 0
40
+
41
+
42
+ ```