Commit ·
42176fd
1
Parent(s): 0afed17
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[hfl/chinese-roberta-wwm-ext](https://huggingface.co/hfl/chinese-roberta-wwm-ext) fine-tuned on the [CDConv dataset](https://github.com/thu-coai/cdconv). It supports 2-class classification for 2-turn dialogue contradiction detection. Usage example:
|
| 2 |
+
|
| 3 |
+
```python
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoTokenizer
|
| 6 |
+
from transformers.models.bert.modeling_bert import BertForSequenceClassification
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained('chujiezheng/roberta-base-cdconv')
|
| 9 |
+
model = BertForSequenceClassification.from_pretrained('chujiezheng/roberta-base-cdconv')
|
| 10 |
+
model.eval()
|
| 11 |
+
|
| 12 |
+
turn1 = [
|
| 13 |
+
"嗯嗯,你喜欢钓鱼吗?", # user
|
| 14 |
+
"喜欢啊,钓鱼很好玩的", # bot
|
| 15 |
+
]
|
| 16 |
+
turn2 = [
|
| 17 |
+
"你喜欢钓鱼吗?", # user
|
| 18 |
+
"不喜欢,我喜欢看别人钓鱼", # bot, we want to identify whether this utterance makes a contradiction
|
| 19 |
+
] # turn1 and turn2 are not required to be two consecutive turns
|
| 20 |
+
text1 = "[SEP]".join(turn1 + turn2[:1])
|
| 21 |
+
text2 = turn2[1]
|
| 22 |
+
|
| 23 |
+
model_input = tokenizer(text1, text2, return_tensors='pt', return_token_type_ids=True, return_attention_mask=True)
|
| 24 |
+
model_output = model(**model_input, return_dict=False)
|
| 25 |
+
prediction = torch.argmax(model_output[0].cpu(), dim=-1)[0].item()
|
| 26 |
+
print(prediction) # 0 for non-contradiction, 1 for contradiction
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
This fine-tuned model obtains 75.7 accuracy and 72.3 macro-F1 on the test set.
|
| 30 |
+
|
| 31 |
+
Please kindly cite the [original paper](https://arxiv.org/abs/2210.08511) if you use this model.
|
| 32 |
+
|
| 33 |
+
```bib
|
| 34 |
+
@inproceedings{zheng-etal-2022-cdconv,
|
| 35 |
+
title={Towards Emotional Support Dialog Systems},
|
| 36 |
+
author={Zheng, Chujie and
|
| 37 |
+
Zhou, Jinfeng and
|
| 38 |
+
Zheng, Yinhe and
|
| 39 |
+
Peng, Libiao and
|
| 40 |
+
Guo, Zhen and
|
| 41 |
+
Wu, Wenquan and
|
| 42 |
+
Niu, Zhengyu and
|
| 43 |
+
Wu, Hua and
|
| 44 |
+
Huang, Minlie},
|
| 45 |
+
booktitle={Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing},
|
| 46 |
+
year={2022}
|
| 47 |
+
}
|
| 48 |
+
```
|