{"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/how-large-language-models-encode-context","title":"How Large Language Models Encode Context Knowledge? A Layer-Wise Probing Study","arxiv_id":"2402.16061","date":"2024-02-25","proceeding":null,"authors":["Tianjie Ju","Weiwei Sun","Wei Du","Xinwei Yuan","Zhaochun Ren","Gongshen Liu"],"abstract":"Previous work has showcased the intriguing capability of large language models (LLMs) in retrieving facts and processing context knowledge. However, only limited research exists on the layer-wise capability of LLMs to encode knowledge, which challenges our understanding of their internal mechanisms. In this paper, we devote the first attempt to investigate the layer-wise capability of LLMs through probing tasks. We leverage the powerful generative capability of ChatGPT to construct probing datasets, providing diverse and coherent evidence corresponding to various facts. We employ $\\mathcal V$-usable information as the validation metric to better reflect the capability in encoding context knowledge across different layers. Our experiments on conflicting and newly acquired knowledge show that LLMs: (1) prefer to encode more context knowledge in the upper layers; (2) primarily encode context knowledge within knowledge-related entity tokens at lower layers while progressively expanding more knowledge within other tokens at upper layers; and (3) gradually forget the earlier context knowledge retained within the intermediate layers when provided with irrelevant evidence. Code is publicly available at https://github.com/Jometeorie/probing_llama.","url_abs":"https://arxiv.org/abs/2402.16061v2","url_pdf":"https://arxiv.org/pdf/2402.16061v2.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":"how-large-language-models-encode-context","repo_url":"https://github.com/jometeorie/probing_llama","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.16061","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.16061"}},"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/jometeorie/probing_llama","reach":{"status":"ok"}}],"summary":{"ran_fixture":3,"ran":4,"ran_draft_wrong":2,"unverified":2},"by_repo_kind":{"official":{"samples":11,"ran":9,"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":11,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/llama/modeling_llama.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/llama/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"f725bc2d76076485","entry":"apply_rotary_pos_emb","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/custom_llama/modeling_llama.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/custom_llama/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f725bc2d76076485"}},{"code_sha256_prefix":"37fc3129c3d06e0c","entry":"apply_rotary_pos_emb","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/llama/modeling_llama.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/llama/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"37fc3129c3d06e0c"}},{"code_sha256_prefix":"507f475feb734647","entry":"compute_intermediate_size","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/llama/convert_llama_weights_to_hf.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/llama/convert_llama_weights_to_hf.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":"507f475feb734647"}},{"code_sha256_prefix":"0c540da8d3df6b6e","entry":"compute_intermediate_size","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/custom_llama/convert_llama_weights_to_hf.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/custom_llama/convert_llama_weights_to_hf.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":"0c540da8d3df6b6e"}},{"code_sha256_prefix":"dfbf610d72061eaf","entry":"import_protobuf","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/llama/tokenization_llama.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/llama/tokenization_llama.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":"dfbf610d72061eaf"}},{"code_sha256_prefix":"c5bcf01d18bba63d","entry":"read_json","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/custom_llama/convert_llama_weights_to_hf.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/custom_llama/convert_llama_weights_to_hf.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c5bcf01d18bba63d"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/custom_llama/modeling_llama.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/custom_llama/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"86fe730f11e67507","entry":"train","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/probing_model.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/probing_model.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":"86fe730f11e67507"}},{"code_sha256_prefix":"731285361b7dea0e","entry":"write_model","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/llama/convert_llama_weights_to_hf.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/llama/convert_llama_weights_to_hf.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":"731285361b7dea0e"}},{"code_sha256_prefix":"cfeea96bf995824a","entry":"write_model","repo":"jometeorie/probing_llama","repo_kind":"official","path":"code/custom_llama/convert_llama_weights_to_hf.py","file_url":"https://github.com/jometeorie/probing_llama/blob/HEAD/code/custom_llama/convert_llama_weights_to_hf.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":"cfeea96bf995824a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}