Scikit-learn
Joblib
English
protocol-routing
llm-routing
multi-agent-systems
cost-aware-inference
protocol-selection
calibration
reasoning
reproducibility
emnlp2026
Instructions to use AgentsSci/EMNLP_Cost-Aware-Protocol-Routing with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use AgentsSci/EMNLP_Cost-Aware-Protocol-Routing with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("AgentsSci/EMNLP_Cost-Aware-Protocol-Routing", "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
Add pretty_name, quiet the version-warning wall in the example, and record the root widget copy's checksum
Browse files
README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
library_name: sklearn
|
|
|
|
| 4 |
# A real checkpoint ships here: router_metadata_only/model.joblib, with its
|
| 5 |
# fitted feature builders, an explicit label map, and a runnable example.
|
| 6 |
# `inference: false` because this is a local scikit-learn artifact -- there is
|
|
@@ -72,6 +73,9 @@ explicit label map, held-out predictions, and a runnable example.
|
|
| 72 |
|
| 73 |
A byte-identical copy of `model.joblib` also sits at the repository root as
|
| 74 |
`sklearn_model.joblib`, purely so Hugging Face's auto-generated snippet resolves.
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
```bash
|
| 77 |
pip install scikit-learn pandas scipy joblib
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
library_name: sklearn
|
| 4 |
+
pretty_name: "Cost-Aware Protocol Routing: Metadata-Only Protocol Router"
|
| 5 |
# A real checkpoint ships here: router_metadata_only/model.joblib, with its
|
| 6 |
# fitted feature builders, an explicit label map, and a runnable example.
|
| 7 |
# `inference: false` because this is a local scikit-learn artifact -- there is
|
|
|
|
| 73 |
|
| 74 |
A byte-identical copy of `model.joblib` also sits at the repository root as
|
| 75 |
`sklearn_model.joblib`, purely so Hugging Face's auto-generated snippet resolves.
|
| 76 |
+
`router_metadata_only/model_metadata.json` records the SHA-256 of both, so the
|
| 77 |
+
two cannot drift apart unnoticed: if they ever disagree, the one under
|
| 78 |
+
`router_metadata_only/` is canonical.
|
| 79 |
|
| 80 |
```bash
|
| 81 |
pip install scikit-learn pandas scipy joblib
|
router_metadata_only/model_metadata.json
CHANGED
|
@@ -88,5 +88,11 @@
|
|
| 88 |
"bytes": 17241,
|
| 89 |
"sha256": "5bcb554174f5cc34588d201938835473170c1c57154718dfede792341fcf3ee1"
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
}
|
|
|
|
| 88 |
"bytes": 17241,
|
| 89 |
"sha256": "5bcb554174f5cc34588d201938835473170c1c57154718dfede792341fcf3ee1"
|
| 90 |
}
|
| 91 |
+
},
|
| 92 |
+
"root_widget_copy": {
|
| 93 |
+
"path": "sklearn_model.joblib",
|
| 94 |
+
"purpose": "byte-identical duplicate so Hugging Face's auto-generated sklearn snippet resolves",
|
| 95 |
+
"canonical": "router_metadata_only/model.joblib",
|
| 96 |
+
"sha256": "63b5358423b430b39f2a586913d48bf84f2b6774cda78bf1bc383c76de7f0c3b"
|
| 97 |
}
|
| 98 |
}
|
router_metadata_only/predict_example.py
CHANGED
|
@@ -15,6 +15,8 @@ from __future__ import annotations
|
|
| 15 |
import json
|
| 16 |
from pathlib import Path
|
| 17 |
|
|
|
|
|
|
|
| 18 |
import joblib
|
| 19 |
import pandas as pd
|
| 20 |
from scipy import sparse
|
|
@@ -25,10 +27,41 @@ HERE = Path(__file__).resolve().parent
|
|
| 25 |
# Decode with this file, not with sorted(labels): the order is the paper's fixed
|
| 26 |
# cost order, and alphabetical decoding disagrees with the released predictions
|
| 27 |
# on 71 of 423 test rows while looking perfectly plausible.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
MAPPING = json.loads((HERE / "label_mapping.json").read_text())
|
| 29 |
INDEX_TO_LABEL = {int(k): v for k, v in MAPPING["index_to_label"].items()}
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def load():
|
| 33 |
return (
|
| 34 |
joblib.load(HERE / "model.joblib"),
|
|
@@ -62,6 +95,7 @@ def build_features(df: pd.DataFrame, builders: dict):
|
|
| 62 |
|
| 63 |
|
| 64 |
def main() -> None:
|
|
|
|
| 65 |
model, builders = load()
|
| 66 |
|
| 67 |
# Three made-up problems, in the schema the router expects.
|
|
|
|
| 15 |
import json
|
| 16 |
from pathlib import Path
|
| 17 |
|
| 18 |
+
import warnings
|
| 19 |
+
|
| 20 |
import joblib
|
| 21 |
import pandas as pd
|
| 22 |
from scipy import sparse
|
|
|
|
| 27 |
# Decode with this file, not with sorted(labels): the order is the paper's fixed
|
| 28 |
# cost order, and alphabetical decoding disagrees with the released predictions
|
| 29 |
# on 71 of 423 test rows while looking perfectly plausible.
|
| 30 |
+
#: The scikit-learn version this checkpoint was fitted under, recorded in
|
| 31 |
+
#: model_metadata.json. Used only to phrase the version note accurately.
|
| 32 |
+
FITTED_WITH = "1.8.0"
|
| 33 |
+
|
| 34 |
MAPPING = json.loads((HERE / "label_mapping.json").read_text())
|
| 35 |
INDEX_TO_LABEL = {int(k): v for k, v in MAPPING["index_to_label"].items()}
|
| 36 |
|
| 37 |
|
| 38 |
+
def _quiet_version_warning():
|
| 39 |
+
"""Silence the version-mismatch warning, after saying it out loud once.
|
| 40 |
+
|
| 41 |
+
The estimator was pickled under scikit-learn 1.8.0. Loading it under any
|
| 42 |
+
other version makes scikit-learn emit an InconsistentVersionWarning for
|
| 43 |
+
EVERY unpickled object -- here that is twelve lines of traceback-looking
|
| 44 |
+
text, including the reader's own filesystem paths, before a single line of
|
| 45 |
+
output. That reads like a broken artifact.
|
| 46 |
+
|
| 47 |
+
It is not suppressed silently: one plain sentence replaces the wall, so the
|
| 48 |
+
reader still learns the fact the warning was trying to convey.
|
| 49 |
+
"""
|
| 50 |
+
try:
|
| 51 |
+
from sklearn.exceptions import InconsistentVersionWarning
|
| 52 |
+
except ImportError: # very old scikit-learn: no such class
|
| 53 |
+
return
|
| 54 |
+
import sklearn
|
| 55 |
+
if sklearn.__version__ != FITTED_WITH:
|
| 56 |
+
print(
|
| 57 |
+
f"note: this checkpoint was fitted with scikit-learn {FITTED_WITH}; "
|
| 58 |
+
f"you are running {sklearn.__version__}.\n"
|
| 59 |
+
" predict() is expected to work. If you need exact "
|
| 60 |
+
"probabilities, match the fitted version or retrain.\n"
|
| 61 |
+
)
|
| 62 |
+
warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
def load():
|
| 66 |
return (
|
| 67 |
joblib.load(HERE / "model.joblib"),
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
def main() -> None:
|
| 98 |
+
_quiet_version_warning()
|
| 99 |
model, builders = load()
|
| 100 |
|
| 101 |
# Three made-up problems, in the schema the router expects.
|