add example usage of model
Browse files
README.md
CHANGED
|
@@ -177,6 +177,61 @@ Hardware: GPU (CUDA)
|
|
| 177 |
|
| 178 |
---
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
## 8. Strengths
|
| 181 |
|
| 182 |
* Strong multilingual generalization
|
|
|
|
| 177 |
|
| 178 |
---
|
| 179 |
|
| 180 |
+
# Example Usage
|
| 181 |
+
|
| 182 |
+
```python
|
| 183 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 184 |
+
import torch
|
| 185 |
+
|
| 186 |
+
# Load model and tokenizer
|
| 187 |
+
model_name = "learn-abc/banking-multilingual-intent-classifier"
|
| 188 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 189 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 190 |
+
|
| 191 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 192 |
+
model.to(device)
|
| 193 |
+
model.eval()
|
| 194 |
+
|
| 195 |
+
# Prediction function
|
| 196 |
+
def predict_intent(text):
|
| 197 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=64)
|
| 198 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 199 |
+
|
| 200 |
+
with torch.no_grad():
|
| 201 |
+
outputs = model(**inputs)
|
| 202 |
+
prediction = torch.argmax(outputs.logits, dim=-1).item()
|
| 203 |
+
confidence = torch.softmax(outputs.logits, dim=-1)[0][prediction].item()
|
| 204 |
+
|
| 205 |
+
predicted_intent = model.config.id2label[prediction]
|
| 206 |
+
|
| 207 |
+
return {
|
| 208 |
+
"intent": predicted_intent,
|
| 209 |
+
"confidence": confidence
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
# Example usage - English
|
| 213 |
+
result = predict_intent("what is my balance")
|
| 214 |
+
print(f"Intent: {result['intent']}, Confidence: {result['confidence']:.2f}")
|
| 215 |
+
# Output: Intent: CHECK_BALANCE, Confidence: 0.99
|
| 216 |
+
|
| 217 |
+
# Example usage - Bangla
|
| 218 |
+
result = predict_intent("আমার ব্যালেন্স কত")
|
| 219 |
+
print(f"Intent: {result['intent']}, Confidence: {result['confidence']:.2f}")
|
| 220 |
+
# Output: Intent: CHECK_BALANCE, Confidence: 0.98
|
| 221 |
+
|
| 222 |
+
# Example usage - Banglish (Romanized)
|
| 223 |
+
result = predict_intent("amar balance koto ache")
|
| 224 |
+
print(f"Intent: {result['intent']}, Confidence: {result['confidence']:.2f}")
|
| 225 |
+
# Output: Intent: CHECK_BALANCE, Confidence: 0.97
|
| 226 |
+
|
| 227 |
+
# Example usage - Code-mixed
|
| 228 |
+
result = predict_intent("আমার last 10 transaction দেখাও")
|
| 229 |
+
print(f"Intent: {result['intent']}, Confidence: {result['confidence']:.2f}")
|
| 230 |
+
# Output: Intent: MINI_STATEMENT, Confidence: 0.98
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
---
|
| 234 |
+
|
| 235 |
## 8. Strengths
|
| 236 |
|
| 237 |
* Strong multilingual generalization
|