Skip to content

Evaluation with labels

When a stream has reference labels, vmfstream.metrics measures how well the nodes match them. This page reproduces the paper’s benchmark: its three test streams, News14, WCEP18 and WCEP19, encoded with SentenceEncoder, and the projection fitted on its development stream. The datasets are not distributed with vmfstream; the code is the same for any labelled stream.

import numpy as np
reference = np.load("reference.npy") # the paper's development stream (Newsfeed, 2015)
benchmark = np.load("benchmark.npz") # its three test streams, encoded the same way
for name in ("news14", "wcep18", "wcep19"):
stories = benchmark[f"{name}_stories"]
print(f"{name}: {len(stories):,} articles, {len(np.unique(stories)):,} stories")
Output
news14: 16,136 articles, 788 stories
wcep18: 47,038 articles, 828 stories
wcep19: 29,931 articles, 519 stories

For each item, B³ precision is the share of the items in its node that share its label, and recall the share of the items with its label that share its node; both are averaged over items (Bagga and Baldwin, 1998). Precision falls when a node mixes stories, recall when a story is split over nodes, and F1 is their harmonic mean.

Published results in online story discovery score sliding windows of seven days, advanced one day at a time, and average over windows; each window is scored on the nodes the items were given when they arrived. windowed_bcubed reproduces that protocol, from the evaluation code of SCStory, which the paper follows:

from vmfstream import Memory
from vmfstream.metrics import windowed_bcubed
for config, make in [("Memory()", Memory), ("Memory.main()", Memory.main)]:
for name in ("news14", "wcep18", "wcep19"):
hours, stories = benchmark[f"{name}_hours"], benchmark[f"{name}_stories"]
memory = make().fit_projection(reference)
history = memory.read(benchmark[f"{name}_embeddings"], hours)
days = np.round(hours / 24).astype(int)
p, r, f1 = windowed_bcubed(stories, history.node, days)
nodes = history.node.max() + 1
print(f"{config:<14} {name} P {p:.3f} R {r:.3f} F1 {f1:.3f} {nodes} nodes")
Output
Memory()       news14  P 0.881  R 0.866  F1 0.869  552 nodes
Memory()       wcep18  P 0.843  R 0.791  F1 0.812  615 nodes
Memory()       wcep19  P 0.858  R 0.818  F1 0.835  379 nodes
Memory.main()  news14  P 0.842  R 0.931  F1 0.880  625 nodes
Memory.main()  wcep18  P 0.779  R 0.883  F1 0.825  607 nodes
Memory.main()  wcep19  P 0.781  R 0.890  F1 0.829  366 nodes

These are the paper’s numbers. With Memory.main() the scores are identical to the published ones (0.880, 0.825, 0.829); with Memory() they differ by at most 0.002 (published: 0.867, 0.811, 0.835), within what rounding moves them, because the soft write is sensitive to the precision of the arithmetic (see Determinism and rounding). Note that these runs use the published encoder: the paper’s main result, B³ F1 of 0.899, 0.861 and 0.877, needs the adapted encoder, which vmfstream does not distribute yet.

Over the whole stream at once, the same assignment scores much lower:

from vmfstream.metrics import bcubed
hours, stories = benchmark["wcep19_hours"], benchmark["wcep19_stories"]
history = Memory().fit_projection(reference).read(benchmark["wcep19_embeddings"], hours)
print("wcep19, whole stream at once: B3 P %.3f R %.3f F1 %.3f" % bcubed(stories, history.node))
Output
wcep19, whole stream at once: B3 P 0.390  R 0.811  F1 0.527

Recall barely moves; precision collapses. A node lives for weeks or months and, over that time, gathers many stories that the labels keep apart; within a week it rarely holds more than one. The window protocol asks what an online system should answer: which items, among the recent ones, belong together.

How finely a stream should be split is also a convention of the annotators. WCEP splits a long saga into separate events, while the memory keeps the saga in one node as long as its items keep arriving, and B³ counts that as merging.

The paper chose every hyperparameter once, on the development stream, and never looked at the test streams to choose. For a new kind of stream, do the same: choose max_concentration, half_life and alpha on a labelled sample with windowed_bcubed, then read the rest with those values unchanged.