{"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/causallm-is-not-optimal-for-in-context","title":"CausalLM is not optimal for in-context learning","arxiv_id":"2308.06912","date":"2023-08-14","proceeding":null,"authors":["Nan Ding","Tomer Levinboim","Jialin Wu","Sebastian Goodman","Radu Soricut"],"abstract":"Recent empirical evidence indicates that transformer based in-context learning performs better when using a prefix language model (prefixLM), in which in-context samples can all attend to each other, compared to causal language models (causalLM), which use auto-regressive attention that prohibits in-context samples to attend to future samples. While this result is intuitive, it is not understood from a theoretical perspective. In this paper we take a theoretical approach and analyze the convergence behavior of prefixLM and causalLM under a certain parameter construction. Our analysis shows that both LM types converge to their stationary points at a linear rate, but that while prefixLM converges to the optimal solution of linear regression, causalLM convergence dynamics follows that of an online gradient descent algorithm, which is not guaranteed to be optimal even as the number of samples grows infinitely. We supplement our theoretical claims with empirical experiments over synthetic and real tasks and using various types of transformers. Our experiments verify that causalLM consistently underperforms prefixLM in all settings.","url_abs":"https://arxiv.org/abs/2308.06912v3","url_pdf":"https://arxiv.org/pdf/2308.06912v3.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":"causallm-is-not-optimal-for-in-context","repo_url":"https://github.com/google-research/causallm_icl","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2308.06912","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2308.06912"}},"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/google-research/causallm_icl","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":8,"unverified":5},"by_repo_kind":{"official":{"samples":13,"ran":8,"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":"25ce8c68e697049c","entry":"dot_product_attention","repo":"google-research/causallm_icl","repo_kind":"official","path":"self_attention_patch.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/self_attention_patch.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":"25ce8c68e697049c"}},{"code_sha256_prefix":"9023ce088127d9ce","entry":"dot_product_attention_weights","repo":"google-research/causallm_icl","repo_kind":"official","path":"self_attention_patch.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/self_attention_patch.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":"9023ce088127d9ce"}},{"code_sha256_prefix":"335bd7f77a12cdf9","entry":"extract_y","repo":"google-research/causallm_icl","repo_kind":"official","path":"predictor_flax.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/predictor_flax.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":"335bd7f77a12cdf9"}},{"code_sha256_prefix":"b5919b0f35895f63","entry":"l2_loss","repo":"google-research/causallm_icl","repo_kind":"official","path":"predictor_flax.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/predictor_flax.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":"b5919b0f35895f63"}},{"code_sha256_prefix":"52590a86263d6fbf","entry":"logistic_loss","repo":"google-research/causallm_icl","repo_kind":"official","path":"predictor_flax.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/predictor_flax.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":"52590a86263d6fbf"}},{"code_sha256_prefix":"a3413d734b445c7a","entry":"map_func","repo":"google-research/causallm_icl","repo_kind":"official","path":"sampler_lib.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/sampler_lib.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":"a3413d734b445c7a"}},{"code_sha256_prefix":"fec430a564c9c333","entry":"set_seed","repo":"google-research/causallm_icl","repo_kind":"official","path":"utils.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/utils.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":"fec430a564c9c333"}},{"code_sha256_prefix":"2e70786d045620a8","entry":"trh","repo":"google-research/causallm_icl","repo_kind":"official","path":"utils.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/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":"2e70786d045620a8"}},{"code_sha256_prefix":"6f0e9bed65917eba","entry":"save_checkpoint","repo":"google-research/causallm_icl","repo_kind":"official","path":"model_trainer.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/model_trainer.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":"6f0e9bed65917eba"}},{"code_sha256_prefix":"18a0f3cf92558fad","entry":"str_to_distribution_fn","repo":"google-research/causallm_icl","repo_kind":"official","path":"sampler_lib.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/sampler_lib.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":"18a0f3cf92558fad"}},{"code_sha256_prefix":"585d0af2bc39c312","entry":"str_to_gmm_mix_fn","repo":"google-research/causallm_icl","repo_kind":"official","path":"sampler_lib.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/sampler_lib.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":"585d0af2bc39c312"}},{"code_sha256_prefix":"db573bba4a35a0c9","entry":"train_step","repo":"google-research/causallm_icl","repo_kind":"official","path":"model_trainer.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/model_trainer.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":"db573bba4a35a0c9"}},{"code_sha256_prefix":"be4179e9fe9ec75c","entry":"y_x_fn","repo":"google-research/causallm_icl","repo_kind":"official","path":"utils.py","file_url":"https://github.com/google-research/causallm_icl/blob/HEAD/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":"be4179e9fe9ec75c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}