{"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/training-dynamics-of-contextual-n-grams-in","title":"Training Dynamics of Contextual N-Grams in Language Models","arxiv_id":"2311.00863","date":"2023-11-01","proceeding":null,"authors":["Lucia Quirke","Lovis Heindrich","Wes Gurnee","Neel Nanda"],"abstract":"Prior work has shown the existence of contextual neurons in language models, including a neuron that activates on German text. We show that this neuron exists within a broader contextual n-gram circuit: we find late layer neurons which recognize and continue n-grams common in German text, but which only activate if the German neuron is active. We investigate the formation of this circuit throughout training and find that it is an example of what we call a second-order circuit. In particular, both the constituent n-gram circuits and the German detection circuit which culminates in the German neuron form with independent functions early in training - the German detection circuit partially through modeling German unigram statistics, and the n-grams by boosting appropriate completions. Only after both circuits have already formed do they fit together into a second-order circuit. Contrary to the hypotheses presented in prior work, we find that the contextual n-gram circuit forms gradually rather than in a sudden phase transition. We further present a range of anomalous observations such as a simultaneous phase transition in many tasks coinciding with the learning rate warm-up, and evidence that many context neurons form simultaneously early in training but are later unlearned.","url_abs":"https://arxiv.org/abs/2311.00863v1","url_pdf":"https://arxiv.org/pdf/2311.00863v1.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":"training-dynamics-of-contextual-n-grams-in","repo_url":"https://github.com/luciaquirke/contextual-ngrams","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"jax","reach":{"status":"ok"}}],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2311.00863","atlas_url":"https://app.syntology.ai/?focus=2311.00863","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2311.00863"}},"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/luciaquirke/contextual-ngrams","reach":{"status":"ok"}}],"summary":{"ran":7},"by_repo_kind":{"official":{"samples":7,"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":7,"samples":[{"code_sha256_prefix":"9354080e13b221de","entry":"eval_loss","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_phase_transition_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_phase_transition_data.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":"9354080e13b221de"}},{"code_sha256_prefix":"0a5ff698025c33c1","entry":"eval_prompts","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_checkpoint_ablation_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_checkpoint_ablation_data.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":"0a5ff698025c33c1"}},{"code_sha256_prefix":"55a80046f8d3c4ab","entry":"get_deactivate_context_hook","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_ngrams_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_ngrams_data.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":"55a80046f8d3c4ab"}},{"code_sha256_prefix":"b1612e00a8d357c7","entry":"load_probe_data","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_dla_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_dla_data.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":"b1612e00a8d357c7"}},{"code_sha256_prefix":"94b84e0f888d9d84","entry":"load_txt_data","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"utils.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/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":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"94b84e0f888d9d84"}},{"code_sha256_prefix":"96c0c6dde64d9e8e","entry":"save_activation","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_checkpoint_ablation_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_checkpoint_ablation_data.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":"96c0c6dde64d9e8e"}},{"code_sha256_prefix":"61f8653dac2da1f9","entry":"train_probe","repo":"luciaquirke/contextual-ngrams","repo_kind":"official","path":"generate_checkpoint_probe_data.py","file_url":"https://github.com/luciaquirke/contextual-ngrams/blob/HEAD/generate_checkpoint_probe_data.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":"61f8653dac2da1f9"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}