Guiding Language Models of Code with Global Context using Monitors
Not on the map. Why?
Abstract (arXiv)
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 with ground truth. Further, LMs with fewer parameters, when augmented with MGD, can outperform larger LMs. With MGD, SantaCoder-1.1B achieves better compilation rate and next-identifier match than the much larger text-davinci-003 model. We also conduct a generalizability study to evaluate the ability of MGD to generalize to multiple programming languages (Java, C# and Rust), coding scenarios (e.g., correct number of arguments to method calls), and to enforce richer semantic constraints (e.g., stateful API protocols). Our data and implementation are available at https://github.com/microsoft/monitors4codegen .
Key facts. Cited by 20 papers in the map (data through 7 Oct 2026). Builds on 34 of its 66 references that are in the map. First posted on arXiv 19 Jun 2023.
Builds on
34 of 66 references.
References · 34
- 2022Training language models to follow instructions with human feedbackcited by 15,712
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2015Neural Machine Translation of Rare Words with Subword Unitscited by 2,898
- 2019The Curious Case of Neural Text Degenerationcited by 2,881
- 2018SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processingcited by 1,973
- 2022Competition-Level Code Generation with AlphaCodecited by 1,427
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
- 2023StarCoder: may the source be with you!cited by 790
- 2019Generalization through Memorization: Nearest Neighbor Language Modelscited by 788
22 more
- 2022GPT-NeoX-20B: An Open-Source Autoregressive Language Modelcited by 711
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
- 2021PICARD: Parsing Incrementally for Constrained Auto-Regressive Decoding from Language Modelscited by 402
- 2021Unified Pre-training for Program Understanding and Generationcited by 361
- 2022A Systematic Evaluation of Large Language Models of Codecited by 360
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
- 2022UniXcoder: Unified Cross-Modal Pre-training for Code Representationcited by 355
- 2022Efficient Training of Language Models to Fill in the Middlecited by 248
- 2023SantaCoder: don't reach for the stars!cited by 169
- 2022Synchromesh: Reliable code generation from pre-trained language modelscited by 156
- 2022DocPrompting: Generating Code by Retrieving the Docscited by 151
- 2020Enabling Language Models to Fill in the Blankscited by 121
- 2022Repository-Level Prompt Generation for Large Language Models of Codecited by 106
- 2022CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Contextcited by 64
- 2018Generative Code Modeling with Graphscited by 59
- 2022When Language Model Meets Private Librarycited by 54
- 2020Big Code != Big Vocabulary: Open-Vocabulary Models for Source Codecited by 53
- 2023CoderEval: A Benchmark of Pragmatic Code Generation with Generative Pre-trained Modelscited by 28
- 2023Better Context Makes Better Code Language Models: A Case Study on Function Call Argument Completioncited by 14
- 2021Neural Program Generation Modulo Static Analysiscited by 13
- 2021Capturing Structural Locality in Non-parametric Language Modelscited by 8
Built on by
Citing papers per year: 2023: 3; 2024: 12; 2025: 5.
20 papers.
Sort:
By area:
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 66
- 2023Unifying the Perspectives of NLP and Software Engineering: A Survey on Language Models for Codecited by 62
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024AgileCoder: Dynamic Collaborative Agents for Software Development based on Agile Methodologycited by 45
- 2025Uncertainty-Guided Chain-of-Thought for Code Generation with LLMscited by 30
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtrackingcited by 28
- 2024Octopus: On-device language model for function calling of software APIscited by 26
- 2024NoFunEval: Funny How Code LMs Falter on Requirements Beyond Functional Correctnesscited by 23
- 2024M2rc-Eval: Massively Multilingual Repository-level Code Completion Evaluationcited by 21
- 2024RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completioncited by 15
- 2024Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language Modelscited by 15
- 2024VersiCode: Towards Version-controllable Code Generationcited by 14
8 more
- 2025Software Development Life Cycle Perspective: A Survey of Benchmarks for Code Large Language Models and Agentscited by 11
- 2024R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code Large Language Modelscited by 9
- 2023Frustrated with Code Quality Issues? LLMs can Help!cited by 5
- 2025Enhancing Project-Specific Code Completion by Inferring Internal API Informationcited by 5
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Qualitycited by 3
- 2024Insights from Benchmarking Frontier Language Models on Web App Code Generationcited by 1
- 2023CodeScholar: Growing Idiomatic Code Examplescited by 0
- 2025Guided Decoding and Its Critical Role in Retrieval-Augmented Generationcited by 0
- 2025Guided Decoding and Its Critical Role in Retrieval-Augmented Generation8 Sep 2025
- 2025Enhancing Project-Specific Code Completion by Inferring Internal API Information28 Jul 2025
- 2025Software Development Life Cycle Perspective: A Survey of Benchmarks for Code Large Language Models and Agents8 May 2025
- 2025Uncertainty-Guided Chain-of-Thought for Code Generation with LLMs19 Mar 2025
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Quality7 Mar 2025
- 2024M2rc-Eval: Massively Multilingual Repository-level Code Completion Evaluation28 Oct 2024
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking9 Oct 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2024Insights from Benchmarking Frontier Language Models on Web App Code Generation8 Sep 2024
- 2024Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language Models29 Jun 2024
- 2024AgileCoder: Dynamic Collaborative Agents for Software Development based on Agile Methodology16 Jun 2024
- 2024VersiCode: Towards Version-controllable Code Generation11 Jun 2024
8 more
- 2024R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code Large Language Models3 Jun 2024
- 2024Octopus: On-device language model for function calling of software APIs2 Apr 2024
- 2024RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completion10 Mar 2024
- 2024SynCode: LLM Generation with Grammar Augmentation3 Mar 2024
- 2024NoFunEval: Funny How Code LMs Falter on Requirements Beyond Functional Correctness29 Jan 2024
- 2023CodeScholar: Growing Idiomatic Code Examples23 Dec 2023
- 2023Unifying the Perspectives of NLP and Software Engineering: A Survey on Language Models for Code14 Nov 2023
- 2023Frustrated with Code Quality Issues? LLMs can Help!22 Sep 2023
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 66
- 2023Unifying the Perspectives of NLP and Software Engineering: A Survey on Language Models for Codecited by 62
- 2024AgileCoder: Dynamic Collaborative Agents for Software Development based on Agile Methodologycited by 45
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtrackingcited by 28
- 2024NoFunEval: Funny How Code LMs Falter on Requirements Beyond Functional Correctnesscited by 23
- 2024M2rc-Eval: Massively Multilingual Repository-level Code Completion Evaluationcited by 21
- 2024RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completioncited by 15
- 2024Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language Modelscited by 15
- 2024VersiCode: Towards Version-controllable Code Generationcited by 14
- 2024R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code Large Language Modelscited by 9
- 2023Frustrated with Code Quality Issues? LLMs can Help!cited by 5
- 2025Enhancing Project-Specific Code Completion by Inferring Internal API Informationcited by 5
12 most cited of 15 All 15 (JSON)
- 2025Enhancing Project-Specific Code Completion by Inferring Internal API Information28 Jul 2025
- 2025Benchmarking AI Models in Software Engineering: A Review, Search Tool, and Unified Approach for Elevating Benchmark Quality7 Mar 2025
- 2024M2rc-Eval: Massively Multilingual Repository-level Code Completion Evaluation28 Oct 2024
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking9 Oct 2024
- 2024Insights from Benchmarking Frontier Language Models on Web App Code Generation8 Sep 2024
- 2024Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language Models29 Jun 2024
- 2024AgileCoder: Dynamic Collaborative Agents for Software Development based on Agile Methodology16 Jun 2024
- 2024VersiCode: Towards Version-controllable Code Generation11 Jun 2024
- 2024R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code Large Language Models3 Jun 2024
- 2024RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completion10 Mar 2024
- 2024SynCode: LLM Generation with Grammar Augmentation3 Mar 2024
- 2024NoFunEval: Funny How Code LMs Falter on Requirements Beyond Functional Correctness29 Jan 2024
12 newest of 15 All 15 (JSON)