Guiding Language Models of Code with Global Context using Monitors
Lakshya A Agrawal, Aditya Kanade, Navin Goyal, Shuvendu K. Lahiri,, Sriram K. Rajamani

TL;DR
This paper introduces monitor-guided decoding (MGD), a method that uses static analysis to improve the global contextual understanding of language models of code, leading to better accuracy and fewer hallucinations across multiple languages.
Contribution
The paper presents MGD, a novel approach that integrates static analysis as monitors during decoding to enhance code generation by language models, especially for unseen global context.
Findings
MGD improves compilation rates and ground truth agreement.
Smaller LMs with MGD outperform larger models without it.
MGD generalizes across multiple programming languages and constraints.
Abstract
Language models of code (LMs) work well when the surrounding code provides sufficient context. This is not true when it becomes necessary to use types, functionality or APIs defined elsewhere in the repository or a linked library, especially those not seen during training. LMs suffer from limited awareness of such global context and end up hallucinating. Integrated development environments (IDEs) assist developers in understanding repository context using static analysis. We extend this assistance, enjoyed by developers, to LMs. We propose monitor-guided decoding (MGD) where a monitor uses static analysis to guide the decoding. We construct a repository-level dataset PragmaticCode for method-completion in Java and evaluate MGD on it. On models of varying parameter scale, by monitoring for type-consistent object dereferences, MGD consistently improves compilation rates and agreement…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Scientific Computing and Data Management · Advanced Malware Detection Techniques
