跳转至

诺基亚开源 AnyJev:零训练让任何开源大模型转变为精准校准的结构化决策模型

Nokia Open-Sources AnyJev: A Training-Free Layer That Turns Any Open LLM Into a Calibrated Decision Model

文章背景与核心概要

在工业界大语言模型 (Large Language Model, LLM) 的实际落地中,绝大多数业务本质上属于从固定选项中选择答案的结构化决策,例如客服路由、意图分类与合规审查,而无需生成冗长的自由文本。然而,直接读取模型的下一个 Token 概率不仅极易受选项排列顺序的干扰,其置信度也严重失真、缺乏统计校准。为此,Nokia 应用研究团队开源了轻量级 Python 库 AnyJev。该工具无需任何参数微调或模型训练,仅通过优雅的循环排列与运行期动态先验校正,便能让主流开源大模型即插即用地转变为高精度、概率可靠的结构化决策模型。基准测试表明,AnyJev 显著消除了位置偏置与先验偏置,在极其严苛的 5% 误差控制下,将模型的可自动决策比例从 7.7% 大幅提升至 52.0%,为企业构建高可靠自动化业务流提供了强有力的生产级保障。


核心摘要

Summary

Nokia 应用研究团队正式开源了 Python 库 AnyJev。该工具无需任何二次微调与训练,便能将各类开源大语言模型 (Large Language Model, LLM) 改造为经过精准校准的结构化决策模型。AnyJev 目前已发布至 PyPI 并遵循 Apache-2.0 开源协议,专为工业生产中“从固定选项集中挑选最佳答案”而非“发散生成自由文本”的分类与决策场景量身定制。通过创新的循环排列 (Cyclic Shifts) 与批次动态校准技术,AnyJev 有效攻克了困扰大模型分类的先验偏置 (Prior Bias) 与位置偏置 (Position Bias) 顽疾,在显著提升决策准确率与稳定性的同时,大幅降低了预期校准误差 (Expected Calibration Error, ECE) 。

Nokia’s applied research team has released AnyJev, an open-source Python library designed to transform any open-source Large Language Model (LLM) into a calibrated decision model without requiring any training. Available on PyPI under the Apache-2.0 license, AnyJev is optimized for production tasks that require selecting an answer from a fixed set of options rather than generating free-form text. By addressing common pitfalls like prior bias and position bias through advanced cyclic shifts and batch calibration, AnyJev significantly improves model accuracy, stability, and calibration error (ECE).


什么是 AnyJev?

What is AnyJev?

AnyJev 借鉴并沿用了 TypeSafe AI 旗下的 System One 决策模型 Jev 的接口设计规范。开发者只需传入一个强类型的结构化问题,系统便能直接输出结构化决策结果,并附带可信度极高的置信概率。这一概率值直接从大模型输出层的下一个 Token 概率分布中提取,整个过程完全摆脱了冗长的文本生成、繁琐的正则解析或额外的参数训练。

AnyJev borrows its interface from Jev, the System One decision model launched by TypeSafe AI. It allows developers to input a typed question and receive a structured decision paired with a dependable probability threshold. This probability is extracted directly from the model's next-token distribution without generating text, parsing outputs, or performing training.

该库原生支持三类核心决策问题: * choice:从预先设定的 \(K\) 个候选选项中挑选出单一最佳答案。 * noul:二元“是/否”判定查询。 * score:将预测答案归类到若干有序的数值或类别区间 (分箱) 中。

The library natively supports three primary question types: * choice: Selects a single option from a predefined set of \(K\) alternatives. * noul: A binary yes/no query. * score: Categorizes the answer into one of several ordered numerical or categorical bins.


直接读取 Logits 的致命缺陷

The Problem With Reading Logits Directly

在传统工程实践中,许多人习惯通过限制大模型仅输出特定的选项标签,进而直接读取并比较对应 Token 的原始得分 (Logits) 。然而,Nokia 研究团队指出,这种看似省事的“走捷径”做法存在两大严重缺陷:

  1. 顺序极度敏感 (Order Sensitivity):仅仅改变选项在提示词中的排列先后顺序,模型的最终选择就可能发生彻底反转;
  2. 概率失真严重 (Poor Calibration):直接计算出的置信概率往往过度自信或偏差过大,缺乏统计学上的真实可信度。

Many existing workflows restrict the model's next-token generation to explicit option labels to read their raw scores. However, the Nokia research team highlights two major flaws with this shortcut: 1. Order Sensitivity: The model's selected answer can completely change simply by reordering the options. 2. Poor Calibration: The resulting probabilities are unreliable and uncalibrated.

官方技术文档指出,这些根本问题源于大模型固有的两大偏置机制:

  • 先验偏置 (Prior Bias):无论上下文语境为何,模型内在更偏好特定的文本标签(例如天然更倾向于输出“Yes”而非“No”);
  • 位置偏置 (Position Bias):模型往往对选项列表中的特定排位(例如首项或末项等视觉位置)产生天然的选择偏好。

According to the official documentation, these issues stem from two primary biases: * Prior Bias: The model inherently favors specific labels (such as "Yes" over "No") regardless of the context. * Position Bias: The model favors specific visual slots or positions within the option list.


AnyJev 的工作机制:L0 与 L1 双层校准

How AnyJev Works: L0 and L1

该库生成的每一次决策结果都包含一个 level 字段,用于指定所采用的校准深度:

Every decision generated by the library includes a level field that dictates the calibration depth:

L0 级校准 (零标注数据,默认启用)

L0 (Zero Labels, Enabled by Default)

L0 模式无需任何人工标注数据,依靠两套内置的无监督机制消除模型偏置:

  • 循环轮转 (Cyclic Shifts):对于包含 \(K\) 个候选选项的问题,系统将其依次轮转排列 \(K\) 次,确保每一个选项都能在每个排位上精确出现一次。随后在对数空间内计算各次分布的几何平均值,从而从数学上彻底抵消累加性的位置偏置;
  • 先验校正 (Prior Correction):AnyJev 实时追踪生产流量预测分布的滑动平均值,在连续处理完前 8 个请求后自动激活,以 0.75 的预设强度动态扣除模型固有的先验偏置。

L0 addresses model biases using two built-in mechanisms: * Cyclic Shifts: For a question containing \(K\) options, the list is displayed in \(K\) distinct rotations, ensuring every option occupies every position exactly once. The resulting probability distributions are combined in log space as a geometric mean, effectively neutralizing additive position bias. * Prior Correction: AnyJev utilizes a running mean of predicted distributions on live inputs to dynamically subtract out prior bias at a strength of 0.75 (activating after processing the first 8 items).

性能开销: L0 在每次决策时需要执行 \(K\) 次预填充 (Prefill) 前向传递,得益于共享前缀批处理优化,推理开销得到了极好的控制。在单张 H100 GPU 上,当选项数 \(K = 20\) 且批处理大小 (Batch Size) 为 32 时,单次决策平均仅耗时约 0.25 秒。

Performance Cost: L0 requires \(K\) prefill passes per decision, efficiently batched over a shared prefix. On a single H100 GPU with \(K = 20\) at a batch size of 32, this takes roughly 0.25 seconds per decision.

L1 级校准 (每个问题需 100 至 500 条标注样本)

L1 (100 to 500 Labels per Question)

L1 级校准在 L0 的基础之上进一步融入了温度缩放 (Temperature Scaling) 算法。拟合得到的校准参数会被保存为一个轻量级的 JSON 文件;它可以在完全不改变候选答案相对排序的前提下,进一步精细重塑置信度数值分布,使概率输出更加严谨贴近真实胜率。

L1 builds upon L0 by incorporating temperature scaling. The fitted parameters are saved as a lightweight JSON artifact, refining confidence metrics without altering the fundamental ranking of the answers.


基准测试评估结果

Benchmark Results

在基于 Qwen3-8B 模型与 BANKING77 数据集 (20 类意图分类任务,包含 300 个测试样本) 的严苛评测中,AnyJev 展现出了极为显著的性能飞跃:

Evaluated on Qwen3-8B using the BANKING77 dataset (20-way classification, 300 test items), AnyJev demonstrates substantial performance gains:

评测指标 原始 Logits AnyJev L0 AnyJev L1
所需标注样本数 0 0 100 至 500
选项逆序时的答案翻转率 0.230 0.073 0.077
准确率 0.747 0.803 0.807
预期校准误差 (ECE) 0.240 0.184 0.095
5% 误差控制下的可自动决策比例 7.7% 46.3% 52.0%
Metric Raw logits AnyJev L0 AnyJev L1
Labels required 0 0 100 to 500
Flip rate when options reversed 0.230 0.073 0.077
Accuracy 0.747 0.803 0.807
Calibration error (ECE) 0.240 0.184 0.095
Auto-decidable at 5% error 7.7% 46.3% 52.0%

更多测试亮点

Additional Highlights

  • 在全部 9 种经过评测的“模型-任务”配置中,L0 模式均成功大幅降低了选项重排导致的答案翻转率;
  • 在专业的类型化决策任务中,搭载 L1 的 Qwen3-32B 创下了 0.036 的超低预期校准误差 (ECE) ,性能远超公开文献中 Jev 基线的 0.144;
  • 该框架已在多种不同架构的开源模型上完成全面验证,涵盖 Qwen、OLMo、Granite、Phi 以及 Mistral 等主流模型家族;
  • Nokia 内部在生产环境工单路由等关键业务上的实测验证中,同样取得了极具前景的落地成果。
  • L0 successfully reduced order-flipping across all 9 evaluated model-and-task configurations.
  • On specialized typed-decision tasks, Qwen3-32B with L1 achieved an Expected Calibration Error (ECE) of 0.036 (outperforming the published Jev baseline of 0.144).
  • The framework has been successfully validated across diverse architectures, including Qwen, OLMo, Granite, Phi, and Mistral models.
  • Nokia's internal testing on production routing tasks has shown highly promising results.

如何上手使用 AnyJev

How to Use AnyJev

# pip install "anyjev[hf]"
from anyjev import Decider, Question
from anyjev.backends.hf import HFBackend

d = Decider(HFBackend("Qwen/Qwen3-8B"))
route = Question.choice("Which team should handle this?",
                        ["billing", "technical", "sales", "other"], name="route")
r = d.decide({"conversation": [...]}, [route])
r["route"].distribution   # probabilities per option

对于企业级高吞吐量推理服务,只需开启前缀缓存 (Prefix Caching) 并初始化 vLLM,即可通过内置的 VLLMBackend 驱动后端实现无缝集成与极速推理。

For high-throughput enterprise serving, you can initialize vLLM with prefix caching enabled and couple it directly with the VLLMBackend integration.


核心总结

Key Takeaways

  • 零训练即插即用:无需任何参数微调,即可瞬间将开源大模型转变为高性能、Jev 风格的类型化决策模型;
  • 全面消除模型偏置:巧妙结合循环轮转与批次动态先验校正,一举化解了长期困扰大模型分类的位置偏置与标签偏置;
  • 翻转率显著降低:在基于 Qwen3-8B 的 BANKING77 测试中,选项顺序调换导致的答案翻转率从 0.230 骤降至 0.073;
  • 生产环境真正就绪:在设定为 5% 的严苛错误容忍阈值下,借助 L1 校准可将业务流量中可全自动放行决策的比例从 7.7% 大幅推升至 52.0%;
  • 开放开源生态:代码基于 Apache-2.0 协议完全开源,已上架 PyPI,并原生提供对 Hugging Face 与 vLLM 高性能推理引擎的开箱即用支持。
  • Training-Free Integration: Converts open-source LLMs into high-performance, Jev-style typed decision models instantly.
  • Robust Bias Mitigation: Leverages cyclic shifts and batch-level priors to eliminate position and label biases.
  • Significant Error Reduction: On Qwen3-8B (BANKING77), order-flip rates drop drastically from 0.230 to 0.073.
  • Production Ready: Auto-decidable traffic at a strict 5% error margin increases from 7.7% to 52.0% when utilizing L1.
  • Open Source: Freely available under the Apache-2.0 license via PyPI with built-in Hugging Face and vLLM backends.