Text Classification
Scikit-learn
Joblib
English
llm-routing
model-selection
budget-optimization
nearest-neighbor
Run this model with HF Jobs
Run JiaqiXue/R2-Router-RouterArena on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/JiaqiXue/R2-Router-RouterArena. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/JiaqiXue/R2-Router-RouterArena on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
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
docs: simplify README, remove GPU/CPU examples
Browse files43 unmodified lines44454647484950515253545556575859606162636465666768697071727374757677787980818283848518 unmodified lines10410510610710810911011111211311411511611711811912012143 unmodified linesuv pip install scikit-learn numpy joblib huggingface_hub vllm```### Complete Example (GPU)```pythonfrom huggingface_hub import snapshot_downloadimport sys# 1. Download routerpath = snapshot_download("JiaqiXue/r2-router")sys.path.insert(0, path)from router import R2Router# 2. Load pre-trained KNN checkpointsrouter = R2Router.from_pretrained(path)# 3. Route a query (auto-embeds with Qwen3-0.6B via vLLM)result = router.route_text("What is the capital of France?")print(f"Model: {result['model_full_name']}")print(f"Token Budget: {result['token_limit']}")print(f"Predicted Quality: {result['predicted_quality']:.3f}")````route_text()` automatically loads Qwen3-0.6B via vLLM on first call and caches it. Batch routing is also supported:```pythonqueries = ["What is the capital of France?","Write a Python function to sort a list","Translate 'hello' to Japanese",]results = router.route_text(queries)for q, r in zip(queries, results):print(f"{q[:40]:40s} -> {r['model']} (budget={r['token_limit']})")```### With vLLM Server (Recommended for Production)Start the embedding server once, then route from any process without reloading the model:18 unmodified linesprint(f"Model: {result['model_full_name']}, Budget: {result['token_limit']}")```### CPU-Only (No GPU)If you don't have a GPU, provide pre-computed embeddings directly:```pythonrouter = R2Router.from_pretrained(path)# Your own 1024-dim embedding (e.g., from an API or pre-computed)embedding = np.random.randn(1024) # replace with real embeddingresult = router.route(embedding)```### Adjusting Lambda (Cost-Accuracy Tradeoff)The `lambda` parameter controls the tradeoff between accuracy and cost:43 unmodified lines4445464748495018 unmodified lines69707172737443 unmodified linesuv pip install scikit-learn numpy joblib huggingface_hub vllm```### With vLLM Server (Recommended)Start the embedding server once, then route from any process without reloading the model:18 unmodified linesprint(f"Model: {result['model_full_name']}, Budget: {result['token_limit']}")```### Adjusting Lambda (Cost-Accuracy Tradeoff)The `lambda` parameter controls the tradeoff between accuracy and cost:
README.md+1-48