Background ideas
A text as a list of numbers
Section titled “A text as a list of numbers”A sentence encoder is a neural network trained so that two sentences with similar meaning give similar lists of numbers. That list is called an embedding, or a vector. Picture it as an arrow in a space of many dimensions, one coordinate per number. Two news items about the same event give arrows pointing in nearby directions.
The cosine and the sphere
Section titled “The cosine and the sphere”If every arrow is scaled to length 1, only its direction matters, and all the tips lie on a sphere of radius 1. Closeness between two points is measured by the cosine of their angle: 1 if they point the same way, 0 if they are perpendicular, −1 if opposite. For unit vectors the cosine is the dot product, .
A fact worth keeping in mind: in 256 dimensions, two random directions have cosine close to 0. There are so many directions that being nearly perpendicular to everything is the norm, and a cosine of 0.5 already signals a strong relation. The lab below shows it, together with the bell of the next sections: drag the dimension from 3 to 256 and watch both curves move.
Lab · Where a node's items fall
The curve is the distribution of the cosine between a node's centre and the items a von Mises–Fisher node of concentration κ produces, in d dimensions. With κ = 0 it is the cosine between two random directions: where a new story's items fall with respect to any node.
In three dimensions a node of κ = 350 is a tiny cap and its items sit at cosine 0.997. In 256 dimensions the same κ puts them around 0.7, never near 1: there is so much room that even a tight story's items are far from its centre, while two random items sit near 0. The gap between the two curves, not the closeness to 1, is what lets the memory tell them apart. (Real nodes are less tidy than the model: on the Portal stream, two items of the same node have cosine 0.45 on average, between 0.14 and 0.72 for 90 % of pairs.)
Centring and principal components
Section titled “Centring and principal components”Embeddings of texts from one source tend to share a common direction, the topics and register typical of that source. Left in place, it makes every text look somewhat similar to every other, so the mean of a reference sample is subtracted. Principal component analysis (PCA) then keeps the d directions along which the texts vary most, like photographing a cloud of points from the angle that best shows its shape. The mean and the directions are computed once, on a reference sample, never on the stream being read. The projection shows both steps on real data, and why it is a PCA rather than UMAP or t-SNE.
Density and likelihood
Section titled “Density and likelihood”A probability density says where points are likely to fall. Evaluating a model’s density at a given point gives its likelihood: how well the point fits the model. In 256 dimensions these numbers are huge or tiny, so we work with their logarithm, and differences are measured in nats: 1 nat means about 2.7 times more likely, 10 nats about 22,000 times, 100 nats an astronomical factor.
A bell on the sphere: von Mises–Fisher
Section titled “A bell on the sphere: von Mises–Fisher”The Gaussian describes data gathered around a mean. The von Mises–Fisher distribution (vMF) is its counterpart on a sphere: points gather around a central direction , with a concentration . With points spread evenly over the whole sphere; with large they gather in a small cap.
The likelihood of a point is its cosine with the centre, scaled by the concentration, plus a constant that depends only on the concentration. That constant makes the total probability 1: a narrow bell is taller at the centre but falls off faster. Computing it needs a Bessel function; vmfstream uses its uniform asymptotic expansion, which stays finite at .
Prior, likelihood and posterior
Section titled “Prior, likelihood and posterior”To decide which node an item belongs to, two things are combined. The prior is how likely each node is before looking at the item: a story receiving many items right now is more likely to begin with. The likelihood is how well the item fits each node. Bayes’ rule says the posterior, the probability after looking, is proportional to prior × likelihood; in logarithms, a sum. The softmax function turns those sums into probabilities that add to 1. It is the same operation as in the attention layers of a transformer.
The Chinese restaurant
Section titled “The Chinese restaurant”The Chinese restaurant process is a classic prior for when the number of groups is unknown. A new customer sits at an occupied table with probability proportional to the number of people already there, or opens a new table with probability proportional to a fixed . In vmfstream the tables are nodes, customers are items, and the number of people is the node’s mass. Large stories attract more, but there is always a door open to a new one.
Exponential forgetting and half-life
Section titled “Exponential forgetting and half-life”Forgetting exponentially means multiplying everything by the same factor for each hour that passes. The half-life is the time it takes to halve. With hours an item weighs 1 on arrival, 0.5 after two days, 0.25 after four and a little under 0.1 after a week. The factor after hours is with , so there is no need to remember when each item arrived: multiplying the total by the factor for the time elapsed is enough.
Sufficient, additive statistics
Section titled “Sufficient, additive statistics”To know the centre and the spread of a group of arrows you do not need every arrow: the sum of the arrows and how many there are suffice. Such numbers are sufficient statistics. They are also additive: adding an item is a sum, merging two groups is a sum of their summaries, and with exponential forgetting, ageing a group is a product. The whole memory runs on these three operations. There is no gradient descent, no weights and no epochs.