DeepSeek-OCR2的Causal Flow Query究竟学到了什么顺序?

实验代码: DeepSeek-OCR2-query-ablation

把 2D 图像按固定raster-scan展平成 1D 序列会带来不合理的归纳偏置,忽略语义关系;DeepSeek-OCR 2 试图用 DeepEncoder V2 让视觉 token 能按语义动态重排,走向更类似人的视觉编码。然而,在DeepSeek-OCR 2的论文中,没有针对causal query token携带的信息以及其真正学习到的顺序进行分析,因此本文试图通过一些小实验探究causal query token的作用以及其学习到的order。用两类可操作的探针去验证“学到的顺序是什么”: (1)看encoder部分 attention 激活模式;(2)对 query token 做置换/打乱干预,观察顺序敏感性与输出变化。通过几个例子,本文发现query token学到的顺序更接近raster-scan-order。

DeepSeek-OCR2架构

DeepSeek-OCR 2 的核心组件是 DeepEncoder V2。它引入一组带因果约束的 causal query,将二维图像网格上的 image tokens 重新采样为一条1D因果的的 query token 序列,整体思路与 Q-Former用 query 去聚合视觉特征的做法相近。最主要的区别体现在因果性:

  • 在 encoder 中,每个位置的 query token 只能关注到“自己之前”的 token(不能看未来的query token),从而形成一种从前到后的信息流;
  • 在 decoder 中,来自 encoder 的 query token 同样遵循“只能看前文”的约束,使得后续生成更依赖这条单向的视觉信息流。

这种设计被论文称为causal visual flow:希望模型在内部形成更贴近阅读顺序/结构推理的视觉流动路径。

DeepSeek-OCR 2 网络架构

DeepSeek-OCR2网络架构

DeepEncoder 的注意力掩码

DeepEncoder部分的attention mask

DeepEncoder attention 激活模式

实验设置:我选取了两类示例图片(PPT 与春联),将输入统一 resize + padding 到 1024×1024。随后用 SAM 编码得到 256 个 image tokens,并将其送入Qwen2 LLM vision encoder进行处理。实验中只保留 global view feature,以减少其它因素干扰。

观测方法:记录网络最后两层中,query tokens 对 image tokens 的 attention 权重;对权重重新做归一化后,绘制 attention 热力图,并计算 attention 的“质心”(用来粗略刻画每个 query 更“看向”图像的哪个区域)。

测试结果在下面的两个视频中,用红色框标注 attention 的权重激活区域,颜色越深表示权重越高;蓝色点表示 attention 的质心;绿色框则是对高激活区域进行聚合后得到的外接矩形。

注意力可视化 1
注意力可视化 2

主要现象:

  1. 几乎每个 query token 都对第一个 image token 表现出偏高的注意力,这与常见的 attention sink 现象相似;
  2. 整体激活轨迹与 raster-scan order较为接近;
  3. 在序列末端,少数 query token 会再次“回看”图像开头区域,表现为注意力重新聚焦到前部 token。

Decoder 部分 query 替换分析

为了测试 decoder 对 query token 序列顺序的敏感性,在解码前对 query 序列做了几种置换,并统一使用确定性解码(do_sample=False):

  • 操作1:将后 128 个query token替换为另一张图的前 128 个query token;
  • 操作2:将前 128 个 query tokens 复制到后 128 个;
  • 操作3:对query token序列随机打乱;
  • 操作4:交换前 128 与后 128个query token;

实验结果-对联图片

用于 OCR 实验的春联图片

baseline(未进行任何query token操作)

马年吉祥

金马奔腾开放景

玉羊启泰展宏图

豆包AI生成

操作1:将后 128 个替换为另一张图的前 128 个

# 马年吉祥

- **Human Factors**
  - the process molds to the needs of the people and team, not the other way around
  - key traits must exist among the people on an agile team and the team itself:
    - Competence.
    - Common focus.
    - Collaboration.
    - 五羊启泰

- 金马奔腾
- 玉羊启泰

操作2:将前 128 个 query tokens 复制到后 128 个;

马年吉祥
金马奔腾
玉羊启瑞
玉羊启瑞

操作3:对序列随机打乱;

马年吉祥

金马奔腾开放景

玉羊启泰展宏图

豆AI生成

操作4:交换前 128 与后 128;

马年吉祥

金马奔腾开盛景

玉羊启泰展宏图

豆包AI生成

实验结果-图片2

用于 OCR 实验的 Human Factors 幻灯片

baseline

- **Human Factors**

  - the process molds to the needs of the people and team, not the other way around
  - key traits must exist among the people on an agile team and the team itself:
    - **Competence.**
    - **Common focus.**
    - **Collaboration.**
    - **Decision-making ability.**
    - **Fuzzy problem-solving ability.**
    - **Mutual trust and respect.**
    - **Self-organization.**

操作1:将后 128 个替换为另一张图的前 128 个

# 马年吉祥

- the process molds to the needs of the people and team, not the other way around
- key traits must exist among the people on an agile team and the team itself:
  - Competence.
  - Common focus.
  - Collaboration.
  - 玉羊启瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞启瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞瑞启

操作2:将前 128 个 query tokens 复制到后 128 个;

- **Human Factors**

  - the process molds to the needs of the people and team, not the other way around
  - key traits must exist among the people on an agile team and the team itself:
    - Competence.
    - Common focus.
    - Collaboration.
    - Collaboration.
    - Common focus.
    - Collaboration.
    - Common focus.
    - Collaboration.
    - Common focus.
    - Collaboration.
    - Common focus.

操作3:对序列随机打乱;

- **Human Factors**

  - the process of the people and their way around
    - key traits must be present in the people and the way they work
    - self-organisation

  - competence
  - focus
  - collaboration
  - decision-making ability
  - mutual respect
  - common sense
  - fuzzy thinking
  - self-organisation

8

操作4:交换前 128 与后 128;

- **Human Factors**

  - the process molds to the needs of the people and team, not the other way around

  - key traits must exist among the people on an agile team and the team itself:
    - Competence.
    - Common focus.
    - Collaboration.
    - Decision-making ability.
    - Fuzzy problem-solving ability.
    - Mutual trust and respect.
    - Self-organization.

实验现象:

  • 多数情况下,query token 的顺序与 raster-scan-order 的对应关系依然很强;
  • 在春联样例上,shuffle 对最终 OCR 结果影响不大;在另一类样例上,即便产生影响,也更多体现为语义轻微扰动而非结构性崩坏。

这说明 query tokens 里可能编码了某种位置信号/遍历先验,使得 decoder 并不完全依赖“严格的序列顺序”来恢复结果。

总结

综合上述两组观察,我目前更倾向于认为:DeepSeek-OCR 2 中这条 因果流(causal flow)上的 query tokens 学到的顺序,与 raster-scan-order 基本一致。因此,它所带来的收益未必来自“显式学会了人类阅读顺序的重排”。