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- pt
|
| 11 |
+
tags:
|
| 12 |
+
- text-classification
|
| 13 |
+
- intent-classification
|
| 14 |
+
- routing
|
| 15 |
+
- multilingual
|
| 16 |
+
- onnx
|
| 17 |
+
license: mit
|
| 18 |
+
datasets:
|
| 19 |
+
- rufatronics/ueg-training-data
|
| 20 |
+
metrics:
|
| 21 |
+
- accuracy
|
| 22 |
+
- f1
|
| 23 |
+
model-index:
|
| 24 |
+
- name: UEG Classifier v1
|
| 25 |
+
results:
|
| 26 |
+
- task:
|
| 27 |
+
type: text-classification
|
| 28 |
+
dataset:
|
| 29 |
+
name: UEG Training Data
|
| 30 |
+
type: rufatronics/ueg-training-data
|
| 31 |
+
metrics:
|
| 32 |
+
- type: accuracy
|
| 33 |
+
value: 0.9735
|
| 34 |
+
- type: f1
|
| 35 |
+
value: 0.9733
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
# UEG — Universal Edge Gateway Classifier
|
| 39 |
+
|
| 40 |
+
A 35M parameter bidirectional transformer for intent classification and AI request routing.
|
| 41 |
+
|
| 42 |
+
## Model Description
|
| 43 |
+
|
| 44 |
+
UEG classifies incoming user text into 22 intent classes across 5 routing tiers, plus a secondary 5-class language resource density classification. Both outputs come from a single forward pass.
|
| 45 |
+
|
| 46 |
+
- **Architecture**: 6-layer bidirectional transformer encoder, 512 hidden dim, 8 attention heads
|
| 47 |
+
- **Parameters**: ~35M
|
| 48 |
+
- **Max sequence length**: 128 tokens
|
| 49 |
+
- **Tokenizer**: Custom BPE trained on the UEG training corpus (32K vocab)
|
| 50 |
+
- **Languages**: English, Arabic, Hindi, French, Spanish, Chinese, Swahili, Portuguese
|
| 51 |
+
|
| 52 |
+
## Performance
|
| 53 |
+
|
| 54 |
+
| Head | Accuracy | Macro F1 |
|
| 55 |
+
|------|----------|----------|
|
| 56 |
+
| Intent (22 classes) | 97.35% | 0.9733 |
|
| 57 |
+
| Resource Density (5 classes) | 99.95% | 0.9987 |
|
| 58 |
+
|
| 59 |
+
## Usage
|
| 60 |
+
|
| 61 |
+
### Via REST API (recommended)
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
import requests
|
| 65 |
+
|
| 66 |
+
r = requests.post("https://ueg-api.onrender.com/classify",
|
| 67 |
+
json={"text": "Write a Python function to sort a list"})
|
| 68 |
+
print(r.json())
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Via ONNX Runtime
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
import onnxruntime as ort
|
| 75 |
+
import numpy as np
|
| 76 |
+
from tokenizers import Tokenizer
|
| 77 |
+
from huggingface_hub import hf_hub_download
|
| 78 |
+
|
| 79 |
+
# Load tokenizer
|
| 80 |
+
tok_path = hf_hub_download("rufatronics/ueg-classifier",
|
| 81 |
+
"tokenizer/tokenizer.json")
|
| 82 |
+
tokenizer = Tokenizer.from_file(tok_path)
|
| 83 |
+
tokenizer.enable_padding(pad_id=0, pad_token="[PAD]", length=128)
|
| 84 |
+
tokenizer.enable_truncation(max_length=128)
|
| 85 |
+
|
| 86 |
+
# Load ONNX model + data file (both needed)
|
| 87 |
+
onnx_path = hf_hub_download("rufatronics/ueg-classifier",
|
| 88 |
+
"export/ueg_model.onnx")
|
| 89 |
+
data_path = hf_hub_download("rufatronics/ueg-classifier",
|
| 90 |
+
"export/ueg_model.onnx.data")
|
| 91 |
+
|
| 92 |
+
sess = ort.InferenceSession(onnx_path,
|
| 93 |
+
providers=["CPUExecutionProvider"])
|
| 94 |
+
|
| 95 |
+
# Inference
|
| 96 |
+
enc = tokenizer.encode("Write a Python function to reverse a string")
|
| 97 |
+
ids = np.array([enc.ids], dtype=np.int64)
|
| 98 |
+
mask = np.array([enc.attention_mask], dtype=np.int64)
|
| 99 |
+
|
| 100 |
+
logits_intent, logits_resource = sess.run(None,
|
| 101 |
+
{"input_ids": ids, "attention_mask": mask})
|
| 102 |
+
|
| 103 |
+
intent_class = np.argmax(logits_intent)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Files
|
| 107 |
+
|
| 108 |
+
| File | Description |
|
| 109 |
+
|------|-------------|
|
| 110 |
+
| `checkpoint_best.pt` | PyTorch weights (best validation epoch) |
|
| 111 |
+
| `checkpoint_latest.pt` | PyTorch weights (final epoch) |
|
| 112 |
+
| `export/ueg_model.onnx` | ONNX model for production inference |
|
| 113 |
+
| `export/ueg_model.onnx.data` | ONNX external data (required alongside .onnx) |
|
| 114 |
+
| `export/config.json` | Architecture hyperparameters |
|
| 115 |
+
| `export/benchmark.json` | Inference latency benchmark |
|
| 116 |
+
| `tokenizer/tokenizer.json` | Tokenizer definition |
|
| 117 |
+
| `tokenizer/tokenizer_config.json` | Tokenizer config with pad/cls/sep IDs |
|
| 118 |
+
| `labels/intent_classes.json` | Intent class label mappings |
|
| 119 |
+
| `labels/resource_classes.json` | Resource density class mappings |
|
| 120 |
+
|
| 121 |
+
## Training
|
| 122 |
+
|
| 123 |
+
Trained from scratch on 176K synthetic examples generated via the UEG data generation pipeline using Groq, Gemini, and Mistral free tiers. Three-phase training: warmup → cosine decay → head fine-tuning. Early stopping with patience=4.
|
| 124 |
+
|
| 125 |
+
Full training code: https://github.com/rufatronics/ueg-datagen
|
| 126 |
+
|
| 127 |
+
## Citation
|
| 128 |
+
|
| 129 |
+
```bibtex
|
| 130 |
+
@misc{ueg2026,
|
| 131 |
+
title={UEG: Universal Edge Gateway for AI Request Routing},
|
| 132 |
+
author={Ahmad Garba},
|
| 133 |
+
year={2026},
|
| 134 |
+
url={https://huggingface.co/rufatronics/ueg-classifier}
|
| 135 |
+
}
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## License
|
| 139 |
+
|
| 140 |
+
MIT
|