SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2605.24869 · 2026

Lngram: N-gram Conditional Memory in Latent Space

Xiaojie Wang, Lei Ren, Yunao Zheng, Guoyang Xia, Ren Lei

arXiv · PDF · Open in the Atlas

Code that ran

5 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 4 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2605.24869.json · badge: /api/ran/2605.24869.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
zyaaa-ux/Lngram canonical (classifier label)
classifier basis: census
5 ran · 4 no recorded run
FunctionStatusWhere it lives
chunked_linear_lastdim Ran
ran; our contract draft was wrong, not the code
zyaaa-ux/Lngram/Single_table_Lngram.py
code served (permissive licence) · get_code("cf3f5c0911a1bef0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a small linear layer
# in_features=4, out_features=3
linear = nn.Linear(in_features=4, out_features=3, bias=True)

# Create input tensor with shape (2, 4)
# batch_size=2, in_features=4
x = torch.randn(2, 4)

# chunk_size should be positive and less than in_features
chunk_size = 2

ARGS = {
    "x": x,
    "linear": linear,
    "chunk_size": chunk_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
estimate_lngram_params_per_layer Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zyaaa-ux/Lngram/Multi-table_Lngram.py
code served (permissive licence) · get_code("7b06678cd06df335")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

ARGS = {
    'hidden_size': 64,
    'bits_per_route': 8,
    'mem_dim': 16,
    'ngrams': (2, 3, 4),
    'num_subtables': 2,
    'conv_kernel_size': 4,
    'conv_bias': False,
    'return_breakdown': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
pack_binary_bits_to_codes Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zyaaa-ux/Lngram/Approximate_gradient_backpropagation.py
code served (permissive licence) · get_code("a1f3b1665cedb429")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family int, shape (2, 3, 2) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small tensor of shape [B, T, C] with binary values (0/1)
# B=2 (batch), T=3 (sequence length), C=8 (channels)
bits_btc = torch.randint(0, 2, (2, 3, 8), dtype=torch.float32)

# Number of bits per route
bits_per_route = 4

ARGS = {
    "bits_btc": bits_btc,
    "bits_per_route": bits_per_route,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family int, shape (2, 3, 2) — shape (2, 3, 2) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
pack_bits_to_route_codes Ran
ran; our contract draft was wrong, not the code
zyaaa-ux/Lngram/Lngram_v2.py
code served (permissive licence) · get_code("153067c1af648778")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family int, shape (2, 3, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from torch import Tensor

torch.manual_seed(0)

# Create a valid bits tensor with shape [B, T, R*M]
# B=2 (batch), T=3 (time), R*M=12 (channels, which must be divisible by bits_per_route)
bits = torch.randint(0, 2, (2, 3, 12), dtype=torch.int32).float()

# bits_per_route must divide channels (12)
# Valid choices: 1, 2, 3, 4, 6, 12
# Using 4 means we'll have 12/4=3 routes
bits_per_route = 4

ARGS = {
    "bits": bits,
    "bits_per_route": bits_per_route,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family int, shape (2, 3, 3) — shape (2, 3, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
resolve_added_module_init_std Ran
ran, honoured the contract we drafted
zyaaa-ux/Lngram/Single_table_Lngram.py
code served (permissive licence) · get_code("c041f480412f9f0d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

class ConfigStandIn:
    def __init__(self, initializer_range=None):
        if initializer_range is not None:
            self.initializer_range = initializer_range

# Test case 1: config with valid positive initializer_range
config_with_range = ConfigStandIn(initializer_range=0.05)

# Test case 2: config with zero initializer_range (should return 0.02)
config_with_zero = ConfigStandIn(initializer_range=0.0)

# Test case 3: config with negative initializer_range (should return 0.02)
config_with_negative = ConfigStandIn(initializer_range=-0.01)

# Test case 4: config without initializer_range attribute (should return 0.02)
config_without_range = ConfigStandIn()

# Use the first config as the main argument
ARGS = {
    'config': config_with_range
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
build_lngram_injector Not yet run
unverified (harvested, no recorded run)
zyaaa-ux/Lngram/Multi-table_Lngram.py
code served (permissive licence) · get_code("e3fb2cb91c16417a")
How it ran

no invocation recorded.

build_lngram_norm Not yet run
unverified (harvested, no recorded run)
zyaaa-ux/Lngram/Lngram_v2.py
code served (permissive licence) · get_code("74586c65014face6")
How it ran

no invocation recorded.

coerce_lngram_config Not yet run
unverified (harvested, no recorded run)
zyaaa-ux/Lngram/Multi-table_Lngram.py
code served (permissive licence) · get_code("31f9faf75d34723b")
How it ran

no invocation recorded.

route_code_storage_dtype Not yet run
unverified (harvested, no recorded run)
zyaaa-ux/Lngram/Lngram_v2.py
code served (permissive licence) · get_code("f0bcde33c122d9c0")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

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 visionlanguage-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.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2605.24869")
get_code_for_paper("2605.24869")
have("2605.24869")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2605.24869.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2605.24869.svg)](https://syntology.ai/paper/2605.24869)

Connect an agent — have() is free.