{"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/selective-prompt-anchoring-for-code","title":"Selective Prompt Anchoring for Code Generation","arxiv_id":"2408.09121","date":"2024-08-17","proceeding":null,"authors":["Yuan Tian","Tianyi Zhang"],"abstract":"Recent advances in large language models (LLMs) have transformed software development by automatically generating code from natural language. Yet challenges remain in generating fully correct code that aligns with user intent. Our study reveals that LLMs tend to pay less attention to user prompts as more code tokens are generated. We hypothesize that this attention dilution issue is an important reason for code generation errors. To mitigate this issue, we propose Selective Prompt Anchoring (SPA) to guide code LLMs to pay more attention to user intent when generating code. We evaluate SPA using six base LLMs across six benchmarks. Our results demonstrate that SPA enhances Pass@1 by up to 12.9%, consistently outperforming SOTA code generation methods in all settings. Our code is available at https://github.com/magic-YuanTian/Selective-Prompt-Anchoring.","url_abs":"https://arxiv.org/abs/2408.09121v5","url_pdf":"https://arxiv.org/pdf/2408.09121v5.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":"selective-prompt-anchoring-for-code","repo_url":"https://github.com/magic-yuantian/selective-prompt-anchoring","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"code-generation","task_name":"Code Generation"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"base","method_name":"BASE"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2408.09121","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2408.09121"}},"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":"deterministic:regex_extraction","url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/magic-yuantian/selective-prompt-anchoring","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran_draft_wrong":4,"ran":3,"unverified":4},"by_repo_kind":{"official":{"samples":11,"ran":7,"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":"37eb35f878deabb1","entry":"create_masked_attention","repo":"magic-yuantian/selective-prompt-anchoring","repo_kind":"official","path":"code/spa.py","file_url":"https://github.com/magic-yuantian/selective-prompt-anchoring/blob/HEAD/code/spa.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"37eb35f878deabb1"}},{"code_sha256_prefix":"8e08f76d757c9320","entry":"divide_tasks","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/anchor_evaluation.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/anchor_evaluation.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":"8e08f76d757c9320"}},{"code_sha256_prefix":"48f4dd62f3915251","entry":"find_last_python_function","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/weighted_utils/weighted_text_utils.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/weighted_utils/weighted_text_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":"48f4dd62f3915251"}},{"code_sha256_prefix":"bdebcb7bf7024120","entry":"format_spa_input","repo":"magic-yuantian/selective-prompt-anchoring","repo_kind":"official","path":"code/spa.py","file_url":"https://github.com/magic-yuantian/selective-prompt-anchoring/blob/HEAD/code/spa.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"bdebcb7bf7024120"}},{"code_sha256_prefix":"aecadcaa2ac48b1b","entry":"get_gpus_max_memory","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/weighted_utils/weighted_text_utils.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/weighted_utils/weighted_text_utils.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"aecadcaa2ac48b1b"}},{"code_sha256_prefix":"39c4708ddb6031ae","entry":"load_tasks_from_jsonl","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/anchor_evaluation.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/anchor_evaluation.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":"39c4708ddb6031ae"}},{"code_sha256_prefix":"8a1f0cd88536eecf","entry":"preprocess_anchors","repo":"magic-yuantian/selective-prompt-anchoring","repo_kind":"official","path":"code/spa.py","file_url":"https://github.com/magic-yuantian/selective-prompt-anchoring/blob/HEAD/code/spa.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8a1f0cd88536eecf"}},{"code_sha256_prefix":"2c88019eca86410e","entry":"SPALogitsProcessor","repo":"magic-yuantian/selective-prompt-anchoring","repo_kind":"official","path":"code/spa.py","file_url":"https://github.com/magic-yuantian/selective-prompt-anchoring/blob/HEAD/code/spa.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":"2c88019eca86410e"}},{"code_sha256_prefix":"556744211a325503","entry":"get_dataset","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/SPA_tune.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/SPA_tune.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":"556744211a325503"}},{"code_sha256_prefix":"d9977f2786c4b8d9","entry":"get_gpus_max_memory","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/weighted_utils/weighted_text_model_load.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/weighted_utils/weighted_text_model_load.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":"d9977f2786c4b8d9"}},{"code_sha256_prefix":"f32275a7d9ecf730","entry":"load_model","repo":"magic-YuanTian/Selective-Prompt-Anchoring","repo_kind":"official","path":"obsolete/obsolete/weighted_utils/weighted_text_utils.py","file_url":"https://github.com/magic-YuanTian/Selective-Prompt-Anchoring/blob/HEAD/obsolete/obsolete/weighted_utils/weighted_text_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":"f32275a7d9ecf730"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}