Alben (ONNX)

Alben 的 ONNX 版本 —— 不需要 PyTorch,也不需要 Python。

适合:Node.js / 边缘设备 / 小容器 / 任何有 onnxruntime 的运行环境。

内容

文件 说明
alben-encoder.onnx + .data 编码塔(约 91 MB,含外部权重)
tokenizer/ 分词器(与 Python 侧逐 id 一致)
onnx_meta.json 标定温度等元数据

用法(Node.js)

npm install @alben/node onnxruntime-node
import { OnnxScorer } from "@alben/node";
const s = await OnnxScorer.create("./alben-onnx");
const r = await s.scoreOptions("charged twice, refund please",
  { billing: "refunds", tech: "bugs" }, "Which team?");
console.log(r.choice, r.confidence);

用法(Python,不装 torch)

pip install onnxruntime tokenizers numpy
from alben.onnx_runtime import OnnxScorer
s = OnnxScorer("./alben-onnx");
r = s.score_options("charged twice, refund please",
                     {"billing": "refunds", "tech": "bugs"},
                     instructions="Which team?");
print(r.choice, r.confidence, r.probabilities);

★ 打分数学(四步,一个都不能漏)

1. 选项文本 = instructions + "\n" + description
2. logits   = state · option * TEMPERATURE(20.0)
3. probs    = softmax(logits / calibration_temperature)
4. confidence = peak_confidence(probs)

calibration_temperature 从 onnx_meta.json 读。 漏掉 2、3 时:「选项全对,但概率差 0.54、置信差 0.81」—— 实测过。

一致性

与 PyTorch 侧逐位对齐:句向量最大绝对误差 2.7e-07, 端到端决策 7/7 选项相同、概率差 0.0000。

许可

Apache-2.0。编码器属 BAAI,MIT,此处为导出物。

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Space using AlbenW/alben-onnx 1