codelion commited on
Commit
358fa63
·
verified ·
1 Parent(s): 8ea3ca1

Streamline model card: remove duplication, improve flow, make more concise

Browse files
Files changed (1) hide show
  1. README.md +78 -154
README.md CHANGED
@@ -15,108 +15,48 @@ metrics:
15
 
16
  # Chayan: Multi-Model LLM Router
17
 
18
- **Chayan** is a high-performance LLM router that intelligently selects between 4 models (gpt-4o-mini, gemini-2.5-flash-lite, gemini-2.5-flash, and gpt-4o) to optimize the accuracy-cost tradeoff.
19
 
20
- ## Performance
21
 
22
- 🏆 **SOTA on RouterArena: #1 Optimal Accuracy Score, #2 Optimal Selection**
23
-
24
- Official RouterArena Full Dataset Results (8,400 queries):
25
- - **88.7% Optimal Accuracy Score** - 🥇 #1 SOTA! (Best routing decision quality)
26
- - **43.0% Optimal Selection Score** - 🥈 #2 Silver! (Second-best model selection)
27
- - **64.9% Overall Accuracy** - #7 overall, #5 among open-source routers
28
- - **Arena Score: 63.8** - #7 overall, #5 among open-source routers
29
  - **$0.60 per 1K queries** - Cost-efficient routing
30
 
31
- **Key Metrics Explained:**
32
- - **Optimal Accuracy Score**: When Chayan routes to a model, that model gives the correct answer 88.7% of the time (highest on leaderboard!)
33
- - **Optimal Selection Score**: Chayan selects the best available model 43% of the time (second-best on leaderboard)
34
-
35
- Sub_10 Benchmark (809 queries):
36
- - **69.05% accuracy**
37
- - **$0.333 per 1K queries** (estimated cost)
38
- - **+7.62pp improvement** over baseline 2-model router
39
- - Achieves **99% of theoretical perfect oracle performance**
40
-
41
- ## Model Architecture
42
-
43
- Chayan uses an adaptive K-NN classifier built on:
44
- - **Base model**: BERT-base-uncased embeddings
45
- - **Classification approach**: Prototype-based memory with FAISS indexing
46
- - **Key innovation**: Calibrated confidence scores to correct for training data imbalance
47
-
48
- ### Supported Models
49
-
50
- | Model | Use Case | Cost/1M tokens |
51
- |-------|----------|----------------|
52
- | openai/gpt-4o-mini | Simple queries | $0.15 |
53
- | google/gemini-2.5-flash-lite | Medium complexity | $0.075 |
54
- | google/gemini-2.5-flash | Higher complexity | $0.30 |
55
- | openai/gpt-4o | Complex queries | $2.50 |
56
-
57
- ## Training Methodology
58
-
59
- ### Dataset
60
- - **Source**: RouterArena sub_10 split (809 queries)
61
- - **Oracle labels**: Generated using 4-model cascade strategy (select cheapest successful model)
62
- - **Features**: Query length, word count, math indicators, sentence count, multiple choice markers
63
-
64
- ### Training Process
65
- 1. **Multi-class classification**: Trained to predict one of 4 models
66
- 2. **Memory-based learning**: K-NN classifier with prototype storage
67
- 3. **Calibration optimization**: Grid search over 625 configurations to find optimal confidence score adjustments
68
-
69
- ### The Calibration Breakthrough
70
-
71
- The uncalibrated router achieved only 61.76% accuracy due to heavy bias toward gpt-4o-mini (83% routing). By applying calibrated confidence scores, we corrected for training data imbalance and achieved 69.05% accuracy.
72
 
73
- **Optimal Calibration Factors:**
74
- ```python
75
- calibration = {
76
- "openai/gpt-4o-mini": 0.9,
77
- "google/gemini-2.5-flash-lite": 1.5,
78
- "google/gemini-2.5-flash": 1.8,
79
- "openai/gpt-4o": 1.5
80
- }
81
- ```
82
 
83
- ## Usage
84
 
85
- ### Installation
86
 
87
  ```bash
88
  pip install adaptive-classifier
89
  ```
90
 
91
- ### Basic Usage
92
-
93
  ```python
94
  from adaptive_classifier import AdaptiveClassifier
95
 
96
- # Load the router
97
  router = AdaptiveClassifier.load("adaptive-classifier/chayan")
98
 
99
- # Get routing decision with top-4 predictions
100
  query = "What is the capital of France?"
101
  predictions = router.predict(query, k=4)
102
 
103
- # predictions is a list of (model_name, confidence) tuples
104
- # [(model1, score1), (model2, score2), (model3, score3), (model4, score4)]
105
-
106
- # Select top model
107
- selected_model = predictions[0][0]
108
- print(f"Route to: {selected_model}")
109
  ```
110
 
111
- ### Usage with Calibration (Recommended)
112
 
113
  ```python
114
- from adaptive_classifier import AdaptiveClassifier
115
-
116
- # Load router
117
- router = AdaptiveClassifier.load("adaptive-classifier/chayan")
118
-
119
- # Define calibration factors
120
  calibration = {
121
  "openai/gpt-4o-mini": 0.9,
122
  "google/gemini-2.5-flash-lite": 1.5,
@@ -124,124 +64,108 @@ calibration = {
124
  "openai/gpt-4o": 1.5
125
  }
126
 
127
- # Get predictions
128
- query = "Explain quantum entanglement in simple terms"
129
  predictions = router.predict(query, k=4)
130
-
131
- # Apply calibration
132
- calibrated_scores = {
133
- model: score * calibration.get(model, 1.0)
134
- for model, score in predictions
135
- }
136
-
137
- # Select model with highest calibrated score
138
  selected_model = max(calibrated_scores.items(), key=lambda x: x[1])[0]
139
- print(f"Route to: {selected_model}")
140
  ```
141
 
142
- ### Feature Augmentation
143
-
144
- The router was trained with query features prepended as text tokens:
145
 
146
- ```python
147
- from adaptive_classifier.complexity_features import augment_query_with_features
 
 
148
 
149
- query = "What is 2+2?"
150
- augmented = augment_query_with_features(query)
151
- # Returns: "[LEN:12][WORDS:3][MATH:1][SENT:1][MC:0] What is 2+2?"
152
 
153
- # Use augmented query for routing
154
- predictions = router.predict(augmented, k=4)
155
- ```
 
 
 
156
 
157
- ## Performance Comparison
158
 
159
- | Router | Accuracy | Cost/1K | Notes |
160
- |--------|----------|---------|-------|
161
- | All gpt-4o-mini | 56.98% | $0.088 | Baseline |
162
- | 2-model router | 61.43% | $0.217 | Previous best |
163
- | **Chayan (uncalibrated)** | 61.76% | $0.269 | Biased toward mini |
164
- | **Chayan (calibrated)** | **69.05%** | **$0.333** | **Optimal** |
165
- | Perfect 2-model oracle | 69.84% | $0.784 | Theoretical max |
166
- | Perfect 4-model cascade | 76.51% | $0.553 | Theoretical max |
167
 
168
- ## RouterArena Leaderboard
169
 
170
- 🏆 **Official Results - #1 Optimal Accuracy, #2 Optimal Selection**
 
 
 
 
171
 
172
- ![RouterArena Leaderboard](routerarena_leaderboard.png)
173
 
174
- Chayan on the official [RouterArena leaderboard](https://routeworks.github.io/) (sorted by Optimal Accuracy):
175
 
176
- | Rank | Router | **Opt. Acc** | **Opt. Select** | Accuracy | Arena Score | Cost/1k | Type |
177
- |------|--------|--------------|-----------------|----------|-------------|---------|------|
178
- | **1** | **Chayan** | **88.7%** 🥇 | **43.0%** 🥈 | 64.9% | 63.8 | $0.60 | Open-Source |
179
- | 2 | RouterBench-MLP | 83.3% | 13.4% | 61.6% | 57.6 | $4.80 | Open-Source |
180
- | 3 | Azure | 82.0% | 22.5% | 68.1% | 66.7 | $0.50 | Closed-Source |
181
- | 4 | vLLM-SR | 79.3% | 4.8% | 67.3% | 64.3 | $1.70 | Open-Source |
182
- | 5 | RouterBench-KNN | 78.8% | 13.1% | 58.7% | 55.5 | $4.30 | Open-Source |
183
 
184
- **Overall Rankings:**
185
- - **Optimal Accuracy Score**: 🥇 #1 (88.7% - SOTA!)
186
- - **Optimal Selection Score**: 🥈 #2 (43.0% - Silver!)
187
- - **Overall Accuracy**: #7 overall, #5 among open-source
188
- - **Arena Score**: #7 overall, #5 among open-source
189
 
190
- **🥇 SOTA Achievement - Optimal Accuracy Score**: Chayan achieves **88.7%**, the highest score among all routers. This measures routing decision quality - when Chayan routes to a model, that model gives the correct answer 88.7% of the time.
 
 
 
 
 
 
191
 
192
- **🥈 Silver Medal - Optimal Selection Score**: Chayan ranks **#2** with **43.0%**, meaning it selects the optimal model (best among all available models) 43% of the time, second only to Azure's 46.3%.
193
 
194
- View the full leaderboard and PR: [RouterArena PR #24](https://github.com/RouteWorks/RouterArena/pull/24)
 
 
 
 
195
 
196
- ## Technical Insights
197
 
198
- ### Why Calibration Works
199
 
200
- The router learned good semantic representations, but the decision boundaries were miscalibrated due to class imbalance in training data:
201
- - 57% gpt-4o-mini examples
202
- - 27% gpt-4o examples
203
- - 12% gemini-flash-lite examples
204
- - 4% gemini-flash examples
205
 
206
- K-NN classifiers are sensitive to class imbalance. By applying calibration factors post-training, we corrected the bias without retraining, unlocking a +7.29pp improvement.
 
207
 
208
- ### Model Details
 
 
209
 
210
- - **Training time**: 19.2 minutes
211
- - **Training examples**: 809 queries
212
- - **Memory size**: 3000 prototypes
213
- - **Temperature**: 0.4
214
- - **Distance metric**: Cosine similarity
215
- - **Embeddings**: Normalized BERT-base-uncased
216
 
217
  ## Limitations
218
 
219
- - Calibration factors were optimized on RouterArena sub_10 split and may not generalize perfectly to other domains
220
- - Router assumes the 4 specific models are available via API
221
- - Performance depends on query distribution matching RouterArena benchmark
222
  - Cost estimates assume ~500 tokens per query
223
 
224
  ## Citation
225
 
226
- If you use Chayan in your research or applications, please cite:
227
-
228
  ```bibtex
229
  @software{chayan_router_2025,
230
  title = {Chayan: Calibrated Multi-Model LLM Router},
231
  author = {Adaptive Classifier Team},
232
  year = {2025},
233
  url = {https://huggingface.co/adaptive-classifier/chayan},
234
- note = {High-performance LLM router achieving 69.05\% accuracy on RouterArena}
235
  }
236
  ```
237
 
238
- ## License
239
-
240
- MIT License
241
-
242
  ## Links
243
 
244
- - **Model Repository**: https://huggingface.co/adaptive-classifier/chayan
245
  - **Library**: https://github.com/codelion/adaptive-classifier
246
  - **RouterArena**: https://routeworks.github.io/
247
  - **RouterArena Paper**: https://arxiv.org/abs/2510.00202
 
 
 
 
 
15
 
16
  # Chayan: Multi-Model LLM Router
17
 
18
+ **Chayan** is a high-performance LLM router that intelligently routes between 4 models (gpt-4o-mini, gemini-2.5-flash-lite, gemini-2.5-flash, and gpt-4o) to optimize the accuracy-cost tradeoff.
19
 
20
+ ## 🏆 RouterArena Performance
21
 
22
+ **Official Leaderboard Results** (8,400 queries):
23
+ - 🥇 **#1 Optimal Accuracy Score: 88.7%** - SOTA! (Best routing decision quality)
24
+ - 🥈 **#2 Optimal Selection Score: 43.0%** - Silver! (Second-best model selection)
25
+ - **#7 Overall** (#5 open-source): 64.9% accuracy, 63.8 arena score
 
 
 
26
  - **$0.60 per 1K queries** - Cost-efficient routing
27
 
28
+ ![RouterArena Leaderboard](routerarena_leaderboard.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ **What do these metrics mean?**
31
+ - **Optimal Accuracy**: When Chayan routes to a model, that model gives the correct answer 88.7% of the time
32
+ - **Optimal Selection**: Chayan selects the best available model 43% of the time
 
 
 
 
 
 
33
 
34
+ View full leaderboard: [RouterArena](https://routeworks.github.io/) | [PR #24](https://github.com/RouteWorks/RouterArena/pull/24)
35
 
36
+ ## Quick Start
37
 
38
  ```bash
39
  pip install adaptive-classifier
40
  ```
41
 
 
 
42
  ```python
43
  from adaptive_classifier import AdaptiveClassifier
44
 
45
+ # Load router
46
  router = AdaptiveClassifier.load("adaptive-classifier/chayan")
47
 
48
+ # Get routing decision
49
  query = "What is the capital of France?"
50
  predictions = router.predict(query, k=4)
51
 
52
+ # Route to top model
53
+ selected_model = predictions[0][0] # e.g., "openai/gpt-4o-mini"
 
 
 
 
54
  ```
55
 
56
+ ### Recommended: Use with Calibration
57
 
58
  ```python
59
+ # Apply calibration factors for best performance
 
 
 
 
 
60
  calibration = {
61
  "openai/gpt-4o-mini": 0.9,
62
  "google/gemini-2.5-flash-lite": 1.5,
 
64
  "openai/gpt-4o": 1.5
65
  }
66
 
 
 
67
  predictions = router.predict(query, k=4)
68
+ calibrated_scores = {model: score * calibration[model] for model, score in predictions}
 
 
 
 
 
 
 
69
  selected_model = max(calibrated_scores.items(), key=lambda x: x[1])[0]
 
70
  ```
71
 
72
+ ## Architecture
 
 
73
 
74
+ **Core Components:**
75
+ - **Base Model**: BERT-base-uncased embeddings
76
+ - **Classifier**: Adaptive K-NN with prototype memory (FAISS-backed)
77
+ - **Innovation**: Calibrated confidence scores to correct training data imbalance
78
 
79
+ **Supported Models:**
 
 
80
 
81
+ | Model | Use Case | Cost/1M tokens |
82
+ |-------|----------|----------------|
83
+ | openai/gpt-4o-mini | Simple queries | $0.15 |
84
+ | google/gemini-2.5-flash-lite | Medium complexity | $0.075 |
85
+ | google/gemini-2.5-flash | Higher complexity | $0.30 |
86
+ | openai/gpt-4o | Complex queries | $2.50 |
87
 
88
+ ## How It Works
89
 
90
+ ### Training
91
+ - **Dataset**: RouterArena sub_10 (809 queries)
92
+ - **Oracle Labels**: 4-model cascade strategy (select cheapest successful model)
93
+ - **Training Time**: 19.2 minutes
94
+ - **Method**: K-NN classifier with 3000 prototypes, temperature 0.4
 
 
 
95
 
96
+ ### The Calibration Breakthrough
97
 
98
+ The uncalibrated router achieved 61.76% accuracy but was biased toward gpt-4o-mini (83% routing). This happened because the training data had class imbalance:
99
+ - 57% gpt-4o-mini examples
100
+ - 27% gpt-4o examples
101
+ - 12% gemini-flash-lite examples
102
+ - 4% gemini-flash examples
103
 
104
+ **Solution**: Apply post-training calibration factors to correct the bias without retraining.
105
 
106
+ **Result**: +7.29pp improvement (61.76% 69.05% on sub_10 benchmark)
107
 
108
+ ## Performance Benchmarks
 
 
 
 
 
 
109
 
110
+ **Sub_10 Benchmark (809 queries):**
 
 
 
 
111
 
112
+ | Router | Accuracy | Cost/1K |
113
+ |--------|----------|---------|
114
+ | All gpt-4o-mini (baseline) | 56.98% | $0.088 |
115
+ | 2-model router | 61.43% | $0.217 |
116
+ | Chayan (uncalibrated) | 61.76% | $0.269 |
117
+ | **Chayan (calibrated)** | **69.05%** | **$0.333** |
118
+ | Perfect 2-model oracle | 69.84% | $0.784 |
119
 
120
+ **Key Insight**: Chayan achieves 99% of perfect oracle performance at 57% lower cost.
121
 
122
+ **Full Dataset (8,400 queries):**
123
+ - **Optimal Accuracy**: 88.7% (🥇 #1)
124
+ - **Optimal Selection**: 43.0% (🥈 #2)
125
+ - **Overall Accuracy**: 64.9% (#7 overall, #5 open-source)
126
+ - **Cost**: $0.60/1K queries
127
 
128
+ ## Advanced Usage
129
 
130
+ ### Feature Augmentation
131
 
132
+ Chayan was trained with query features prepended as tokens:
 
 
 
 
133
 
134
+ ```python
135
+ from adaptive_classifier.complexity_features import augment_query_with_features
136
 
137
+ query = "What is 2+2?"
138
+ augmented = augment_query_with_features(query)
139
+ # Returns: "[LEN:12][WORDS:3][MATH:1][SENT:1][MC:0] What is 2+2?"
140
 
141
+ predictions = router.predict(augmented, k=4)
142
+ ```
 
 
 
 
143
 
144
  ## Limitations
145
 
146
+ - Calibration factors optimized on RouterArena sub_10; may require adjustment for other domains
147
+ - Requires the 4 specific models to be available via API
148
+ - Performance depends on query distribution similar to RouterArena benchmark
149
  - Cost estimates assume ~500 tokens per query
150
 
151
  ## Citation
152
 
 
 
153
  ```bibtex
154
  @software{chayan_router_2025,
155
  title = {Chayan: Calibrated Multi-Model LLM Router},
156
  author = {Adaptive Classifier Team},
157
  year = {2025},
158
  url = {https://huggingface.co/adaptive-classifier/chayan},
159
+ note = {SOTA LLM router: 88.7\% optimal accuracy on RouterArena}
160
  }
161
  ```
162
 
 
 
 
 
163
  ## Links
164
 
 
165
  - **Library**: https://github.com/codelion/adaptive-classifier
166
  - **RouterArena**: https://routeworks.github.io/
167
  - **RouterArena Paper**: https://arxiv.org/abs/2510.00202
168
+
169
+ ## License
170
+
171
+ MIT License