{"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/transformers-learn-higher-order-optimization","title":"Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear Regression","arxiv_id":"2310.17086","date":"2023-10-26","proceeding":null,"authors":["Deqing Fu","Tian-Qi Chen","Robin Jia","Vatsal Sharan"],"abstract":"Transformers excel at in-context learning (ICL) -- learning from demonstrations without parameter updates -- but how they do so remains a mystery. Recent work suggests that Transformers may internally run Gradient Descent (GD), a first-order optimization method, to perform ICL. In this paper, we instead demonstrate that Transformers learn to approximate second-order optimization methods for ICL. For in-context linear regression, Transformers share a similar convergence rate as Iterative Newton's Method, both exponentially faster than GD. Empirically, predictions from successive Transformer layers closely match different iterations of Newton's Method linearly, with each middle layer roughly computing 3 iterations; thus, Transformers and Newton's method converge at roughly the same rate. In contrast, Gradient Descent converges exponentially more slowly. We also show that Transformers can learn in-context on ill-conditioned data, a setting where Gradient Descent struggles but Iterative Newton succeeds. Finally, to corroborate our empirical findings, we prove that Transformers can implement $k$ iterations of Newton's method with $k + \\mathcal{O}(1)$ layers.","url_abs":"https://arxiv.org/abs/2310.17086v3","url_pdf":"https://arxiv.org/pdf/2310.17086v3.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":"transformers-learn-higher-order-optimization","repo_url":"https://github.com/deqingfu/transformers-icl-higher-order","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"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.17086","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.17086"}},"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/DeqingFu/transformers-icl-second-order","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/deqingfu/transformers-icl-higher-order","reach":{"status":"ok"}}],"summary":{"ran":7,"unverified":3},"by_repo_kind":{"found_in_text":{"samples":10,"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":10,"samples":[{"code_sha256_prefix":"d7ae3e05768f422d","entry":"accuracy","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/tasks.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/tasks.py","link_basis":"harvester_set","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":"d7ae3e05768f422d"}},{"code_sha256_prefix":"b25e1cafdb9ebe37","entry":"basic_plot","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/plot_utils.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/plot_utils.py","link_basis":"first_harvest_node","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":"b25e1cafdb9ebe37"}},{"code_sha256_prefix":"5e0c28dc433111b9","entry":"get_data_sampler","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/samplers.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/samplers.py","link_basis":"first_harvest_node","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":"5e0c28dc433111b9"}},{"code_sha256_prefix":"fc94f27a0973e093","entry":"mean_squared_error","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/tasks.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/tasks.py","link_basis":"harvester_set","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":"fc94f27a0973e093"}},{"code_sha256_prefix":"44a629abef84e7c0","entry":"sample_transformation","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/samplers.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/samplers.py","link_basis":"first_harvest_node","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":"44a629abef84e7c0"}},{"code_sha256_prefix":"348d63a78eb4cb94","entry":"squared_error","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/tasks.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/tasks.py","link_basis":"harvester_set","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":"348d63a78eb4cb94"}},{"code_sha256_prefix":"dcdff2706acbf855","entry":"train_step","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/train_linear.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/train_linear.py","link_basis":"first_harvest_node","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":"dcdff2706acbf855"}},{"code_sha256_prefix":"c07e8759bc056638","entry":"build_model","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/models.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/models.py","link_basis":"first_harvest_node","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":"c07e8759bc056638"}},{"code_sha256_prefix":"3c24ac252fef0868","entry":"get_final_var","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/curriculum.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/curriculum.py","link_basis":"harvester_set","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":"3c24ac252fef0868"}},{"code_sha256_prefix":"4d49c710f74c99c4","entry":"sample_seeds","repo":"DeqingFu/transformers-icl-second-order","repo_kind":"found_in_text","path":"src/train_linear.py","file_url":"https://github.com/DeqingFu/transformers-icl-second-order/blob/HEAD/src/train_linear.py","link_basis":"harvester_set","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":"4d49c710f74c99c4"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}