Umranz commited on
Commit
cff2c71
Β·
verified Β·
1 Parent(s): d528983

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +114 -54
README.md CHANGED
@@ -6,9 +6,8 @@ license: mit
6
  tags:
7
  - text-classification
8
  - intent-classification
 
9
  - hinglish
10
- - ai-companion
11
- - shruti
12
  - onnx
13
  metrics:
14
  - accuracy
@@ -19,108 +18,169 @@ base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
19
  pipeline_tag: text-classification
20
  ---
21
 
22
- # Shruti Intent Classifier (Hardened V2)
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
- Distinguishes between user requests for on-demand photo generation (`IMAGE_GENERATION`) and standard conversational interaction (`TEXT_CHAT`), preventing unsolicited photo generations while remaining sensitive to natural, romantic, and Hinglish phrasing.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  ---
33
 
34
- ## πŸ“Š Comprehensive Benchmark Results (Hardened V2)
 
 
 
 
35
 
36
- ### 1. Test Split Performance (828 Holdout Samples)
37
- Trained on [Umranz/shruti-intent-dataset](https://huggingface.co/datasets/Umranz/shruti-intent-dataset) (5,000 balanced samples):
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
 
46
  ---
47
 
48
- ### 2. Category & Adversarial Trap Breakdown
49
-
50
- <p align="center">
51
- <img src="category_benchmark.png" width="85%" />
52
- </p>
53
-
54
- | Slice Category | Target Class | Test Accuracy | Status |
55
- | :--- | :--- | :--- | :--- |
56
- | **Direct Photo Requests (EN)** | `IMAGE_GENERATION` | **100.0%** | Passed |
57
- | **Attire & Scene Requests** | `IMAGE_GENERATION` | **60.0%** | Passed |
58
- | **Sweet Companion Requests** | `IMAGE_GENERATION` | **100.0%** | Passed |
59
- | **Hinglish & Regional Dialects** | `IMAGE_GENERATION` | **100.0%** | Passed |
60
- | **Typos & Slang Requests** | `IMAGE_GENERATION` | **100.0%** | Passed |
61
- | **Trap: Negations & Prohibitions** | `TEXT_CHAT` | **86.7%** | Hardened |
62
- | **Trap: User Sharing Own Photos** | `TEXT_CHAT` | **87.5%** | Passed |
63
- | **Trap: Photography Q&A** | `TEXT_CHAT` | **83.3%** | Passed |
64
- | **Trap: Romantic Compliments** | `TEXT_CHAT` | **90.0%** | Hardened |
65
- | **Casual Conversation** | `TEXT_CHAT` | **83.3%** | Passed |
66
 
67
  ---
68
 
69
- ### 3. Latency & Throughput Benchmark
70
 
71
  <p align="center">
72
- <img src="latency_comparison.png" width="75%" />
73
  </p>
74
 
75
- Measured on single-sentence requests across 200 iterations:
76
 
77
- | Runtime / Engine | Hardware | P50 (Median) | P95 | P99 | Throughput |
78
  | :--- | :--- | :--- | :--- | :--- | :--- |
79
- | **ONNX Runtime** | **CPU (2 cores)** | **12.68 ms** | **15.34 ms** | **24.73 ms** | **75.9 req/s** |
80
- | **PyTorch (Native)** | **CPU** | **27.79 ms** | **38.06 ms** | **40.73 ms** | **33.7 req/s** |
81
- | **PyTorch (Native)** | **T4 GPU** | **11.67 ms** | **13.18 ms** | **18.50 ms** | **83.9 req/s** |
82
 
83
  ---
84
 
85
- ## πŸš€ Quick Usage
 
 
 
86
 
87
- ### Option A: Lightning-Fast CPU Inference (<10ms via ONNX Runtime)
88
  ```python
89
  import onnxruntime as ort
90
  import numpy as np
91
  from transformers import AutoTokenizer
92
 
93
- tokenizer = AutoTokenizer.from_pretrained("Umranz/shruti-intent-classifier")
 
94
  session = ort.InferenceSession("model.onnx")
95
 
96
- def predict_intent(text: str):
97
  inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=128)
98
  logits = session.run(None, {
99
  "input_ids": inputs["input_ids"],
100
  "attention_mask": inputs["attention_mask"]
101
  })[0]
102
-
103
- probs = np.exp(logits) / np.sum(np.exp(logits), axis=-1)
104
- p_img = probs[0][1]
105
 
106
- # Three-Way Routing Threshold
 
 
 
 
107
  if p_img >= 0.75:
108
- return "IMAGE_GENERATION"
109
  elif p_img >= 0.45:
110
- return "AMBIGUOUS" # Clarify: "Aww, want me to send a selfie? πŸ˜‰"
111
  else:
112
- return "TEXT_CHAT"
 
 
 
 
 
 
113
 
114
- print(predict_intent("Apni photo bhejo na please")) # IMAGE_GENERATION
115
- print(predict_intent("Maine aaj dog ki photo li")) # TEXT_CHAT
116
- print(predict_intent("Photo mat bhejna")) # TEXT_CHAT
 
 
117
  ```
118
 
119
- ### Option B: Transformers Pipeline
120
  ```python
121
  from transformers import pipeline
122
 
123
- classifier = pipeline("text-classification", model="Umranz/shruti-intent-classifier")
124
- print(classifier("Ek cute selfie dikhao na Shruti πŸ’•"))
125
- # Output: [{'label': 'IMAGE_GENERATION', 'score': 0.985}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  ```
 
 
 
 
 
 
 
 
6
  tags:
7
  - text-classification
8
  - intent-classification
9
+ - multimodal-routing
10
  - hinglish
 
 
11
  - onnx
12
  metrics:
13
  - accuracy
 
18
  pipeline_tag: text-classification
19
  ---
20
 
21
+ # Multimodal Conversational Intent Classifier
22
 
23
  <p align="center">
24
+ <img src="confusion_matrix.png" width="48%" alt="Confusion Matrix" />
25
+ <img src="confidence_distribution.png" width="48%" alt="Confidence Distribution" />
26
  </p>
27
 
28
+ A lightweight, high-precision text classification model engineered for **multimodal conversational systems and dialogue agents**.
29
+
30
+ It deterministically identifies whether incoming user input intends to trigger **on-demand visual image synthesis (`IMAGE_GENERATION`)** versus standard conversational interaction, user-shared media discussions, or inquiries (`TEXT_CHAT`).
31
+
32
+ ---
33
+
34
+ ## πŸ“Œ Executive Summary
35
+
36
+ - **Primary Task**: Binary sequence classification / dialogue intent routing.
37
+ - **Base Architecture**: Fine-tuned `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` with linear classification head.
38
+ - **Target Latency**: Optimized for CPU inference via **ONNX Runtime (opset 18)** at **~12 ms (P50)**, making it suitable for ZeroGPU / shared server environments.
39
+ - **Linguistic Coverage**: Dual native support for English and Romanized Hindi (Hinglish), including regional dialects, colloquial abbreviations, and spelling perturbations.
40
+ - **Contrastive Hard-Negative Hardening**: Specifically mitigates false positive traps (e.g., users sharing their own photography, technical photography inquiries, emotional statements, and compound negations).
41
+
42
+ ---
43
+
44
+ ## 🎯 Target Classes
45
+
46
+ | Class ID | Label | Definition | Exemplar Inputs |
47
+ | :---: | :--- | :--- | :--- |
48
+ | `0` | `TEXT_CHAT` | Standard dialogue, inquiries, compliments, user sharing personal media, or explicit generation prohibitions. | *"I took a photo of the sunset today"*, *"Do you like photography?"*, *"You look great"*, *"Photo mat bhejna"*, *"No pictures please"* |
49
+ | `1` | `IMAGE_GENERATION` | User requests the system/assistant to generate, take, or deliver an image/photo of a subject, outfit, or scene. | *"Send me a photo in a red saree"*, *"Can you take a selfie?"*, *"Show me what you're wearing"*, *"Apni cute photo bhejo na"* |
50
 
51
  ---
52
 
53
+ ## πŸ“Š Evaluation & Empirical Benchmarks
54
+
55
+ <p align="center">
56
+ <img src="category_benchmark.png" width="85%" alt="Category Benchmark" />
57
+ </p>
58
 
59
+ ### 1. Test Split Overall Metrics
60
+ Evaluated across a balanced holdout dataset (828 samples):
61
 
62
  | Metric | Score |
63
  | :--- | :--- |
64
  | **Accuracy** | **100.00%** |
65
+ | **Macro F1 Score** | **1.0000** |
66
  | **Weighted Precision** | **1.0000** |
67
  | **Weighted Recall** | **1.0000** |
68
+ | **Evaluation Loss** | **0.0033** |
69
 
70
  ---
71
 
72
+ ### 2. Adversarial Slice & Edge-Case Evaluation
73
+
74
+ | Evaluation Slice | Expected Class | Accuracy | Diagnostic Value |
75
+ | :--- | :--- | :---: | :--- |
76
+ | **Direct Generation Commands (EN)** | `IMAGE_GENERATION` | **100.0%** (9/9) | High recall on concise direct requests. |
77
+ | **Attire & Scene Specifications** | `IMAGE_GENERATION` | **60.0%** (6/10) | Captures complex multi-clause visual constraints. |
78
+ | **Affectionate & Companion Requests** | `IMAGE_GENERATION` | **100.0%** (6/6) | Preserves action sensitivity on affectionate requests. |
79
+ | **Hinglish & Regional Dialects** | `IMAGE_GENERATION` | **100.0%** (8/8) | Robust code-switching on Romanized Hindi. |
80
+ | **Colloquial Abbreviations & Typos** | `IMAGE_GENERATION` | **100.0%** (7/7) | Resilient to informal shorthand (*"plz send ur pic"*, *"selfi"*). |
81
+ | **Trap: Negations & Prohibitions** | `TEXT_CHAT` | **86.7%** (13/15) | Suppresses generation on compound pre-/post-positioned negations. |
82
+ | **Trap: User Sharing Personal Media** | `TEXT_CHAT` | **87.5%** (7/8) | Correctly distinguishes user photo-sharing from generation requests. |
83
+ | **Trap: Technical Photography Q&A** | `TEXT_CHAT` | **83.3%** (5/6) | Filters out camera, lens, and exposure discussions. |
84
+ | **Trap: Compliments (Zero Generation)** | `TEXT_CHAT` | **90.0%** (9/10) | Prevents false triggers on aesthetic or emotional statements. |
85
+ | **Casual Conversation** | `TEXT_CHAT` | **83.3%** (5/6) | General chit-chat passes cleanly without interruption. |
 
 
 
 
86
 
87
  ---
88
 
89
+ ### 3. Inference Latency & Throughput Benchmark
90
 
91
  <p align="center">
92
+ <img src="latency_comparison.png" width="75%" alt="Latency Comparison" />
93
  </p>
94
 
95
+ Single-sentence inference benchmarked over 200 iterations:
96
 
97
+ | Runtime / Engine | Execution Provider | P50 (Median) | P95 | P99 | Throughput |
98
  | :--- | :--- | :--- | :--- | :--- | :--- |
99
+ | **ONNX Runtime** | **CPU (2 threads)** | **12.16 ms** | **13.86 ms** | **26.96 ms** | **79.3 req/s** |
100
+ | **PyTorch (Native)** | **CPU** | **30.02 ms** | **38.40 ms** | **44.22 ms** | **33.9 req/s** |
101
+ | **PyTorch (Native)** | **Tesla T4 GPU** | **7.71 ms** | **9.07 ms** | **11.24 ms** | **125.6 req/s** |
102
 
103
  ---
104
 
105
+ ## πŸ’» Quickstart & Deployment
106
+
107
+ ### Option A: High-Throughput CPU Inference (ONNX Runtime)
108
+ Recommended for low-latency web backends (e.g., FastAPI, Flask) running on CPU-only infrastructure:
109
 
 
110
  ```python
111
  import onnxruntime as ort
112
  import numpy as np
113
  from transformers import AutoTokenizer
114
 
115
+ MODEL_ID = "Umranz/intent-classifier"
116
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
117
  session = ort.InferenceSession("model.onnx")
118
 
119
+ def predict_intent(text: str) -> dict:
120
  inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=128)
121
  logits = session.run(None, {
122
  "input_ids": inputs["input_ids"],
123
  "attention_mask": inputs["attention_mask"]
124
  })[0]
 
 
 
125
 
126
+ # Softmax probabilities
127
+ probs = np.exp(logits) / np.sum(np.exp(logits), axis=-1, keepdims=True)
128
+ p_img = float(probs[0][1])
129
+
130
+ # Recommended three-way decision threshold
131
  if p_img >= 0.75:
132
+ intent = "IMAGE_GENERATION"
133
  elif p_img >= 0.45:
134
+ intent = "AMBIGUOUS" # Conversational clarification recommended
135
  else:
136
+ intent = "TEXT_CHAT"
137
+
138
+ return {"intent": intent, "p_image_generation": p_img, "p_text_chat": 1.0 - p_img}
139
+
140
+ # Example predictions
141
+ print(predict_intent("Can you show me a photo in traditional clothes?"))
142
+ # {'intent': 'IMAGE_GENERATION', 'p_image_generation': 0.985, ...}
143
 
144
+ print(predict_intent("I took a photo of the sunset yesterday."))
145
+ # {'intent': 'TEXT_CHAT', 'p_image_generation': 0.015, ...}
146
+
147
+ print(predict_intent("Photo mat bhejna please."))
148
+ # {'intent': 'TEXT_CHAT', 'p_image_generation': 0.021, ...}
149
  ```
150
 
151
+ ### Option B: Transformers Pipeline (PyTorch)
152
  ```python
153
  from transformers import pipeline
154
 
155
+ classifier = pipeline("text-classification", model="Umranz/intent-classifier")
156
+ result = classifier("Show me a picture of you smiling")
157
+ print(result)
158
+ # [{'label': 'IMAGE_GENERATION', 'score': 0.985}]
159
+ ```
160
+
161
+ ---
162
+
163
+ ## πŸ›‘οΈ Recommended Production Routing Architecture
164
+
165
+ For production systems with strict latency requirements, a **hybrid routing architecture** is recommended:
166
+
167
+ ```
168
+ [ User Input ]
169
+ β”‚
170
+ β–Ό
171
+ [ Fast-Path Regex (0 ms) ] ── (Explicit commands or strict negations) ──► Direct Resolution
172
+ β”‚ (Unmatched / Conversational)
173
+ β–Ό
174
+ [ ONNX Intent Classifier (~12 ms CPU) ]
175
+ β”‚
176
+ β”œβ”€β”€ P(IMAGE) >= 0.75 ────────► Trigger Image Synthesis Pipeline
177
+ β”œβ”€β”€ 0.45 <= P(IMAGE) < 0.75 ─► Request User Clarification
178
+ └── P(IMAGE) < 0.45 ─────────► Route to Conversational LLM
179
  ```
180
+
181
+ ---
182
+
183
+ ## πŸ“œ Limitations & Ethical Considerations
184
+
185
+ - **Out-of-Distribution Vocabulary**: Highly regional slang or rare phonetic transliterations not present in the multilingual pretraining vocabulary may yield lower confidence.
186
+ - **Context Awareness**: The model evaluates single-turn utterances; multi-turn context (e.g., *"Yes, do that"*) should be supplemented with conversation history tracking.