File size: 7,370 Bytes
b751bb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37d98fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b751bb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37d98fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b751bb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
---
language:
- en
library_name: transformers
pipeline_tag: text-classification
base_model: distilbert-base-uncased
metrics:
- accuracy
- f1
tags:
- intent-classification
- multitask
- iab
- conversational-ai
- adtech
- calibrated-confidence
license: apache-2.0
---

# admesh/agentic-intent-classifier

Production-ready intent + IAB classifier bundle for conversational traffic.

Combines multitask intent modeling, supervised IAB content classification, and per-head confidence calibration to support safe monetization decisions in real time.

## Links

- Hugging Face: https://huggingface.co/admesh/agentic-intent-classifier
- GitHub: https://github.com/GouniManikumar12/agentic-intent-classifier

## What It Predicts

| Field | Description |
|---|---|
| `intent.type` | `commercial`, `informational`, `navigational`, `transactional`, … |
| `intent.subtype` | `product_discovery`, `comparison`, `how_to`, … |
| `intent.decision_phase` | `awareness`, `consideration`, `decision`, … |
| `iab_content` | IAB Content Taxonomy 3.0 tier1 / tier2 / tier3 labels |
| `component_confidence` | Per-head calibrated confidence with threshold flags |
| `system_decision` | Monetization eligibility, opportunity type, policy |

---

## Deployment Options

### 0. Colab / Kaggle Quickstart (copy/paste)

```python
!pip -q install -U pip
!pip -q install -U "torch==2.10.0" "torchvision==0.25.0" "torchaudio==2.10.0"
!pip -q install -U "transformers>=4.36.0" "huggingface_hub>=0.20.0" "safetensors>=0.4.0"
```

Restart the runtime after installs (**Runtime → Restart runtime**) so the new Torch version is actually used.

```python
from transformers import pipeline

clf = pipeline(
    "admesh-intent",
    model="admesh/agentic-intent-classifier",
    trust_remote_code=True,  # required (custom pipeline + multi-model bundle)
)

out = clf("Which laptop should I buy for college?")
print(out["meta"])
print(out["model_output"]["classification"]["intent"])
```

---

## Latency / inference timing (quick check)

The first call includes model/code loading. Warm up once, then measure:

```python
import time
q = "Which laptop should I buy for college?"

_ = clf("warm up")
t0 = time.perf_counter()
out = clf(q)
print(f"latency_ms={(time.perf_counter() - t0) * 1000:.1f}")
```

### 1. `transformers.pipeline()` — anywhere (Python)

```python
from transformers import pipeline

clf = pipeline(
    "admesh-intent",
    model="admesh/agentic-intent-classifier",
    trust_remote_code=True,
)

result = clf("Which laptop should I buy for college?")
```

Batch and custom thresholds:

```python
# batch
results = clf([
    "Best running shoes under $100",
    "How does TCP work?",
    "Buy noise-cancelling headphones",
])

# custom confidence thresholds
result = clf(
    "Buy headphones",
    threshold_overrides={"intent_type": 0.6, "intent_subtype": 0.35},
)
```

---

### 2. HF Inference Endpoints (managed, deploy to AWS / Azure / GCP)

1. Go to https://ui.endpoints.huggingface.co
2. **New Endpoint** → select `admesh/agentic-intent-classifier`
3. Framework: **PyTorch** — Task: **Text Classification**
4. Enable **"Load with trust_remote_code"**
5. Deploy

The endpoint serves the same `pipeline()` interface above via REST:

```bash
curl https://<your-endpoint>.endpoints.huggingface.cloud \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"inputs": "Which laptop should I buy for college?"}'
```

---

### 3. HF Spaces (Gradio / Streamlit demo)

```python
# app.py for a Gradio Space
import gradio as gr
from transformers import pipeline

clf = pipeline(
    "admesh-intent",
    model="admesh/agentic-intent-classifier",
    trust_remote_code=True,
)

def classify(text):
    return clf(text)

gr.Interface(fn=classify, inputs="text", outputs="json").launch()
```

---

### 4. Local / notebook via `snapshot_download`

```python
import sys
from huggingface_hub import snapshot_download

local_dir = snapshot_download(
    repo_id="admesh/agentic-intent-classifier",
    repo_type="model",
)
sys.path.insert(0, local_dir)

from pipeline import AdmeshIntentPipeline
clf = AdmeshIntentPipeline()
result = clf("I need a CRM for a 5-person startup")
```

Or the one-liner factory:

```python
from pipeline import AdmeshIntentPipeline
clf = AdmeshIntentPipeline.from_pretrained("admesh/agentic-intent-classifier")
```

---

## Troubleshooting (avoid environment errors)

### `No module named 'combined_inference'` (or similar)

This means the Hub repo root is missing required Python files. Ensure these exist at the **root of the model repo** (same level as `pipeline.py`):

- `pipeline.py`, `config.json`, `config.py`
- `combined_inference.py`, `schemas.py`
- `model_runtime.py`, `multitask_runtime.py`, `multitask_model.py`
- `inference_intent_type.py`, `inference_subtype.py`, `inference_decision_phase.py`, `inference_iab_classifier.py`
- `iab_classifier.py`, `iab_taxonomy.py`

### `does not appear to have a file named model.safetensors`

Transformers requires a standard checkpoint at the repo root for `pipeline()` to initialize. This repo includes a **small dummy** `model.safetensors` + tokenizer files at the root for compatibility; the *real* production weights live in:

- `multitask_intent_model_output/`
- `iab_classifier_model_output/`
- `artifacts/calibration/`

---

## Example Output

```json
{
  "model_output": {
    "classification": {
      "iab_content": {
        "taxonomy": "IAB Content Taxonomy",
        "taxonomy_version": "3.0",
        "tier1": {"id": "552", "label": "Style & Fashion"},
        "tier2": {"id": "579", "label": "Men's Fashion"},
        "mapping_mode": "exact",
        "mapping_confidence": 0.73
      },
      "intent": {
        "type": "commercial",
        "subtype": "product_discovery",
        "decision_phase": "consideration",
        "confidence": 0.9549,
        "commercial_score": 0.656
      }
    }
  },
  "system_decision": {
    "policy": {
      "monetization_eligibility": "allowed_with_caution",
      "eligibility_reason": "commercial_discovery_signal_present"
    },
    "opportunity": {"type": "soft_recommendation", "strength": "medium"}
  },
  "meta": {
    "system_version": "0.6.0-phase4",
    "calibration_enabled": true,
    "iab_mapping_is_placeholder": false
  }
}
```

## Reproducible Revision

```python
from huggingface_hub import snapshot_download
local_dir = snapshot_download(
    repo_id="admesh/agentic-intent-classifier",
    repo_type="model",
    revision="0584798f8efee6beccd778b0afa06782ab5add60",
)
```

## Included Artifacts

| Path | Contents |
|---|---|
| `multitask_intent_model_output/` | DistilBERT multitask weights + tokenizer |
| `iab_classifier_model_output/` | IAB content classifier weights + tokenizer |
| `artifacts/calibration/` | Per-head temperature + threshold JSONs |
| `pipeline.py` | `AdmeshIntentPipeline` (transformers.Pipeline subclass) |
| `combined_inference.py` | Core inference logic |

## Notes

- `trust_remote_code=True` is required because this model uses a custom multi-head architecture that does not map to a single standard `AutoModel` checkpoint.
- `meta.iab_mapping_is_placeholder: true` means IAB artifacts were missing or skipped; train and calibrate IAB for full production accuracy.
- For long-running servers, instantiate once and reuse — models are cached in memory after the first call.