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
Download handler.py from omgkyng/email-intent-classifier: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/omgkyng/email-intent-classifier/resolve/main/handler.py
- Command line
-
hf download hf://omgkyng/email-intent-classifier/handler.py
-
curl -L -o handler.py https://huggingface.co/omgkyng/email-intent-classifier/resolve/main/handler.py
909 Bytes
| 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)} | |