File size: 1,171 Bytes
0a3a74b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language:
- zh
tags:
- pytorch
- zh
- Conversational

---

[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.
Usage example:

NOTE: it should be used under similar data distribution.

```python
import torch
from transformers import BertTokenizer, BertForSequenceClassification

tokenizer = BertTokenizer.from_pretrained('thu-coai/roberta-zh-sensible')
model = BertForSequenceClassification.from_pretrained('thu-coai/roberta-zh-sensible', num_labels=2)
model.eva()

context = [
    "你大爱的冷门古诗词是什么?\t一枝红艳露凝香,云雨巫山枉断肠",
    "你大爱的冷门古诗词是什么?\t一枝红艳露凝香,云雨巫山枉断肠",
]

response = [
    "最爱春江花月夜",
    "我也很喜欢",
]

model_input = tokenizer(context, response, return_tensors='pt', padding=True)
with torch.no_grad():
    model_output = model(**model_input, return_dict=True)
logits = model_output.logits
preds_all = torch.argmax(logits, dim=-1).cpu()
print(preds_all) # 1 for sensible response else 0


```