Edit model card

Den4ikAI/ruBert-tiny-questions-classifier

Модель классифицирует вопрос на два класса:

  1. Точный вопрос (exact_question) - вопрос требующий четкого, фактологичного ответа.
  2. Неточный вопрос (innacurate_question) - вопрос допускающий рассуждения, философские вопросы.

Использование

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('что такое цианид'))

Citation

@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
}
Downloads last month
20
Inference Examples
This model does not have enough activity to be deployed to Inference API (serverless) yet. Increase its social visibility and check back later, or deploy to Inference Endpoints (dedicated) instead.