RowRed commited on
Commit
e38602d
·
verified ·
1 Parent(s): 920c837

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +188 -0
README.md ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - prompt-routing
7
+ - complexity-classifier
8
+ - deberta-v3
9
+ - llm-router
10
+ - cost-optimization
11
+ datasets:
12
+ - RowRed/ComplexityRouter
13
+ - OpenAssistant/oasst2
14
+ base_model:
15
+ - microsoft/deberta-v3-base
16
+ ---
17
+
18
+ # ComplexityRouter: A Complexity based LLM Router
19
+
20
+ Introducing ComplexityRouter, A lightweight prompt complexity classifier finetuned from **microsoft/deberta-v3-base**. Using prompts from [Open Assistant Conversations Dataset Release 2 (OASST2)](https://huggingface.co/datasets/OpenAssistant/oasst2), some from myself, and some made more complex by Qwen3.5-4B (non-thinking mode), I created a synthetic dataset classifying 4,400 of the prompts using [Qwen3.5-4B Non Thinking Mode](https://huggingface.co/Qwen/Qwen3.5-4B).
21
+
22
+ It assigns prompts to one of 4 complexity levels, making it useful for routing queries to the appropriate LLM tier.
23
+
24
+ ## Model Details
25
+
26
+ ### Model Description
27
+
28
+ - **Model type:** Text Classification (multi‑class)
29
+ - **Language:** English
30
+ - **Backbone:** microsoft/deberta-v3-base
31
+ - **License:** Apache‑2.0
32
+ - **Finetuned from model:** microsoft/deberta-v3-base
33
+ - **Training data:** OASST2 + synthetic augmentations + manually created prompts
34
+ Labels generated by **Qwen3.5‑4B** (non‑thinking mode).
35
+
36
+ ### Model Sources
37
+
38
+ - **Dataset repository:** https://huggingface.co/datasets/RowRed/ComplexityRouter
39
+
40
+ ## Uses
41
+
42
+ ### Direct Use
43
+
44
+ Route prompts to appropriate LLM tiers based on predicted complexity:
45
+
46
+ | Level | Meaning | Suggested LLM Tier |
47
+ |-------|---------|-------------------|
48
+ | 0 (Trivial) | Simple lookups, basic Q&A (e.g., “What is 2+2?”) | Fast/cheap local model |
49
+ | 1 (Simple) | Moderate reasoning, basic domain knowledge | Mid‑tier model |
50
+ | 2 (Moderate) | Complex reasoning, deep knowledge required | Strong model |
51
+ | 3 (Complex) | Very complex reasoning, niche expertise | Frontier API model |
52
+
53
+ **Recommended routing strategy:** Group levels **0 and 1** together (fast/cheap tier), level 2 as standard, level 3 as premium. The model achieves **92.5% adjacent accuracy** on my test, meaning it rarely misroutes by more than one tier.
54
+
55
+ ### Out‑of‑Scope Use
56
+
57
+ - Multi‑turn conversation routing (single prompts only).
58
+ - Non‑English prompts (training data was English‑only).
59
+ - Prompts requiring image or multimodal understanding.
60
+
61
+ ## Bias, Risks, and Limitations
62
+
63
+ - Training data is synthetic and may not represent all real‑world prompt distributions.
64
+ - Level 1 (Simple) and Level 2 (Moderate) have lower per‑class F1 scores – boundary cases are inherently ambiguous.
65
+ - The model may struggle with very domain‑specific technical jargon.
66
+ - Performance may degrade on prompts that are very different from the training distribution.
67
+
68
+ ## Notice
69
+ This is my first attempt making a widespread finetune. There are probably lots of issues, but thought the idea was sound. I might make a second (hopefully better) version eventually, but am not sure where to get lots of high-quality open source data.
70
+
71
+ ## Training Details
72
+ ### Training Data
73
+
74
+ | Split | Samples | Source File | Notes |
75
+ |-------------|---------|----------------------|-------|
76
+ | Training | 2,800 | TRAINING.jsonl | Used for model training |
77
+ | Validation | 600 | TRAINING.jsonl | Used for early stopping / hyperparameter tuning |
78
+ | Test (internal) | 600 | TRAINING.jsonl | Used for in‑distribution evaluation |
79
+ | Test (held‑out) | 400 | TEST.jsonl | Fully independent test set (reported results) |
80
+
81
+ **Total unique prompts:** 4,400
82
+
83
+ Class distribution (training):
84
+ Level 0: 762 (27.2%) • Level 1: 674 (24.1%) • Level 2: 795 (28.4%) • Level 3: 569 (20.3%)
85
+
86
+ ## Training Procedure
87
+ - Hardware: NVIDIA T4 (16 GB VRAM, Google Colab)
88
+ - Framework: PyTorch 2.11 + Hugging Face Transformers
89
+ - Optimizer: AdamW (lr=2e-5, weight_decay=0.01)
90
+ - Scheduler: Linear warmup (10% of steps) → linear decay
91
+ - Loss: Weighted Cross‑Entropy (classification) + MSE (regression)
92
+ - Batch size: 16 (effective 32 with gradient accumulation)
93
+ - Epochs: 7 (early stopping patience = 3)
94
+ - Training time: ~18 minutes
95
+ - Class balancing: sqrt‑scaled class weights + weighted random sampler
96
+
97
+ ## Evaluation Results
98
+ Test Set (400 held‑out samples)
99
+
100
+ | Metric | Value |
101
+ |--------------------------|-------|
102
+ | Exact Match Accuracy | 65.0% |
103
+ | Adjacent (±1) Accuracy | 92.5% |
104
+ | Macro F1 | 0.663 |
105
+ | Weighted F1 | 0.653 |
106
+
107
+ ## How to Get Started with the Model
108
+
109
+ ```python
110
+ from transformers import AutoTokenizer, AutoModel
111
+ import torch
112
+ import torch.nn as nn
113
+
114
+ class PromptComplexityRouter(nn.Module):
115
+ def __init__(self, backbone="microsoft/deberta-v3-base", num_labels=4):
116
+ super().__init__()
117
+ self.backbone = AutoModel.from_pretrained(backbone)
118
+ hidden_size = self.backbone.config.hidden_size
119
+ self.classifier = nn.Sequential(
120
+ nn.Dropout(0.1),
121
+ nn.Linear(hidden_size, 256),
122
+ nn.GELU(),
123
+ nn.Dropout(0.1),
124
+ nn.Linear(256, num_labels),
125
+ )
126
+
127
+ def forward(self, input_ids, attention_mask):
128
+ outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
129
+ cls_output = outputs.last_hidden_state[:, 0, :]
130
+ return self.classifier(cls_output)
131
+
132
+ # Load
133
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
134
+ tokenizer = AutoTokenizer.from_pretrained("RowRed/ComplexityRouter")
135
+ model = PromptComplexityRouter()
136
+ model.load_state_dict(
137
+ torch.load("pytorch_model.bin", map_location=device),
138
+ strict=False
139
+ )
140
+ model.to(device)
141
+ model.eval()
142
+
143
+ # Predict
144
+ prompts = ["What is 2+2?", "Explain quantum entanglement in detail."]
145
+ encoded = tokenizer(prompts, padding=True, truncation=True, return_tensors="pt").to(device)
146
+ with torch.no_grad():
147
+ logits = model(encoded["input_ids"], encoded["attention_mask"])
148
+ probs = torch.softmax(logits, dim=-1)
149
+ predictions = torch.argmax(probs, dim=-1)
150
+
151
+ for prompt, level in zip(prompts, predictions):
152
+ print(f"Level {level.item()}: {prompt}")
153
+ ```
154
+
155
+ ## Citation
156
+ If you use this model, please cite:
157
+
158
+ ```bibtex
159
+ @software{ComplexityRouter,
160
+ author = {RowRed},
161
+ title = {ComplexityRouter},
162
+ year = {2026},
163
+ url = {https://huggingface.co/RowRed/ComplexityRouter}
164
+ }
165
+ ```
166
+
167
+ Additionally, acknowledge the base dataset and labeling model:
168
+
169
+ ```bibtex
170
+ @dataset{oasst2,
171
+ author = {OpenAssistant Contributors},
172
+ title = {Open Assistant Conversations Dataset Release 2},
173
+ year = {2023},
174
+ url = {https://huggingface.co/datasets/OpenAssistant/oasst2}
175
+ }
176
+
177
+ @software{qwen3.5-4b,
178
+ author = {Qwen Team},
179
+ title = {Qwen3.5-4B},
180
+ year = {2026},
181
+ url = {https://huggingface.co/Qwen/Qwen3.5-4B}
182
+ }
183
+ ```
184
+
185
+ ## License
186
+ This model is released under Apache‑2.0.
187
+ The backbone (microsoft/deberta-v3-base) is MIT‑licensed.
188
+ The training dataset is derived from OASST2 (Apache‑2.0) and Qwen3.5‑4B outputs (Apache‑2.0).