Instructions to use omgkyng/email-intent-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use omgkyng/email-intent-classifier with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("omgkyng/email-intent-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 909 Bytes
f019ce5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from typing import Dict
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
class EndpointHandler:
def __init__(self, path=""):
self.tokenizer = AutoTokenizer.from_pretrained(path)
self.model = AutoModelForSequenceClassification.from_pretrained(path)
self.model.eval()
self.id2label = {0: "create", 1: "edit", 2: "query"}
def __call__(self, data: Dict[str, str]) -> Dict[str, str]:
text = data.get("inputs", "")
inputs = self.tokenizer(text, return_tensors="pt")
with torch.no_grad():
outputs = self.model(**inputs)
probs = torch.nn.functional.softmax(outputs.logits, dim=1)
pred = torch.argmax(probs, dim=1).item()
label = self.id2label[pred]
confidence = probs[0][pred].item()
return {"label": label, "confidence": round(confidence, 3)}
|