Skip to content

Memory explorer

The explorer fills the window with one stream: the Wikipedia Current Events Portal from 2016 to 2024, 49,090 items, read with the library’s two presets and with one setting changed at a time from each, 28 readings in all. It opens on 3 March 2022, a week into the invasion of Ukraine, with Memory(). Press Play, drag the timeline, click anything, and change the settings in the bar at the top.

The explorer on 3 March 2022: the reading bar, the memory's table, the sphere with the parts of the selected node, the inspector with its words and parts, and the timeline

Every reading was made by the Python library before the page was built; the browser reads nothing. The bar offers the two presets and each setting that differs among the readings, with the values that were read. Choosing a value switches to the reading that has it and shares most of the other settings with the current one, so from Memory() the half-life buttons change only the half-life, and from Memory.main() they keep its cap, expiry and hard write. The day, and any item or node you selected, stay put; a node is followed through its latest item to the node that holds that item in the new reading.

The page computes what it shows of each reading (concentration, drift, colours, labels) in the background as soon as it opens, so switching is immediate once the bar no longer says how many readings are left.

The numbers below are those of the readings in the page, counted with the Python library; each changes one setting of Memory(), which opens 7,075 nodes over the nine years, the largest with 3,451 items. With Memory() the 256 rows of the table are full at the end of every reading, so the count of nodes is the count of stories the memory opened.

The half-life. It decides how long a quiet story waits for its next item. With 12 hours the memory opens 13,201 nodes and none grows beyond 542 items. With a week it opens 977, and one of them takes 12,109 items, a quarter of the stream. Play the timeline at both ends to see the bands break up or merge.

The concentration cap. Lowering it to 150 makes every node broader: 693 nodes cover the nine years. Raising it from 500 to 1000 leaves the count as it is (7,074 against 7,075), but fewer nodes reach 20 items, 81 against 217.

alpha. Four orders of magnitude, from 0.0001 to 1, take the memory from 4,183 nodes to 8,761, about a factor of two. In 256 dimensions the angle to the centres decides where an item goes, and the prior only breaks near-ties (The read).

Expiry. With 0.1, a node leaves once its mass falls below 0.1, and only 39 nodes are in memory at the end. A story that returns after its node left opens a new one, so more nodes are born (8,063); with 0.5, 9,345, and 5,760 of them receive a single item.

Hard write. It changes little on its own: 7,115 nodes against 7,075, the largest with 3,924 items against 3,451. Memory.main() combines it with a cap of 350 and an expiry of 0.1, and opens 8,376 nodes, 37 of them in memory at the end.

The sphere shows the memory at the end of the chosen day. Every item is a point, coloured by the node it went to, and fades as the memory forgets it, with the memory’s half-life. Under the points, each node is a von Mises–Fisher density, drawn per pixel. The buttons at the top right choose how:

  • density colours each place by the nodes probable there, with an intensity that grows with the probability compared with the uniform density of a new story; territories colours it by the node an item there would most likely join, and hatches the places where no node is denser than uniform.
  • relief raises the surface by the mass density, so a busy, concentrated node is a sharp peak and a broad one a dome; contours draws its level lines; borders marks where two nodes are equally likely; grid and glow are only for orientation.

Colours blend by the posterior, so a border is soft where an item would be split between nodes. Relief, contours, grid and glow are on when the page opens; the choice is kept in the browser. Scroll into the sphere and the nodes show their words; closer, their parts, each in a shade of the node’s colour (Parts and words). Hover a point to read its item. While the timeline plays, the camera turns slowly towards the region with most mass in memory (uncheck Follow to stop it).

The timeline shows the mass of every node over the whole stream, each as its own area from the base line: the largest behind, the smaller in front of them, the twelve largest in the colours of the inspector’s list. An area grows while its node receives items and thins with the half-life once they stop. Drag the timeline to move through the days; click an area to inspect its node.

The memory on this day lists the rows of the memory’s table, heaviest first, with each node’s mass, its concentration κ, its age and the items it received that day. Nodes born that day are marked in green; nodes that left are listed at the end. Below, a log of the day: the busiest nodes, the births and the departures. With Memory() expiry is off, so a node leaves only when the table is full and a new node takes the row of the lightest one.

The inspector opens on whatever you click. For a node: when it was born and when it left, its mass, concentration and drift over its life (the cosine between its centre and its first one), its words and its parts on the chosen day, its exemplars up to that day, its latest items, and the nodes closest to it. For an item: its text, its node, its surprise and the best options of its read, with each option’s advantage over a new story in nats, which explains why the item went where it went. The search box has two modes. word finds the items that contain the text and the nodes with most of them. meaning finds the items and nodes closest to those items in the memory’s own space, by cosine to their average direction (the page cannot embed a query: the encoder is not in it), and marks the items that do not contain the word: for Brexit, votes on the Withdrawal Agreement Bill that never use it. The results come in two tabs, nodes and items; opening one keeps the search, with a link back. The timeline draws the weight the matching items keep in memory (each fading with the half-life, like the points), and the page moves to the day it peaks: for Brexit by word, 4 September 2019.

  • Every point is an item, coloured by the node the memory gave it on arrival. Which nodes are in memory on each day, their masses, the births and the departures are what the memory did.
  • Concentration, drift and nearest nodes are recomputed from the history with History.statistics, in the memory’s 256 dimensions. With the soft write of Memory() the history keeps only each item’s share in its own node, so these values miss the tiny slivers of other items; with hard write they are exact.
  • The options of each read come from the read itself (Memory.read(..., candidates=3)). Only the two presets were read with them, to keep the page lighter; for the other readings the inspector says so.
  • The positions on the sphere are the same for every reading, so that a point stays where it is when you switch. They come from a spherical UMAP (output metric haversine), which takes the 256-dimensional points to the surface of an ordinary sphere. It keeps which items are neighbours, not distances or angles: two caps far apart in the drawing are not necessarily dissimilar.
  • So each node’s density on the sphere is refitted to the 3-D positions, and densities, territories and relief are drawn from those. Its concentration is not the κ the memory decides with in 256 dimensions (that one is in the table and the inspector), and a node whose items the layout spreads looks broader than it is. The territories show the most probable node on the drawing, not the memory’s decision, which is made in 256 dimensions.
  • Densities are drawn for nodes with mass of at least 0.1, and points for items whose weight is at least 0.01, so that the drawing can be read.

Read the stream as usual, then open the explorer on it. serve starts a small service on this machine and opens the page in the browser:

from vmfstream import Memory
from vmfstream.viz import serve
memory = Memory().fit_projection(reference)
points = memory.project(embeddings) # the stream on the memory's sphere
history = memory.read(points, hours, projected=True, candidates=3) # keep the options of every read
serve(history, points=points, titles=texts, start=start_date) # Ctrl-C to stop

With points, the bar offers every setting of the grid and the two presets, not only the readings you made. A value in italics has not been read yet: choosing it makes the library read the stream with it, there, with Memory.read, and the page switches to the new reading when it is done. On the Portal stream (49,090 items) that takes about half a minute; a reading made once is kept for the session, and with cache="readings/" across sessions. Readings are made one at a time, and explorer.readings holds all of them.

The service listens only on this machine (host="0.0.0.0" shares it with the local network) and sends nothing elsewhere; the page loads three.js from a CDN. The positions on the sphere come from sphere_layout (spherical UMAP), computed when serve starts unless you pass layout=; on a long stream it takes a while, so keep it if you will serve again. In a notebook, explorer = serve(..., block=False) returns at once, and explorer.stop() ends it.

explorer_html writes the same page as a single HTML file with the data inside, to send or publish (the explorer of these docs is one). It carries only the readings you give it:

from vmfstream.viz import explorer_html, sphere_layout
variants = [Memory(half_life=h).fit_projection(reference).read(embeddings, hours) for h in (24.0, 96.0)]
explorer_html(history, "explorer.html", layout=sphere_layout(history), titles=texts, start=start_date, variants=variants)

The points take about one byte per coordinate and item, and each reading a few hundred kilobytes per 50,000 items. scripts/build_explorer.py builds the documentation’s explorer this way.