Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import joblib
3import torch
4
5# Load model and tokenizer
6model_name = "sandyyuan/deberta-v3-xsmall-sequence-classification"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
10# For the label encoder, you'll need to download it separately
11# label_encoder = joblib.load("label_encoder.pkl")
12
13# Example inference
14text = "John Smith"
15inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=64)
16
17with torch.no_grad():
18 outputs = model(**inputs)
19 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
20 predicted_class_idx = torch.argmax(probabilities, dim=-1).item()
21 confidence = torch.max(probabilities).item()
22
23print(f"Predicted class index: {predicted_class_idx}")
24print(f"Confidence: {confidence:.3f}")@misc{deberta-sequence-classification-2025,
title={DeBERTa-v3-xsmall for Sequence Classification},
author={Sandy Yuan},
year={2025},
url={https://huggingface.co/sandyyuan/deberta-v3-xsmall-sequence-classification}
}