Downloads · 30 days
12
1% of all-time downloads
Den4ikAI/ruBert-tiny-questions-classifier
ruBert-tiny-questions-classifier is a text classification model from Den4ikAI. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
Модель классифицирует вопрос на два класса:
Downloads · 30 days
12
1% of all-time downloads
All-time downloads
1.4K
Public
Repo size
234 MB
Likes
3
Public
Click a slice to open those files.
.bin117 MB · 97%
From the Hugging Face model README
Модель классифицирует вопрос на два класса:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
class RuBertQuestionClassifier:
def __init__(self):
self.device = torch.device("cpu")
self.tokenizer = AutoTokenizer.from_pretrained("Den4ikAI/ruBert-tiny-questions-classifier")
self.model = AutoModelForSequenceClassification.from_pretrained("Den4ikAI/ruBert-tiny-questions-classifier").to(
self.device).eval()
self.classes = ['exact_question', 'inaccurate_question']
def get_question_type(self, text):
text = text.lower().replace(',', '').replace('?', '')
inputs = self.tokenizer(text, max_length=512, add_special_tokens=False, truncation=True,
return_tensors='pt').to(self.device)
with torch.no_grad():
logits = self.model(**inputs).logits
probas = list(torch.sigmoid(logits)[0].cpu().detach().numpy())
out = self.classes[probas.index(max(probas))]
self.logger.debug('Mode: {}'.format(out))
return out
classifier = RuBertQuestionClassifier()
print(classifier.get_question_type('когда я найду своего принца'))
print(classifier.get_question_type('что такое цианид'))
@MISC{Den4ikAI/ruBert-tiny-questions-classifier,
author = {Denis Petrov},
title = {Russian question type classifier model},
url = {https://huggingface.co/Den4ikAI/ruBert-tiny-questions-classifier},
year = 2023
}