Text Classification
Scikit-learn
Joblib
English
llm-routing
model-selection
budget-optimization
nearest-neighbor
Instructions to use JiaqiXue/R2-Router-RouterArena with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use JiaqiXue/R2-Router-RouterArena with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("JiaqiXue/R2-Router-RouterArena", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Fix Quick Start: use snapshot_download for proper import
Browse files
README.md
CHANGED
|
@@ -40,10 +40,17 @@ pip install scikit-learn numpy joblib huggingface_hub
|
|
| 40 |
### Load Pre-trained Checkpoints
|
| 41 |
|
| 42 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
from router import R2Router
|
| 44 |
|
| 45 |
# Load pre-trained KNN checkpoints (no training needed)
|
| 46 |
-
router = R2Router.from_pretrained(
|
| 47 |
|
| 48 |
# Route a query (requires 1024-dim embedding from Qwen3-0.6B)
|
| 49 |
result = router.route(embedding)
|
|
@@ -55,10 +62,16 @@ print(f"Predicted Quality: {result['predicted_quality']:.3f}")
|
|
| 55 |
### Train from Scratch
|
| 56 |
|
| 57 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
from router import R2Router
|
| 59 |
|
| 60 |
# Train KNN from the provided sub_10 training data
|
| 61 |
-
router = R2Router.from_training_data(
|
| 62 |
|
| 63 |
# Route a query
|
| 64 |
result = router.route(embedding)
|
|
|
|
| 40 |
### Load Pre-trained Checkpoints
|
| 41 |
|
| 42 |
```python
|
| 43 |
+
from huggingface_hub import snapshot_download
|
| 44 |
+
import sys
|
| 45 |
+
|
| 46 |
+
# Download model
|
| 47 |
+
path = snapshot_download("JiaqiXue/r2-router")
|
| 48 |
+
sys.path.insert(0, path)
|
| 49 |
+
|
| 50 |
from router import R2Router
|
| 51 |
|
| 52 |
# Load pre-trained KNN checkpoints (no training needed)
|
| 53 |
+
router = R2Router.from_pretrained(path)
|
| 54 |
|
| 55 |
# Route a query (requires 1024-dim embedding from Qwen3-0.6B)
|
| 56 |
result = router.route(embedding)
|
|
|
|
| 62 |
### Train from Scratch
|
| 63 |
|
| 64 |
```python
|
| 65 |
+
from huggingface_hub import snapshot_download
|
| 66 |
+
import sys
|
| 67 |
+
|
| 68 |
+
path = snapshot_download("JiaqiXue/r2-router")
|
| 69 |
+
sys.path.insert(0, path)
|
| 70 |
+
|
| 71 |
from router import R2Router
|
| 72 |
|
| 73 |
# Train KNN from the provided sub_10 training data
|
| 74 |
+
router = R2Router.from_training_data(path, k=80)
|
| 75 |
|
| 76 |
# Route a query
|
| 77 |
result = router.route(embedding)
|