--- language: - en - hi license: mit tags: - text-classification - intent-classification - multimodal-routing - hinglish - onnx metrics: - accuracy - f1 - precision - recall base_model: sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 pipeline_tag: text-classification --- # Multimodal Conversational Intent Classifier

Confusion Matrix Confidence Distribution

A lightweight, high-precision text classification model engineered for **multimodal conversational systems and dialogue agents**. 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`). --- ## 📌 Executive Summary - **Primary Task**: Binary sequence classification / dialogue intent routing. - **Base Architecture**: Fine-tuned `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` with linear classification head. - **Target Latency**: Optimized for CPU inference via **ONNX Runtime (opset 18)** at **~12 ms (P50)**, making it suitable for ZeroGPU / shared server environments. - **Linguistic Coverage**: Dual native support for English and Romanized Hindi (Hinglish), including regional dialects, colloquial abbreviations, and spelling perturbations. - **Contrastive Hard-Negative Hardening**: Specifically mitigates false positive traps (e.g., users sharing their own photography, technical photography inquiries, emotional statements, and compound negations). --- ## 🎯 Target Classes | Class ID | Label | Definition | Exemplar Inputs | | :---: | :--- | :--- | :--- | | `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"* | | `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"* | --- ## 📊 Evaluation & Empirical Benchmarks

Category Benchmark

### 1. Test Split Overall Metrics Evaluated across a balanced holdout dataset (828 samples): | Metric | Score | | :--- | :--- | | **Accuracy** | **100.00%** | | **Macro F1 Score** | **1.0000** | | **Weighted Precision** | **1.0000** | | **Weighted Recall** | **1.0000** | | **Evaluation Loss** | **0.0033** | --- ### 2. Adversarial Slice & Edge-Case Evaluation | Evaluation Slice | Expected Class | Accuracy | Diagnostic Value | | :--- | :--- | :---: | :--- | | **Direct Generation Commands (EN)** | `IMAGE_GENERATION` | **100.0%** (9/9) | High recall on concise direct requests. | | **Attire & Scene Specifications** | `IMAGE_GENERATION` | **60.0%** (6/10) | Captures complex multi-clause visual constraints. | | **Affectionate & Companion Requests** | `IMAGE_GENERATION` | **100.0%** (6/6) | Preserves action sensitivity on affectionate requests. | | **Hinglish & Regional Dialects** | `IMAGE_GENERATION` | **100.0%** (8/8) | Robust code-switching on Romanized Hindi. | | **Colloquial Abbreviations & Typos** | `IMAGE_GENERATION` | **100.0%** (7/7) | Resilient to informal shorthand (*"plz send ur pic"*, *"selfi"*). | | **Trap: Negations & Prohibitions** | `TEXT_CHAT` | **86.7%** (13/15) | Suppresses generation on compound pre-/post-positioned negations. | | **Trap: User Sharing Personal Media** | `TEXT_CHAT` | **87.5%** (7/8) | Correctly distinguishes user photo-sharing from generation requests. | | **Trap: Technical Photography Q&A** | `TEXT_CHAT` | **83.3%** (5/6) | Filters out camera, lens, and exposure discussions. | | **Trap: Compliments (Zero Generation)** | `TEXT_CHAT` | **90.0%** (9/10) | Prevents false triggers on aesthetic or emotional statements. | | **Casual Conversation** | `TEXT_CHAT` | **83.3%** (5/6) | General chit-chat passes cleanly without interruption. | --- ### 3. Inference Latency & Throughput Benchmark

Latency Comparison

Single-sentence inference benchmarked over 200 iterations: | Runtime / Engine | Execution Provider | P50 (Median) | P95 | P99 | Throughput | | :--- | :--- | :--- | :--- | :--- | :--- | | **ONNX Runtime** | **CPU (2 threads)** | **12.16 ms** | **13.86 ms** | **26.96 ms** | **79.3 req/s** | | **PyTorch (Native)** | **CPU** | **30.02 ms** | **38.40 ms** | **44.22 ms** | **33.9 req/s** | | **PyTorch (Native)** | **Tesla T4 GPU** | **7.71 ms** | **9.07 ms** | **11.24 ms** | **125.6 req/s** | --- ## 💻 Quickstart & Deployment ### Option A: High-Throughput CPU Inference (ONNX Runtime) Recommended for low-latency web backends (e.g., FastAPI, Flask) running on CPU-only infrastructure: ```python import onnxruntime as ort import numpy as np from transformers import AutoTokenizer MODEL_ID = "Umranz/intent-classifier" tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) session = ort.InferenceSession("model.onnx") def predict_intent(text: str) -> dict: inputs = tokenizer(text, return_tensors="np", truncation=True, max_length=128) logits = session.run(None, { "input_ids": inputs["input_ids"], "attention_mask": inputs["attention_mask"] })[0] # Softmax probabilities probs = np.exp(logits) / np.sum(np.exp(logits), axis=-1, keepdims=True) p_img = float(probs[0][1]) # Recommended three-way decision threshold if p_img >= 0.75: intent = "IMAGE_GENERATION" elif p_img >= 0.45: intent = "AMBIGUOUS" # Conversational clarification recommended else: intent = "TEXT_CHAT" return {"intent": intent, "p_image_generation": p_img, "p_text_chat": 1.0 - p_img} # Example predictions print(predict_intent("Can you show me a photo in traditional clothes?")) # {'intent': 'IMAGE_GENERATION', 'p_image_generation': 0.985, ...} print(predict_intent("I took a photo of the sunset yesterday.")) # {'intent': 'TEXT_CHAT', 'p_image_generation': 0.015, ...} print(predict_intent("Photo mat bhejna please.")) # {'intent': 'TEXT_CHAT', 'p_image_generation': 0.021, ...} ``` ### Option B: Transformers Pipeline (PyTorch) ```python from transformers import pipeline classifier = pipeline("text-classification", model="Umranz/intent-classifier") result = classifier("Show me a picture of you smiling") print(result) # [{'label': 'IMAGE_GENERATION', 'score': 0.985}] ``` --- ## 🛡️ Recommended Production Routing Architecture For production systems with strict latency requirements, a **hybrid routing architecture** is recommended: ``` [ User Input ] │ ▼ [ Fast-Path Regex (0 ms) ] ── (Explicit commands or strict negations) ──► Direct Resolution │ (Unmatched / Conversational) ▼ [ ONNX Intent Classifier (~12 ms CPU) ] │ ├── P(IMAGE) >= 0.75 ────────► Trigger Image Synthesis Pipeline ├── 0.45 <= P(IMAGE) < 0.75 ─► Request User Clarification └── P(IMAGE) < 0.45 ─────────► Route to Conversational LLM ``` --- ## 📜 Limitations & Ethical Considerations - **Out-of-Distribution Vocabulary**: Highly regional slang or rare phonetic transliterations not present in the multilingual pretraining vocabulary may yield lower confidence. - **Context Awareness**: The model evaluates single-turn utterances; multi-turn context (e.g., *"Yes, do that"*) should be supplemented with conversation history tracking.