{"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/arxiv-2605-24869","title":"Lngram: N-gram Conditional Memory in Latent Space","arxiv_id":"2605.24869","date":"2026-05-24","proceeding":null,"authors":["Yunao Zheng","Guoyang Xia","Xiaojie Wang","Lei Ren"],"abstract":"Sequence modeling requires both compositional reasoning and local static knowledge retrieval, yet standard Transformers handle both through dense computation. Engram partially decouples retrieval from the backbone, but its token-based keys remain tied to text tokenization and hash compression. We propose Lngram, a latent-space conditional memory module that learns discrete symbols directly from hidden states and performs N-gram lookup over these symbols. This design removes the dependence on tokenizer IDs and naturally extends to non-text modalities. In our evaluated settings, Lngram outperforms Transformer and Engram baselines, consistently reduces perplexity in long-context language modeling, and effectively injects domain knowledge when added post hoc to pretrained models. Joint training with the backbone further surpasses full fine-tuning, while experiments on vision-language and vision-language-action tasks show overall gains. Analyses with LogitLens and CKA suggest that Lngram enables prediction-relevant information to emerge earlier, increasing effective depth with limited inference and memory overhead. Code is available at https://github.com/zyaaa-ux/Lngram.","url_abs":"https://arxiv.org/abs/2605.24869","url_pdf":"https://arxiv.org/pdf/2605.24869","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2605.24869","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2605.24869"}},"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":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/zyaaa-ux/Lngram","reach":null}],"summary":{"ran":5,"unverified":4},"by_repo_kind":{"found_in_text":{"samples":9,"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":0,"samples":[{"code_sha256_prefix":"cf3f5c0911a1bef0","entry":"chunked_linear_lastdim","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Single_table_Lngram.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Single_table_Lngram.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"cf3f5c0911a1bef0"}},{"code_sha256_prefix":"7b06678cd06df335","entry":"estimate_lngram_params_per_layer","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Multi-table_Lngram.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Multi-table_Lngram.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7b06678cd06df335"}},{"code_sha256_prefix":"a1f3b1665cedb429","entry":"pack_binary_bits_to_codes","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Approximate_gradient_backpropagation.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Approximate_gradient_backpropagation.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a1f3b1665cedb429"}},{"code_sha256_prefix":"153067c1af648778","entry":"pack_bits_to_route_codes","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Lngram_v2.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Lngram_v2.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"153067c1af648778"}},{"code_sha256_prefix":"c041f480412f9f0d","entry":"resolve_added_module_init_std","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Single_table_Lngram.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Single_table_Lngram.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c041f480412f9f0d"}},{"code_sha256_prefix":"e3fb2cb91c16417a","entry":"build_lngram_injector","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Multi-table_Lngram.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Multi-table_Lngram.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e3fb2cb91c16417a"}},{"code_sha256_prefix":"74586c65014face6","entry":"build_lngram_norm","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Lngram_v2.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Lngram_v2.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"74586c65014face6"}},{"code_sha256_prefix":"31f9faf75d34723b","entry":"coerce_lngram_config","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Multi-table_Lngram.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Multi-table_Lngram.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"31f9faf75d34723b"}},{"code_sha256_prefix":"f0bcde33c122d9c0","entry":"route_code_storage_dtype","repo":"zyaaa-ux/Lngram","repo_kind":"found_in_text","path":"Lngram_v2.py","file_url":"https://github.com/zyaaa-ux/Lngram/blob/HEAD/Lngram_v2.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f0bcde33c122d9c0"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.CL","source":"arxiv_2026.jsonl"},"syntology_extracted_results":null}