{"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/adaptable-logical-control-for-large-language","title":"Adaptable Logical Control for Large Language Models","arxiv_id":"2406.13892","date":"2024-06-19","proceeding":null,"authors":["Honghua Zhang","Po-Nien Kung","Masahiro Yoshida","Guy Van Den Broeck","Nanyun Peng"],"abstract":"Despite the success of Large Language Models (LLMs) on various tasks following human instructions, controlling model generation at inference time poses a persistent challenge. In this paper, we introduce Ctrl-G, an adaptable framework that facilitates tractable and flexible control of LLM generation to reliably follow logical constraints. Ctrl-G combines any production-ready LLM with a Hidden Markov Model, enabling LLM outputs to adhere to logical constraints represented as deterministic finite automata. We show that Ctrl-G, when applied to a TULU2-7B model, outperforms GPT3.5 and GPT4 on the task of interactive text editing: specifically, for the task of generating text insertions/continuations following logical constraints, Ctrl-G achieves over 30% higher satisfaction rate in human evaluation compared to GPT4. When applied to medium-size language models (e.g., GPT2-large), Ctrl-G also beats its counterparts for constrained generation by large margins on standard benchmarks. Additionally, as a proof-of-concept study, we experiment Ctrl-G on the Grade School Math benchmark to assist LLM reasoning, foreshadowing the application of Ctrl-G, as well as other constrained generation approaches, beyond traditional language generation tasks.","url_abs":"https://arxiv.org/abs/2406.13892v2","url_pdf":"https://arxiv.org/pdf/2406.13892v2.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":"adaptable-logical-control-for-large-language","repo_url":"https://github.com/joshuacnf/Ctrl-G","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"math","task_name":"Math"},{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2406.13892","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.13892"}},"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/joshuacnf/Ctrl-G","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":12,"unverified":4},"by_repo_kind":{"official":{"samples":16,"ran":12,"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":"d87a362a29e90f86","entry":"Kmeans_faiss","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation/lvd_hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation/lvd_hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d87a362a29e90f86"}},{"code_sha256_prefix":"72da812259d684ba","entry":"Kmeans_faiss","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation_vllm/lvd_hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation_vllm/lvd_hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"72da812259d684ba"}},{"code_sha256_prefix":"f3b4273175d620c9","entry":"apply_dropout","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation/train_hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation/train_hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f3b4273175d620c9"}},{"code_sha256_prefix":"bb87328692c74c6b","entry":"edges2G","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/dfa.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/dfa.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"bb87328692c74c6b"}},{"code_sha256_prefix":"e52f469bbbb24e15","entry":"edges2states","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/dfa.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/dfa.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e52f469bbbb24e15"}},{"code_sha256_prefix":"d8085015685ae53f","entry":"ib_ib_bj_to_ij","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d8085015685ae53f"}},{"code_sha256_prefix":"89f1bdb63107dedb","entry":"load_examples","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation/lvd_hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation/lvd_hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"89f1bdb63107dedb"}},{"code_sha256_prefix":"d7065ff3317ecdf8","entry":"load_examples","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation_vllm/lvd_hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation_vllm/lvd_hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d7065ff3317ecdf8"}},{"code_sha256_prefix":"28f9792482ba813f","entry":"matmul","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/hmm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/hmm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"28f9792482ba813f"}},{"code_sha256_prefix":"8eed124e6d6f4c9b","entry":"pad_to_len","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation/sample_data.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation/sample_data.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8eed124e6d6f4c9b"}},{"code_sha256_prefix":"9a7c043624eb97dd","entry":"query_vllm","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation_vllm/sample_data_instruct_vllm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation_vllm/sample_data_instruct_vllm.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9a7c043624eb97dd"}},{"code_sha256_prefix":"7ace1653104977b0","entry":"set2npset","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/dfa.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/dfa.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7ace1653104977b0"}},{"code_sha256_prefix":"6d7012aee1b0a90c","entry":"init_client_and_tokenizer","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"distillation_vllm/sample_data_instruct_vllm.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/distillation_vllm/sample_data_instruct_vllm.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6d7012aee1b0a90c"}},{"code_sha256_prefix":"d3a5928db0c06ba7","entry":"logsumexp","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/utils.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d3a5928db0c06ba7"}},{"code_sha256_prefix":"5b8c472909c8aefc","entry":"matmul_log","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/utils.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5b8c472909c8aefc"}},{"code_sha256_prefix":"506618569fa81eba","entry":"matmul_loga_b","repo":"joshuacnf/Ctrl-G","repo_kind":"official","path":"ctrlg/utils.py","file_url":"https://github.com/joshuacnf/Ctrl-G/blob/HEAD/ctrlg/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"506618569fa81eba"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}