{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/constrained-decoding-for-code-language-models","title":"Constrained Decoding for Fill-in-the-Middle Code Language Models via Efficient Left and Right Quotienting of Context-Sensitive Grammars","arxiv_id":"2402.17988","date":"2024-02-28","proceeding":null,"authors":["Daniel Melcer","Nathan Fulton","Sanjay Krishna Gouda","Haifeng Qian"],"abstract":"Large Language Models are powerful tools for program synthesis and advanced auto-completion, but come with no guarantee that their output code is syntactically correct. This paper contributes an incremental parser that allows early rejection of syntactically incorrect code, as well as efficient detection of complete programs for fill-in-the-middle (FIM) tasks. We extend the Earley parsing algorithm to allow for left and right quotients of context-free grammars, and develop methods to handle quotienting of several context-sensitive features present in the grammars of many common programming languages. The result of these contributions is an efficient, general, and well-grounded method for left and right quotient parsing. To validate our theoretical contributions -- and the effectiveness of certain design decisions -- we evaluate our method on the particularly difficult case of FIM completion for Python 3, with syntax-correctness constraints. Our results demonstrate that constrained generation can significantly reduce the incidence of syntax errors in recommended code.","url_abs":"https://arxiv.org/abs/2402.17988v2","url_pdf":"https://arxiv.org/pdf/2402.17988v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"constrained-decoding-for-code-language-models","repo_url":"https://github.com/amazon-science/incremental-parsing","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"program-synthesis","task_name":"Program Synthesis"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.17988","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.17988"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/amazon-science/incremental-parsing","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":4,"unverified":2},"by_repo_kind":{"official":{"samples":6,"ran":4,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"a69071e9274fe02e","entry":"cut_text_random","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/evaluation/text_cuts.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/evaluation/text_cuts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a69071e9274fe02e"}},{"code_sha256_prefix":"a67dc4188029ee5d","entry":"extract_absolute_positions","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/evaluation/text_cuts.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/evaluation/text_cuts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a67dc4188029ee5d"}},{"code_sha256_prefix":"aa0e7bf322585b9e","entry":"get_runs_of_same_indentation","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/evaluation/text_cuts.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/evaluation/text_cuts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"aa0e7bf322585b9e"}},{"code_sha256_prefix":"8cf06c6d34b7983f","entry":"parse_top_level_file","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/evaluation/evaluate_stack.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/evaluation/evaluate_stack.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8cf06c6d34b7983f"}},{"code_sha256_prefix":"01edc77d3bb7b944","entry":"create_balanced_context","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/generation/utils.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/generation/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"01edc77d3bb7b944"}},{"code_sha256_prefix":"4971c3e59cfa2506","entry":"tokenizer_int64","repo":"amazon-science/incremental-parsing","repo_kind":"official","path":"incremental_parsing/generation/utils.py","file_url":"https://github.com/amazon-science/incremental-parsing/blob/HEAD/incremental_parsing/generation/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4971c3e59cfa2506"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}