Views
No views yet
low, medium, and hard complexity levels. It is designed for LLM routing, enabling applications to dispatch simple requests to smaller, lower-cost models while reserving larger reasoning models for complex, multi-step tasks.answerdotai/ModernBERT-large (ModernBertForSequenceClassification)model.onnx, ~397 MB).tokenizers — zero PyTorch or transformers runtime dependencies are required for inference.| Class ID | Label | Description & Examples |
|---|---|---|
| 0 | low | Simple factual questions, basic definitions, direct short lookup, unit conversions. Example: "What is the capital of France?", "How many days in a leap year?" |
| 1 | medium | Explanations, code snippets, summarizing text, multi-step instructions. Example: "Explain how key-value storage works in Redis", "Write a python script to parse CSV files." |
| 2 | hard | Complex algorithms, multi-file code synthesis, lock-free concurrency, advanced mathematics. Example: "Implement a lock-free SPMC queue in C++ using atomics", "Calculate the integral of x^2 * sin(x) dx." |
low, medium, and hard buckets):| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
low | 100.00% | 81.00% | 0.8950 | 100 |
medium | 82.18% | 83.00% | 0.8259 | 100 |
hard | 84.87% | 100.00% | 0.9182 | 101 |
| Overall | 88.04% Acc | — | 0.8797 Macro-F1 | 301 total |
| Actual \ Predicted | low | medium | hard |
|---|---|---|---|
low | 81 | 18 | 1 |
medium | 0 | 83 | 17 |
hard | 0 | 0 | 101 |
| Metric | Measurement |
|---|---|
| Median Latency (p50) | 67.68 ms |
| Mean Latency | 81.44 ms |
| p90 Latency | 134.69 ms |
| p99 Latency | 161.74 ms |
| Throughput | 12.3 queries/sec |
tests/ folder:tests/test_dataset.csv: 301 held-out test queries (100 low, 100 medium, 101 hard).tests/evaluate.py: Standalone evaluation script for computing accuracy, F1, confusion matrix, and latency profile.python tests/evaluate.pypip install onnxruntime tokenizers numpy huggingface-hub1import numpy as np
2import onnxruntime as ort
3from tokenizers import Tokenizer
4from huggingface_hub import hf_hub_download
5
6# Repository details
7REPO_ID = "prvn-ramesh/query-classifier-onnx"
8
9# 1. Download model artifacts from Hugging Face Hub
10model_path = hf_hub_download(repo_id=REPO_ID, filename="model.onnx")
11tok_path = hf_hub_download(repo_id=REPO_ID, filename="tokenizer.json")
12
13# 2. Load tokenizer and initialize ONNX Runtime session
14tokenizer = Tokenizer.from_file(tok_path)
15session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])
16label_map = {0: "low", 1: "medium", 2: "hard"}
17
18def classify_query(text: str):
19 # Tokenize input string
20 encoded = tokenizer.encode(text)
21 input_ids = np.array([encoded.ids], dtype=np.int64)
22 attention_mask = np.array([encoded.attention_mask], dtype=np.int64)
23
24 # Run inference session
25 outputs = session.run(None, {
26 "input_ids": input_ids,
27 "attention_mask": attention_mask
28 })
29
30 # Softmax over logits
31 logits = outputs[0][0]
32 exp_logits = np.exp(logits - np.max(logits))
33 probs = exp_logits / np.sum(exp_logits)
34
35 pred_idx = int(np.argmax(probs))
36
37 return {
38 "label": label_map[pred_idx],
39 "confidence": float(probs[pred_idx]),
40 "scores": {label_map[i]: float(probs[i]) for i in range(len(probs))}
41 }
42
43# Example usage
44query = "Write a lock-free multi-threaded SPMC queue in C++ using atomics"
45result = classify_query(query)
46
47print(f"Query: {query}")
48print(f"Predicted Class: {result['label'].upper()} (Confidence: {result['confidence']:.2%})")
49print(f"All Scores: {result['scores']}")