{"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/unlocking-anticipatory-text-generation-a","title":"Unlocking Anticipatory Text Generation: A Constrained Approach for Large Language Models Decoding","arxiv_id":"2312.06149","date":"2023-12-11","proceeding":null,"authors":["Lifu Tu","Semih Yavuz","Jin Qu","Jiacheng Xu","Rui Meng","Caiming Xiong","Yingbo Zhou"],"abstract":"Large Language Models (LLMs) have demonstrated a powerful ability for text generation. However, achieving optimal results with a given prompt or instruction can be challenging, especially for billion-sized models. Additionally, undesired behaviors such as toxicity or hallucinations can manifest. While much larger models (e.g., ChatGPT) may demonstrate strength in mitigating these issues, there is still no guarantee of complete prevention. In this work, we propose formalizing text generation as a future-constrained generation problem to minimize undesirable behaviors and enforce faithfulness to instructions. The estimation of future constraint satisfaction, accomplished using LLMs, guides the text generation process. Our extensive experiments demonstrate the effectiveness of the proposed approach across three distinct text generation tasks: keyword-constrained generation (Lin et al., 2020), toxicity reduction (Gehman et al., 2020), and factual correctness in question-answering (Gao et al., 2023).","url_abs":"https://arxiv.org/abs/2312.06149v4","url_pdf":"https://arxiv.org/pdf/2312.06149v4.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":"unlocking-anticipatory-text-generation-a","repo_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2312.06149","atlas_url":"https://app.syntology.ai/?focus=2312.06149","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2312.06149"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/SalesforceAIResearch/Unlocking-TextGen","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":11,"ran_fixture":1,"ran_draft_wrong":1,"unverified":3},"by_repo_kind":{"official":{"samples":16,"ran":13,"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":"87f4d17f413b49ea","entry":"Falcon40b_reorder_cache","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/base_generation.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/base_generation.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":"87f4d17f413b49ea"}},{"code_sha256_prefix":"07def8743d23308c","entry":"Falcon_reorder_cache","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/generate.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/generate.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":"07def8743d23308c"}},{"code_sha256_prefix":"f725bc2d76076485","entry":"apply_rotary_pos_emb","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"TestReward/transformers_flash/modeling/modeling_llama_flash.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/TestReward/transformers_flash/modeling/modeling_llama_flash.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f725bc2d76076485"}},{"code_sha256_prefix":"e3ead4161d5e3d4a","entry":"calc_banned_bad_words_ids","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/generate.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/generate.py","link_basis":"harvester_set","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":"e3ead4161d5e3d4a"}},{"code_sha256_prefix":"8d77347cfa15b834","entry":"calc_banned_ngram_tokens","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/generate.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/generate.py","link_basis":"harvester_set","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":"8d77347cfa15b834"}},{"code_sha256_prefix":"1f5f980fef237c7a","entry":"calc_banned_ngram_tokens","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/generate.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/generate.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":"1f5f980fef237c7a"}},{"code_sha256_prefix":"63580965c8e7db0b","entry":"get_shorter_text","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/beam_search_eli5_large.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/beam_search_eli5_large.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":"63580965c8e7db0b"}},{"code_sha256_prefix":"0d99aee2775dd298","entry":"is_prefix","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/lexical_constraints.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/lexical_constraints.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0d99aee2775dd298"}},{"code_sha256_prefix":"d1d5762f28b96e14","entry":"is_suffix","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/lexical_constraints.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/lexical_constraints.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"d1d5762f28b96e14"}},{"code_sha256_prefix":"b194da4ef4825110","entry":"make_demo","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/beam_search_eli5_large.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/beam_search_eli5_large.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":"b194da4ef4825110"}},{"code_sha256_prefix":"a8f5fdcd9fc14fb2","entry":"make_doc_prompt","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"FactaulQA/beam_search_eli5_large.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/FactaulQA/beam_search_eli5_large.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":"a8f5fdcd9fc14fb2"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"TestReward/transformers_flash/modeling/modeling_llama_flash.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/TestReward/transformers_flash/modeling/modeling_llama_flash.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"48dee1cfc0fc7bbd","entry":"tokenize_constraints","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/utils.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/utils.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":"48dee1cfc0fc7bbd"}},{"code_sha256_prefix":"ad41a9451a0ec4b4","entry":"expand","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"Toxicity/sample_toxity_llm_facon.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/Toxicity/sample_toxity_llm_facon.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":"ad41a9451a0ec4b4"}},{"code_sha256_prefix":"79fc2b47d7e1bee9","entry":"init_batch","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/lexical_constraints.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/lexical_constraints.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":"79fc2b47d7e1bee9"}},{"code_sha256_prefix":"57eb609f3dcd1c6a","entry":"postprocess_next_token_scores","repo":"SalesforceAIResearch/Unlocking-TextGen","repo_kind":"official","path":"InstructionFollowing/generate.py","file_url":"https://github.com/SalesforceAIResearch/Unlocking-TextGen/blob/HEAD/InstructionFollowing/generate.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":"57eb609f3dcd1c6a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}