arXiv:2602.00746cs.SEcs.CV2026-02被引 5

用图像压缩代码让大模型更好理解长段代码。

Can Vision-Language Models Handle Long-Context Code? An Empirical Study on Visual Compression

  • 将代码转为图像序列,避免文本压缩导致的依赖断裂。
  • 在100万词上下文下,准确率比现有方法高4倍,压缩效率提升4倍。
  • 适合需要全局理解的任务,如代码摘要和问答。

大型语言模型因上下文窗口限制难以处理长代码。现有文本压缩方法虽能缓解,但常破坏依赖关系,造成语义碎片。为此,我们提出LongCodeOCR,一种将代码渲染为二维图像序列的视觉压缩框架,供视觉语言模型处理。该方法保持全局视图,避免过滤带来的依赖断裂。我们在四个基准上系统评估LongCodeOCR与当前最优方法LongCodeZip的表现,涵盖代码摘要、问答和补全任务。结果表明,视觉压缩在需全局理解的任务中具备可行性:在约1.7倍压缩比下,LongCodeOCR在长模块摘要任务上的CompScore较LongCodeZip提升36.85分;在100万词上下文长度下,使用90亿参数专用视觉语言模型Glyph时,LongCodeOCR准确率更高,且压缩效率达4倍;同时,压缩阶段延迟从约4.3小时降至约1分钟(100万词)。最终,研究揭示了覆盖率与保真度的根本权衡:视觉压缩更利于保留全局依赖,但在精确性要求高的任务上存在保真瓶颈;而文本压缩虽保符号级精度,却牺牲结构覆盖范围。

原文摘要 · Abstract (English)

Large Language Models (LLMs) struggle with long-context code due to window limitations. Existing textual code compression methods mitigate this via selective filtering but often disrupt dependency closure, causing semantic fragmentation. To address this, we introduce LongCodeOCR, a visual compression framework that renders code into compressed two-dimensional image sequences for Vision-Language Models (VLMs). By preserving a global view, this approach avoids the dependency breakage inherent in filtering. We systematically evaluate LongCodeOCR against the state-of-the-art LongCodeZip across four benchmarks spanning code summarization, code question answering, and code completion. Our results demonstrate that visual code compression serves as a viable alternative for tasks requiring global understanding. At comparable compression ratios ($\sim$1.7$\times$), LongCodeOCR improves CompScore on Long Module Summarization by 36.85 points over LongCodeZip. At a 1M-token context length with Glyph (a specialized 9B VLM), LongCodeOCR maintains higher accuracy than LongCodeZip while operating at about 4$\times$ higher compression. Moreover, compared with LongCodeZip, LongCodeOCR drastically reduces compression-stage overhead (reducing latency from $\sim$4.3 hours to $\sim$1 minute at 1M tokens). Finally, our results characterize a fundamental coverage--fidelity trade-off: visual code compression retains broader context coverage to support global dependencies, yet faces fidelity bottlenecks on exactness-critical tasks; by contrast, textual code compression preserves symbol-level precision while sacrificing structural coverage.

代码理解视觉语言模型长上下文压缩

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。