{"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/in-context-learning-state-vector-with-inner","title":"In-Context Learning State Vector with Inner and Momentum Optimization","arxiv_id":"2404.11225","date":"2024-04-17","proceeding":null,"authors":["Dongfang Li","Zhenyu Liu","Xinshuo Hu","Zetian Sun","Baotian Hu","Min Zhang"],"abstract":"Large Language Models (LLMs) have exhibited an impressive ability to perform In-Context Learning (ICL) from only a few examples. Recent works have indicated that the functions learned by ICL can be represented through compressed vectors derived from the transformer. However, the working mechanisms and optimization of these vectors are yet to be thoroughly explored. In this paper, we address this gap by presenting a comprehensive analysis of these compressed vectors, drawing parallels to the parameters trained with gradient descent, and introduce the concept of state vector. Inspired by the works on model soup and momentum-based gradient descent, we propose inner and momentum optimization methods that are applied to refine the state vector progressively as test-time adaptation. Moreover, we simulate state vector aggregation in the multiple example setting, where demonstrations comprising numerous examples are usually too lengthy for regular ICL, and further propose a divide-and-conquer aggregation method to address this challenge. We conduct extensive experiments using Llama-2 and GPT-J in both zero-shot setting and few-shot setting. The experimental results show that our optimization method effectively enhances the state vector and achieves the state-of-the-art performance on diverse tasks. Code is available at https://github.com/HITsz-TMG/ICL-State-Vector","url_abs":"https://arxiv.org/abs/2404.11225v2","url_pdf":"https://arxiv.org/pdf/2404.11225v2.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":"in-context-learning-state-vector-with-inner","repo_url":"https://github.com/hitsz-tmg/icl-state-vector","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"},{"task_slug":"test-time-adaptation","task_name":"Test-time Adaptation"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2404.11225","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2404.11225"}},"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/hitsz-tmg/icl-state-vector","reach":{"status":"ok"}}],"summary":{"ran":5,"unverified":1},"by_repo_kind":{"official":{"samples":6,"ran":5,"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":6,"samples":[{"code_sha256_prefix":"7fa4c0d4e9cee1af","entry":"get_data_layers","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"selected_layers.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/selected_layers.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7fa4c0d4e9cee1af"}},{"code_sha256_prefix":"dc25dfef6f90b386","entry":"metric_average","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dc25dfef6f90b386"}},{"code_sha256_prefix":"85ac527a9dce9de6","entry":"sea_born","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"85ac527a9dce9de6"}},{"code_sha256_prefix":"f4d8b3796ddaccdf","entry":"shuffle_train","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"utils.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f4d8b3796ddaccdf"}},{"code_sha256_prefix":"3b34facc51914c48","entry":"str2list","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"state_vector_optimize.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/state_vector_optimize.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3b34facc51914c48"}},{"code_sha256_prefix":"f5d8f58d3af60f15","entry":"get_optimizers","repo":"hitsz-tmg/icl-state-vector","repo_kind":"official","path":"optimizer.py","file_url":"https://github.com/hitsz-tmg/icl-state-vector/blob/HEAD/optimizer.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f5d8f58d3af60f15"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}