Seven Mental · 心智七篇
← Knowledge Atlas · Concept

轨迹偏差(Trajectory Bias)

轨迹偏差:约束解码的隐性语义代价,格式合规与语义正确率的疾算衡量,Scha尔 & de Melo (RANLP 2025) 命名
CONCEPT · TRAJECTORY BIAS · CONSTRAINED-DECODING SEMANTIC LOSS · SCHALL & DE MELO 2025

Trajectory Bias

Trajectory Bias — the systematic semantic loss induced by constrained decoding during LLM reasoning

Constrained decoding zeroes out grammar-violating token probabilities at each step and renormalizes. When a JSON format demands a low-probability token (braces, quotes, commas), that renormalization is a large perturbation. LLM generation is sequence-dependent — across many steps, the cumulative perturbation systematically pushes the decoding path toward “prefixes that are structurally easy to keep legal” rather than semantically optimal paths. Format compliance is not task quality.

Differential impact
Instruction-tuned modelsConversational training objective frictions with grammar constraints — the model pursues both, at the cost of semantically suboptimal tokens. Trajectory bias is stronger.
Base modelsNo internal conversational objective, less friction with grammar constraints, better adaptation to structural constraints. A predictor of post-finetune behavior.
Mitigation strategies
CRANE free-reasoning window
Reserve free-text reasoning slots inside the grammar — reason naturally first, then emit the constrained-format final answer
Asymmetric few-shot need
Under constraints, models gain more from extra few-shot examples — they need more explicit in-context guidance
Train-time integration
Inference-time-only constraints are fundamentally misaligned — baking constraints into training is the long-term direction
Symbol-connection tension
Format itself alters thinking — the emergent cost where connectionism meets symbolic constraints at the token level
→ Structured Outputs · System 1 vs 2 · Neurosymbolic AISchall & de Melo (RANLP 2025)

轨迹偏差(Trajectory Bias)

定义

轨迹偏差是约束解码在 LLM 推理过程中引发的一种系统性语义损失。由 Schall & de Melo(RANLP 2025)命名并通过实验证实:即使生成输出在句法上完全合规,约束施加的累积扰动也会系统性地将解码路径推离语义最优方向。

机制

扰动来源

约束解码在每个 token 采样步骤中执行:

  1. 将违反文法约束的 token 概率归零(掩码)
  2. 对剩余合法 token 集合重归一化

当严格格式要求在某个位置只留下低概率的合法 token(如 JSON 中强制输出 {", 等标记)时,重归一化变成一次大扰动:模型在该位置的概率质量被强制重新分配,偏离其自然生成分布。

累积效应

单次扰动影响有限。但 LLM 的生成是序列依赖的——每个 token 的选择影响后续所有 token 的条件概率。跨多步重复扰动后:

  • 解码路径被系统性推向在结构上更容易保持合法的前缀
  • 这些前缀不一定对应语义最正确的推理路径
  • 模型的推理轨迹(token 序列中编码的中间计算过程)在产出最终答案之前已被损坏

日志概率分析

Schall & de Melo 的日志概率分析直接测量了这种扰动:约束解码强迫模型从其偏好的自然语言模式转向低置信度的结构化替代路径。低置信度本身就是语义损失的信号——模型在被迫走一条它认为”不那么对”的路。

差异化的影响

指令微调模型 vs 基础模型

实验在 11 个模型上显示出明显分歧:

指令微调模型(chat/assistant models):

  • 对话训练产生的内部目标与文法约束产生摩擦
  • 模型同时试图满足对话目标和文法边界,代价是生成语义次优 token
  • 轨迹偏差效应更强

基础模型

  • 没有指令微调产生的对话内部目标
  • 与文法约束的摩擦较小
  • 对结构约束适应更好

这一分歧揭示:当前指令微调实践可能无意间削弱了模型的结构化输出能力

Few-shot 示例的非对称需求

约束条件下,模型从额外 few-shot 示例获益的斜率比无约束时更陡。这是轨迹偏差的行为后果:约束剥夺了模型依靠自然语言推理灵活性来补偿错误的能力,必须靠更显式的 in-context 引导来”预偏”推理轨迹。

与推理能力的理论联系

CRANE(Beurer-Kellner et al., 2025)从理论上证明:将输出限制到过于严格的文法(只允许句法合法的最终答案)会减弱模型的推理能力。这为轨迹偏差提供了理论基础:

严格文法约束 → 推理路径空间收窄 → 模型无法在最优推理路径上前进 → 语义正确率下降

CRANE 的解决方案是在文法中保留自由文本推理区间,让模型先完成自然语言推理,再生成约束格式的最终答案。

实践含义

  1. 格式合规率不等于任务质量:评估约束解码效果必须同时测量语义正确率
  2. 提示工程的补偿策略:增加 few-shot 示例、优化 prompt 结构可部分缓解轨迹偏差
  3. 模型选型的预测工具:基础模型在约束条件下的表现可预测其指令微调后的结构化输出能力
  4. 训练时集成的长期方向:仅在推理时施加约束是根本性错位;将约束纳入训练阶段是更优路径
  5. 自由推理区间:CRANE 式设计(先推理后格式化)是在当前范式内缓解轨迹偏差的可操作方案

对符号主义 vs 联结主义的意义

轨迹偏差是联结主义与符号主义在 token 生成级别交汇产生的紧急代价:

  • 联结主义计算优化了流畅自然语言的分布式连续表征
  • 符号约束在输出层面施加离散硬边界结构
  • 格式本身改变了思考过程:模型并非只是”用不同格式写同样答案”,约束在每步的干预累积改变了中间计算路径

这是两种范式单独分析时无法预测的紧急现象,是 ch-07 符号主义与联结主义章节的核心实证案例。

相关概念

References

  • Schall, Maximilian and de Melo, Gerard. “The Hidden Cost of Structure: How Constrained Decoding Affects Language Model Performance.” RANLP 2025, pp. 1074–1084. sources/ranlp-2025-hidden-cost-constrained-decoding.md
  • Beurer-Kellner et al. “CRANE: Reasoning with Constrained LLM Generation.” arXiv:2502.09061, 2025.