Skip to content

The read

An item arrives with its point zz, Δt\Delta t hours after the previous one. Before anything is written, the memory reads it. This is the first half of Memory.step.

0. Expiry (when expiry > 0). Nodes whose mass, forgotten up to now, is below expiry leave the memory and free their row. The dormant node below shows why this is needed.

1. The prior: the restaurant, with masses brought up to date.

π0∝α,πk∝λΔtNk\pi_0 \propto \alpha, \qquad \pi_k \propto \lambda^{\Delta t} N_k

Slot 0 is new story and weighs alpha. Each node weighs its mass as it will be when the item arrives. After a long pause every mass has shrunk but α\alpha has not, so a long pause makes a new story more likely.

2. The likelihood: how well the item fits each bell. For each active node, log⁡fk(z)=κk (μk⋅z)+log⁡Cd(κk)\log f_k(z) = \kappa_k\,(\mu_k \cdot z) + \log C_d(\kappa_k). For new story, the uniform density on the sphere: the same everywhere, because a story that does not exist yet could be anywhere.

3. The posterior.

rk=softmax⁡k(log⁡πk+log⁡fk(z)),k=0,1,…,Kr_k = \operatorname{softmax}_k\big(\log \pi_k + \log f_k(z)\big), \qquad k = 0, 1, \dots, K

rkr_k is the probability that the item belongs to node kk, or to a new story for k=0k = 0. Along the way the memory obtains the item’s surprise, s=−log⁡∑kπkfk(z)s = -\log \sum_k \pi_k f_k(z), returned as Step.surprise.

The lab below runs exactly these sums, with the library’s formulas. Its three starting nodes are chosen to show one effect: the dormant node C, with almost no mass, takes the item because it is very narrow and the item falls close to it. Switch expiry on to see how that is prevented.

Lab · The read, step by step

Cosine: how close the item is to the node's centre. Mass: the node's recent items. κ: the node's concentration. d = 256, α = 0.01, half-life 48 h, as in the library's defaults.

A · ongoing story
B · broad theme
C · dormant story
Optionmass on arrivalgeometry κ·cosnarrownessprior log(mass/α)advantage (nats)

“Narrowness” is log C(κ) minus the log of the uniform density: what a narrow node pays for concentrating its probability in a small region. The three columns add up to the node's advantage over a new story; a positive advantage means the node beats it.

Look at the size of the columns. Geometry and narrowness are tens or hundreds of nats; the prior is a few. Multiplying a node’s mass by ten adds only 2.3 nats. The decision is almost always taken by the angle between the item and the centres, corrected by concentration; the prior breaks near-ties. For the same reason the posterior is nearly always close to 100 % for one option. On the Portal stream (the history of What the memory keeps):

chosen = np.array([history.share[i] for i in range(len(history))])
print(f"items whose node took over 99% of the posterior: {np.mean(chosen > 0.99):.1%}")
print(f"items whose node took under 60%: {np.mean(chosen < 0.6):.1%}")
Output
items whose node took over 99% of the posterior: 82.8%
items whose node took under 60%:                 2.0%

This gives a useful way to explain the model. Each node behaves as a cosine threshold of its own: an item enters if its cosine with the centre exceeds a value that depends on the node’s concentration. A broad theme (low κ) accepts loosely related items; a compact story (high κ) only very similar ones. Systems with a single fixed threshold treat every story alike; here each node sets its own, from how compact its story is.

Least cosine for a node to beat the new-story slot, by its concentration, with d = 256 and α = 0.01. The two curves, mass 1 and mass 20, almost coincide: mass barely moves the threshold.

Why does a cosine of 0.44 suffice for a node at the cap? Because in 256 dimensions the items of even a tight node do not sit near cosine 1, and unrelated items sit near 0. The cosine lab draws both distributions.

The read also returns how unexpected the item was: s=−log⁡∑kπkfk(z)s = -\log \sum_k \pi_k f_k(z), the negative log-density of the item under the whole memory, prior included. It comes out negative, because a density on a sphere of 256 dimensions can be far larger than 1 (the uniform density alone is about e344e^{344}, which is why the very first item of a stream, read against an empty memory, has a surprise of exactly −344.3); only differences matter. Items that opened a node were, on average, 55 nats more surprising than items that joined one:

print(f"births: {history.born.sum():,} of {len(history):,} items ({history.born.mean():.1%})")
print(f"mean surprise, item that opened a node: {history.surprise[history.born].mean():7.1f} nats")
print(f"mean surprise, item that joined one: {history.surprise[~history.born].mean():7.1f} nats")
Output
births: 7,075 of 49,090 items (14.4%)
mean surprise, item that opened a node:  -336.1 nats
mean surprise, item that joined one:     -391.1 nats

Surprise is recorded for every item (Step.surprise, History.surprise) and is a signal in its own right: a burst of surprising items is a burst of news the memory had no place for.

Without expiry, a narrow node that has had no items for days keeps its centre and its κ; it only loses mass, and mass barely counts. If a new item falls close to its centre, the dormant node wins, even if the live story is another one. Expiry removes nodes whose mass falls below the threshold: with expiry = 0.1 and a half-life of 48 hours, a node of one item expires after 6.6 days, a node of mass 5 after 11.3.

For readers who come from deep learning: the read is a cross-attention layer without parameters. The item is the query, the node centres are the keys, each key has its own temperature κk\kappa_k and its own bias log⁡Cd(κk)+log⁡πk\log C_d(\kappa_k) + \log \pi_k, and it returns the attention weights rather than a mixture of values. Nothing in it is learned: everything comes from the stored sums, which is why the weights are probabilities with a meaning.