File size: 1,156 Bytes
ff9c858
 
3d07812
ff9c858
 
64f605f
ff9c858
64f605f
ff9c858
 
3d07812
ff9c858
 
 
 
 
 
64f605f
ff9c858
64f605f
ff9c858
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import torch

# Загрузка модели и токенизатора
model_id = "beyond/roberta-base-email-intent-classifier"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

# pipeline с device="cpu" (или "cuda:0" если есть GPU)
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)

# Пример: классификация писем
emails = [
    "Спасибо за ваше письмо. Давайте созвонимся в пятницу.",
    "К сожалению, мы не готовы сотрудничать в этом направлении.",
    "А подскажите, пожалуйста, как вы работаете с B2B и есть ли у вас кейсы в финансовой сфере?"
]

results = classifier(emails)

for email, res in zip(emails, results):
    print(f"Email: {email}\n→ Predicted intent: {res['label']} (confidence: {res['score']:.2f})\n")