Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- ru
|
| 5 |
+
pipeline_tag: text-classification
|
| 6 |
+
widget:
|
| 7 |
+
- text: 'что такое QR-код'
|
| 8 |
+
- text: 'когда деньги придут за мной'
|
| 9 |
+
- text: 'почему девушки мне не дают'
|
| 10 |
---
|
| 11 |
+
# Den4ikAI/ruBert-tiny-questions-classifier
|
| 12 |
+
Модель классифицирует вопрос на два класса:
|
| 13 |
+
|
| 14 |
+
1. Точный вопрос (exact_question) - вопрос требующий четкого, фактологичного ответа.
|
| 15 |
+
2. Неточный вопрос (innacurate_question) - вопрос допускающий рассуждения, философские вопросы.
|
| 16 |
+
|
| 17 |
+
# Использование
|
| 18 |
+
```python
|
| 19 |
+
import torch
|
| 20 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class RuBertQuestionClassifier:
|
| 25 |
+
def __init__(self):
|
| 26 |
+
self.device = torch.device("cpu")
|
| 27 |
+
self.tokenizer = AutoTokenizer.from_pretrained("Den4ikAI/ruBert-tiny-questions-classifier")
|
| 28 |
+
self.model = AutoModelForSequenceClassification.from_pretrained("Den4ikAI/ruBert-tiny-questions-classifier").to(
|
| 29 |
+
self.device).eval()
|
| 30 |
+
self.classes = ['exact_question', 'inaccurate_question']
|
| 31 |
+
|
| 32 |
+
def get_question_type(self, text):
|
| 33 |
+
text = text.lower().replace(',', '').replace('?', '')
|
| 34 |
+
inputs = self.tokenizer(text, max_length=512, add_special_tokens=False, truncation=True,
|
| 35 |
+
return_tensors='pt').to(self.device)
|
| 36 |
+
with torch.no_grad():
|
| 37 |
+
logits = self.model(**inputs).logits
|
| 38 |
+
probas = list(torch.sigmoid(logits)[0].cpu().detach().numpy())
|
| 39 |
+
out = self.classes[probas.index(max(probas))]
|
| 40 |
+
self.logger.debug('Mode: {}'.format(out))
|
| 41 |
+
return out
|
| 42 |
+
classifier = RuBertQuestionClassifier()
|
| 43 |
+
print(classifier.get_question_type('когда я найду своего принца'))
|
| 44 |
+
print(classifier.get_question_type('что такое цианид'))
|
| 45 |
+
```
|
| 46 |
+
# Citation
|
| 47 |
+
```
|
| 48 |
+
@MISC{Den4ikAI/ruBert-tiny-questions-classifier,
|
| 49 |
+
author = {Denis Petrov},
|
| 50 |
+
title = {Russian question type classifier model},
|
| 51 |
+
url = {https://huggingface.co/Den4ikAI/ruBert-tiny-questions-classifier},
|
| 52 |
+
year = 2023
|
| 53 |
+
}
|
| 54 |
+
```
|