判斷一則請求與工作有沒有關係。這是 LLM 成本路由的第一道關卡:
判為 not_work_related 的請求會直接被擋下,不會呼叫任何語言模型。
work_related / not_work_relatedxlm-roberta-base在企業把請求送進昂貴的雲端大模型之前先判斷一次,避免兩種常見浪費: 用最貴的模型做分類、翻譯、單位換算這種小事;以及拿公司的 LLM 額度做與工作無關的事。
整個判斷在本地完成,不需要任何 API 金鑰,請求內容也不會送往第三方。
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
repo = "GOSHUNCLE/llm-router-relevance-gate"
tok = AutoTokenizer.from_pretrained(repo)
mdl = AutoModelForSequenceClassification.from_pretrained(repo).eval()
text = "分析 SMT 錫橋良率異常的可能根因並提出改善建議"
inputs = tok(text, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
probs = torch.softmax(mdl(**inputs).logits, dim=-1)[0]
idx = int(probs.argmax())
print(mdl.config.id2label[idx], float(probs[idx]))
若判為 work_related,接著才會交給第二段的
難度路由模型 決定要用貴的還是便宜的模型。
| 階段 | 模型 | 標籤 |
|---|---|---|
| 第一段 相關性守門 | GOSHUNCLE/llm-router-relevance-gate | work_related / not_work_related |
| 第二段 難度路由 | GOSHUNCLE/llm-router-complexity | simple / complex |
完整的路由邏輯(含關鍵詞規則)、可直接試玩的 Demo、訓練腳本與資料集,都在 GOSHUNCLE/liang-task-router。
模板式合成資料,電子製造業情境、中英混合,不需要任何模型或金鑰即可重現
(training/generate_synthetic.py,固定 seed):
stage1.jsonl — 2,000 筆,work_related / not_work_related 各半stage2.jsonl — 1,000 筆,simple / complex 各半資料不含任何個人資料、公司名稱或真實使用者語料。
以 xlm-roberta-base 微調:4 epochs、learning rate 2e-5、batch size 16、max length 256,
資料切分 80 / 10 / 10(train / validation / test),依 Macro-F1 選最佳 checkpoint。
simple。Apache License 2.0。基礎模型 xlm-roberta-base 為 MIT 授權。
Stage 1 of a two-stage LLM cost router: decides whether a request is work-related.
Requests classified as not_work_related are blocked before any LLM is called.
Fine-tuned from xlm-roberta-base on synthetic, template-generated data
(electronics-manufacturing scenarios, mixed Chinese/English).
No human-labeled benchmark exists yet, so no accuracy figures are claimed.
See the demo Space for the full
routing logic (keyword rules + both stages), training scripts and dataset.
Licensed under Apache-2.0; base model xlm-roberta-base is MIT.
model.safetensors 1.1 GBonnx/model_quantized.onnx 279 MB