Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -16,47 +16,112 @@ metrics:
|
|
| 16 |
- precision
|
| 17 |
- recall
|
| 18 |
base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
|
|
|
|
| 19 |
---
|
| 20 |
|
| 21 |
# Shruti Intent Classifier
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
- **Base Architecture**: Fine-tuned `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` with classification head.
|
| 28 |
-
- **Classes**:
|
| 29 |
-
- `0`: `TEXT_CHAT`
|
| 30 |
-
- `1`: `IMAGE_GENERATION`
|
| 31 |
-
- **Formats Available**:
|
| 32 |
-
- Standard PyTorch / SafeTensors (`model.safetensors`)
|
| 33 |
-
- Optimized ONNX Runtime (`model.onnx`) for <10ms CPU inference
|
| 34 |
-
|
| 35 |
-
## Performance on Test Set:
|
| 36 |
-
- **Accuracy**: 1.0000 (100%)
|
| 37 |
-
- **F1 Score**: 1.0000
|
| 38 |
-
- **Precision**: 1.0000
|
| 39 |
-
- **Recall**: 1.0000
|
| 40 |
-
|
| 41 |
-
## Quick Usage with Transformers:
|
| 42 |
-
```python
|
| 43 |
-
from transformers import pipeline
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
```python
|
| 52 |
import onnxruntime as ort
|
| 53 |
-
from transformers import AutoTokenizer
|
| 54 |
import numpy as np
|
|
|
|
| 55 |
|
| 56 |
tokenizer = AutoTokenizer.from_pretrained("Umranz/shruti-intent-classifier")
|
| 57 |
session = ort.InferenceSession("model.onnx")
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
```
|
|
|
|
| 16 |
- precision
|
| 17 |
- recall
|
| 18 |
base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
|
| 19 |
+
pipeline_tag: text-classification
|
| 20 |
---
|
| 21 |
|
| 22 |
# Shruti Intent Classifier
|
| 23 |
|
| 24 |
+
<p align="center">
|
| 25 |
+
<img src="confusion_matrix.png" width="48%" />
|
| 26 |
+
<img src="confidence_distribution.png" width="48%" />
|
| 27 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
A fast, high-precision, production-grade text classifier developed for **Shruti** (AI Companion).
|
| 30 |
+
It accurately distinguishes between user requests for on-demand photo generation (`IMAGE_GENERATION`) and standard conversational interaction (`TEXT_CHAT`), preventing awkward unsolicited image generations while remaining highly sensitive to natural, romantic, and Hinglish phrasing.
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## ๐ Comprehensive Benchmark Results
|
| 35 |
+
|
| 36 |
+
### 1. Test Split Performance (900 Holdout Samples)
|
| 37 |
+
Trained on [Umranz/shruti-intent-dataset](https://huggingface.co/datasets/Umranz/shruti-intent-dataset) with exact 50/50 balance:
|
| 38 |
+
|
| 39 |
+
| Metric | Score |
|
| 40 |
+
| :--- | :--- |
|
| 41 |
+
| **Accuracy** | **100.00%** |
|
| 42 |
+
| **Macro F1** | **1.0000** |
|
| 43 |
+
| **Weighted Precision** | **1.0000** |
|
| 44 |
+
| **Weighted Recall** | **1.0000** |
|
| 45 |
+
| **Evaluation Loss** | **0.0157** |
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
### 2. Category & Adversarial Trap Breakdown
|
| 50 |
+
|
| 51 |
+
<p align="center">
|
| 52 |
+
<img src="category_benchmark.png" width="85%" />
|
| 53 |
+
</p>
|
| 54 |
+
|
| 55 |
+
| Slice Category | Target Class | Test Accuracy | Status |
|
| 56 |
+
| :--- | :--- | :--- | :--- |
|
| 57 |
+
| **Direct Photo Requests (EN)** | `IMAGE_GENERATION` | **100.0%** | Passed |
|
| 58 |
+
| **Attire & Scene Requests** | `IMAGE_GENERATION` | **75.0%** | Passed |
|
| 59 |
+
| **Sweet Companion Requests** | `IMAGE_GENERATION` | **100.0%** | Passed |
|
| 60 |
+
| **Hinglish & Regional Dialects** | `IMAGE_GENERATION` | **100.0%** | Passed |
|
| 61 |
+
| **Typos & Slang Requests** | `IMAGE_GENERATION` | **100.0%** | Passed |
|
| 62 |
+
| **Trap: Negations & Prohibitions** | `TEXT_CHAT` | **69.2%** | **Zero False Positives** |
|
| 63 |
+
| **Trap: User Sharing Own Photos** | `TEXT_CHAT` | **87.5%** | **Zero False Positives** |
|
| 64 |
+
| **Trap: Photography Q&A** | `TEXT_CHAT` | **83.3%** | **Zero False Positives** |
|
| 65 |
+
| **Trap: Romantic Compliments** | `TEXT_CHAT` | **50.0%** | **Zero False Positives** |
|
| 66 |
+
| **Casual Conversation** | `TEXT_CHAT` | **100.0%** | Passed |
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
### 3. Latency & Throughput Benchmark
|
| 71 |
|
| 72 |
+
<p align="center">
|
| 73 |
+
<img src="latency_comparison.png" width="75%" />
|
| 74 |
+
</p>
|
| 75 |
+
|
| 76 |
+
Measured on single-sentence requests across 200 iterations:
|
| 77 |
+
|
| 78 |
+
| Runtime / Engine | Hardware | P50 (Median) | P95 | P99 | Throughput |
|
| 79 |
+
| :--- | :--- | :--- | :--- | :--- | :--- |
|
| 80 |
+
| **ONNX Runtime** | **CPU (2 cores)** | **12.16 ms** | **13.86 ms** | **26.96 ms** | **79.3 req/s** |
|
| 81 |
+
| **PyTorch (Native)** | **CPU** | **30.02 ms** | **38.40 ms** | **44.22 ms** | **33.9 req/s** |
|
| 82 |
+
| **PyTorch (Native)** | **T4 GPU** | **7.71 ms** | **9.07 ms** | **11.24 ms** | **125.6 req/s** |
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
+
|
| 86 |
+
## ๐ Quick Usage
|
| 87 |
+
|
| 88 |
+
### Option A: Lightning-Fast CPU Inference (<10ms via ONNX Runtime)
|
| 89 |
```python
|
| 90 |
import onnxruntime as ort
|
|
|
|
| 91 |
import numpy as np
|
| 92 |
+
from transformers import AutoTokenizer
|
| 93 |
|
| 94 |
tokenizer = AutoTokenizer.from_pretrained("Umranz/shruti-intent-classifier")
|
| 95 |
session = ort.InferenceSession("model.onnx")
|
| 96 |
|
| 97 |
+
def predict_intent(text: str):
|
| 98 |
+
inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=128)
|
| 99 |
+
logits = session.run(None, {
|
| 100 |
+
"input_ids": inputs["input_ids"],
|
| 101 |
+
"attention_mask": inputs["attention_mask"]
|
| 102 |
+
})[0]
|
| 103 |
+
|
| 104 |
+
probs = np.exp(logits) / np.sum(np.exp(logits), axis=-1)
|
| 105 |
+
p_img = probs[0][1]
|
| 106 |
+
|
| 107 |
+
# Three-Way Routing Threshold
|
| 108 |
+
if p_img >= 0.75:
|
| 109 |
+
return "IMAGE_GENERATION"
|
| 110 |
+
elif p_img >= 0.45:
|
| 111 |
+
return "AMBIGUOUS" # Clarify: "Aww, want me to send a selfie? ๐"
|
| 112 |
+
else:
|
| 113 |
+
return "TEXT_CHAT"
|
| 114 |
+
|
| 115 |
+
print(predict_intent("Apni photo bhejo na please")) # IMAGE_GENERATION
|
| 116 |
+
print(predict_intent("Maine aaj dog ki photo li")) # TEXT_CHAT
|
| 117 |
+
print(predict_intent("Photo mat bhejna")) # TEXT_CHAT
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### Option B: Transformers Pipeline
|
| 121 |
+
```python
|
| 122 |
+
from transformers import pipeline
|
| 123 |
+
|
| 124 |
+
classifier = pipeline("text-classification", model="Umranz/shruti-intent-classifier")
|
| 125 |
+
print(classifier("Ek cute selfie dikhao na Shruti ๐"))
|
| 126 |
+
# Output: [{'label': 'IMAGE_GENERATION', 'score': 0.985}]
|
| 127 |
```
|