按年被提到
20232023 · 4 次2026
软件工程与 AI 编程›代码生成与程序合成·arXiv:2306.10763 · cs.CL

Guiding Language Models of Code with Global Context using Monitors

用监视器为代码语言模型提供全局上下文引导
Lakshya A Agrawal, Aditya Kanade, Navin Goyal, Shuvendu K. Lahiri, Sriram K. Rajamani · 2023

用静态分析监视器引导解码,减少代码模型的幻觉调用

开始阅读 ↗PDFalphaXiv 讨论
被提及 · 5 人首次 2023-08-14 · 最近 2025-05-14
5不同的人
4活跃月份
5讨论串
17被引(OpenAlex)

代码语言模型缺乏对仓库中其他位置定义的类型、API 的了解,容易编造不存在的调用。论文提出监视器引导解码(MGD):解码时由监视器借助静态分析约束输出,例如保证对象解引用类型一致。在作者构建的 Java 仓库级方法补全数据集 PragmaticCode 上,MGD 在不同规模模型上都提高了编译率和与真值的一致性,小模型 SantaCoder-1.1B 加上 MGD 后超过大得多的 text-davinci-003;方法还可推广到 C#、Rust 及更丰富的语义约束。

HN 为什么提它

HN 评论者把它当作“在推理时接入静态分析,让生成的代码不止语法正确、没有幻觉的解引用”的代表性工作来引用。

方法难度 3 / 5约 45 分钟经得起时间
读之前最好知道
1大语言模型的解码(decoding)
2静态分析与类型系统
3代码补全与 IDE 的工作方式
4Java 基础

HN 书评

推荐在前,同类按时间 · 每篇最多保留 20 条,统计用全部提及
引用LakshyAAAgrawal · 2023-08

“shows how to have the language models generate code without hallucinated dereferences.”

指出它展示了如何让语言模型生成没有幻觉式解引用的代码
Show HN: LLMs can generate valid JSON 100% of the time原评论 ↗
引用LakshyAAAgrawal · 2023-08

“we propose Monitor Guided Decoding, which interfaces LLMs to static analysis”

介绍 Monitor Guided Decoding:让 LLM 对接静态分析
Show HN: LLMs can generate valid JSON 100% of the time原评论 ↗
引用namibj · 2023-11

“which essentially gives IDE-typical type-aware autocomplete to an LLM to primarily study the scenario of enforcing type-consistent method completion in a Java repository.”

说明它给 LLM 提供 IDE 式类型感知补全,研究 Java 仓库中的方法补全
Hacking Google Bard – From Prompt Injection to Data Exfiltration原评论 ↗
引用disconcision · 2023-11

“it's been done, in a limited way: Guiding Language Models of Code with Global Context using Monitors”

指出这件事已有人以有限形式做过
How to tackle unreliability of coding assistants原评论 ↗
引用emrek1 · 2024-03

“incorporating static analysis at inference time to ensure code is more than just syntactically correct [0]”

引它为例:推理时结合静态分析,保证代码不只是语法正确
Show HN: Prompts as WASM Programs原评论 ↗
引用_jayhack_ · 2025-05

“which uses static analysis beyond the type system to filter out e.g. invalid variable names, invalid control flow etc.”

指出它用类型系统之外的静态分析过滤无效变量名、无效控制流等
Type-constrained code generation with language models原评论 ↗