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
Fix Quick Start: complete runnable example with embedding generation
Browse files33 unmodified lines3435363738394041424344454647484950515253545556575811 unmodified lines7071727374757677787980818283848586878889909133 unmodified lines### Installation```bashpip install scikit-learn numpy joblib huggingface_hub```### Load Pre-trained Checkpoints```pythonfrom huggingface_hub import snapshot_downloadimport sys# Download modelpath = snapshot_download("JiaqiXue/r2-router")sys.path.insert(0, path)from router import R2Router# Load pre-trained KNN checkpoints (no training needed)router = R2Router.from_pretrained(path)# Route a query (requires 1024-dim embedding from Qwen3-0.6B)result = router.route(embedding)print(f"Model: {result['model_full_name']}")print(f"Token Budget: {result['token_limit']}")11 unmodified linesfrom router import R2Router# Train KNN from the provided sub_10 training datarouter = R2Router.from_training_data(path, k=80)# Route a queryresult = router.route(embedding)```### Get Query EmbeddingsR2-Router uses [Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B) embeddings (1024-dim). You can generate them with:```pythonfrom sentence_transformers import SentenceTransformermodel = SentenceTransformer("Qwen/Qwen3-0.6B")embedding = model.encode("What is the capital of France?")```Or with vLLM for faster batch inference:33 unmodified lines34353637383940414243444546474849505152535455565758596061626311 unmodified lines757677787980818283848586878889909133 unmodified lines### Installation```bashpip install scikit-learn numpy joblib huggingface_hub sentence-transformers```### Complete Example```pythonfrom huggingface_hub import snapshot_downloadfrom sentence_transformers import SentenceTransformerimport 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. Embed your query with Qwen3-0.6B (1024-dim)embedder = SentenceTransformer("Qwen/Qwen3-0.6B")embedding = embedder.encode("What is the capital of France?")# 4. Route!result = router.route(embedding)print(f"Model: {result['model_full_name']}")print(f"Token Budget: {result['token_limit']}")11 unmodified linesfrom router import R2Router# Train KNN from the provided sub_10 training data (custom hyperparameters)router = R2Router.from_training_data(path, k=80)```### Alternative: vLLM Embeddings (Faster for Batches)```pythonfrom vllm import LLMllm = LLM(model="Qwen/Qwen3-0.6B", runner="pooling")outputs = llm.embed(["What is the capital of France?"])embedding = outputs[0].outputs.embedding```Or with vLLM for faster batch inference:
README.md+16-16