Text Classification
Transformers
ONNX
Safetensors
English
Hindi
distilbert
int8
query-classification
generic-semantic
multilingual
Eval Results (legacy)
Instructions to use addyo07/distilbert-query-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use addyo07/distilbert-query-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="addyo07/distilbert-query-classifier")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("addyo07/distilbert-query-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- hi
|
| 5 |
+
license: mit
|
| 6 |
+
library_name: transformers
|
| 7 |
+
tags:
|
| 8 |
+
- distilbert
|
| 9 |
+
- onnx
|
| 10 |
+
- int8
|
| 11 |
+
- query-classification
|
| 12 |
+
- generic-semantic
|
| 13 |
+
- multilingual
|
| 14 |
+
- text-classification
|
| 15 |
+
datasets:
|
| 16 |
+
- addyo07/query-classification-dataset
|
| 17 |
+
metrics:
|
| 18 |
+
- accuracy
|
| 19 |
+
pipeline_tag: text-classification
|
| 20 |
+
model-index:
|
| 21 |
+
- name: distilbert-query-classifier
|
| 22 |
+
results:
|
| 23 |
+
- task:
|
| 24 |
+
type: text-classification
|
| 25 |
+
name: Generic vs Semantic Classification
|
| 26 |
+
dataset:
|
| 27 |
+
name: query-classification-dataset
|
| 28 |
+
type: addyo07/query-classification-dataset
|
| 29 |
+
split: test
|
| 30 |
+
metrics:
|
| 31 |
+
- type: accuracy
|
| 32 |
+
value: 0.9839
|
| 33 |
+
name: Accuracy
|
| 34 |
+
- type: precision
|
| 35 |
+
value: 0.9844
|
| 36 |
+
name: Precision
|
| 37 |
+
- type: recall
|
| 38 |
+
value: 0.9834
|
| 39 |
+
name: Recall
|
| 40 |
+
- type: f1
|
| 41 |
+
value: 0.9839
|
| 42 |
+
name: F1
|
| 43 |
+
widget:
|
| 44 |
+
- text: "my name is John"
|
| 45 |
+
- text: "hello"
|
| 46 |
+
- text: "मेरा नाम रवि है"
|
| 47 |
+
- text: "नमस्ते"
|
| 48 |
+
- text: "I love spicy food"
|
| 49 |
+
- text: "stop"
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
# Query Sieve Classifier
|
| 53 |
+
|
| 54 |
+
**DistilBERT multilingual** fine-tuned to classify user queries as **GENERIC** or **SEMANTIC** — filtering chit-chat from durable knowledge worth storing.
|
| 55 |
+
|
| 56 |
+
## Model Description
|
| 57 |
+
|
| 58 |
+
- **Architecture**: `distilbert-base-multilingual-cased` (134M params)
|
| 59 |
+
- **Quantization**: INT8 dynamic (ONNX Runtime)
|
| 60 |
+
- **Input**: Short text queries in English or Hindi (≤10 words recommended for model path; longer sentences bypass to SEMANTIC)
|
| 61 |
+
- **Output**: Binary — GENERIC (0) or SEMANTIC (1)
|
| 62 |
+
- **Inference**: ONNX Runtime CPU (Intel/AMD), single-thread P99 = **16.87ms**
|
| 63 |
+
|
| 64 |
+
## Intended Use
|
| 65 |
+
|
| 66 |
+
This model is designed as a **memory relevance gate** in voice AI pipelines. Before storing a user's utterance in long-term memory (episodic + semantic), run it through this classifier:
|
| 67 |
+
|
| 68 |
+
- **SEMANTIC** → contains facts, preferences, name, location, relationships → store in memory
|
| 69 |
+
- **GENERIC** → greeting, command, chit-chat, filler → skip memory, pass directly to LLM
|
| 70 |
+
|
| 71 |
+
Sentences longer than 10 words bypass the model entirely and are treated as SEMANTIC, since they almost always contain durable information.
|
| 72 |
+
|
| 73 |
+
## Performance
|
| 74 |
+
|
| 75 |
+
| Split | Accuracy |
|
| 76 |
+
|-------|----------|
|
| 77 |
+
| Test (15% holdout) | **98.39%** |
|
| 78 |
+
|
| 79 |
+
### Latency
|
| 80 |
+
|
| 81 |
+
| Mode | P50 | P99 |
|
| 82 |
+
|------|-----|-----|
|
| 83 |
+
| Multi-thread CPU | 8.39 ms | 11.81 ms |
|
| 84 |
+
| Single-thread CPU (intra_op_threads=1) | 14.81 ms | 16.87 ms |
|
| 85 |
+
|
| 86 |
+
## Usage
|
| 87 |
+
|
| 88 |
+
### Python
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
from transformers import AutoTokenizer
|
| 92 |
+
import onnxruntime as ort
|
| 93 |
+
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("addyo07/distilbert-query-classifier")
|
| 95 |
+
session = ort.InferenceSession("model_quantized.onnx")
|
| 96 |
+
|
| 97 |
+
def classify(text: str) -> str:
|
| 98 |
+
inputs = tokenizer(text, return_tensors="np", max_length=64, truncation=True, padding="max_length")
|
| 99 |
+
logits = session.run(None, {
|
| 100 |
+
"input_ids": inputs["input_ids"].astype(np.int64),
|
| 101 |
+
"attention_mask": inputs["attention_mask"].astype(np.int64),
|
| 102 |
+
})[0]
|
| 103 |
+
return "SEMANTIC" if logits[0][1] > logits[0][0] else "GENERIC"
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Rust
|
| 107 |
+
|
| 108 |
+
```toml
|
| 109 |
+
[dependencies]
|
| 110 |
+
query-sieve = { git = "https://github.com/your-org/query-sieve" }
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
```rust
|
| 114 |
+
use query_sieve::GenericSemanticClassifier;
|
| 115 |
+
|
| 116 |
+
let classifier = GenericSemanticClassifier::load(
|
| 117 |
+
"models/model_quantized.onnx",
|
| 118 |
+
"models/tokenizer.json",
|
| 119 |
+
)?;
|
| 120 |
+
let result = classifier.classify("my name is John")?;
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
## Training Data
|
| 124 |
+
|
| 125 |
+
The dataset contains **12,044 synthetic examples** generated by `llama3.1:8b`:
|
| 126 |
+
|
| 127 |
+
| Category | English | Hindi |
|
| 128 |
+
|----------|---------|-------|
|
| 129 |
+
| GENERIC | 3,003 | 3,019 |
|
| 130 |
+
| SEMANTIC | 3,017 | 3,005 |
|
| 131 |
+
|
| 132 |
+
The SEMANTIC category is balanced to contain ~40% short standalone statements (3-7 words) to prevent the model from learning "semantic = long sentence."
|
| 133 |
+
|
| 134 |
+
## Files
|
| 135 |
+
|
| 136 |
+
| File | Size | Description |
|
| 137 |
+
|------|------|-------------|
|
| 138 |
+
| `model_quantized.onnx` | 130 MB | INT8 quantized ONNX model |
|
| 139 |
+
| `tokenizer.json` | 2.8 MB | HuggingFace tokenizer |
|
| 140 |
+
| `config.json` | 0.7 KB | Model configuration |
|
| 141 |
+
|
| 142 |
+
## License
|
| 143 |
+
|
| 144 |
+
MIT
|