File size: 591 Bytes
2f3b04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import pipeline
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline

device = "cuda:0" if torch.cuda.is_available() else "cpu"

model_name = 'qanastek/XLMRoberta-Alexa-Intents-Classification'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
intent_classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer)


def perform_intent_classification(text):
    result = intent_classifier(text)
    return {"Intent": [result]}