Expose the count that a Mean branch discards and test whether the root learns to combine it with item content.
Seed 3605 on gpu: 3 of 3 behavioral checks met. See the measurements below. The experiment code has changed since this run; these measurements describe its earlier version.
Insights
Providing an item count lets the model distinguish totals that an average alone cannot. Every item in a record repeats the same amount, so the branch summary stays unchanged when only the number of copies changes. The ordinary root count field supplies the missing factor needed for a total.
The matched probes require different predictions for the same repeated value at different counts. This isolates learning the amount-times-count relationship from recovering multiplicity through the collection itself. It is a useful diagnostic when a reduction appears to lose mass. The proof covers repeated-value bags and familiar counts; it does not establish sums over arbitrary mixed-value collections.
Setup
Code
"""A visible item count diagnoses cardinality lost by Mean.Learn value times visible cardinality and distinguish matched probes.Run: uv run python proofs/run.py P004"""from __future__ import annotationsfrom collections.abc import Iteratorimport lightning.pytorch as litimport numpy as npimport torchfrom reporting import reportimport relflow as rfPROOF_ID ="P004"TRAIN_MAX =6CAPACITY =12
Examples
Targets use mask=True; the labels below are supervision hidden from the encoder.
Three repetitions of −0.4 require −1.2. Both the repeated value and the visible count vary across the generated records.
Synthetic data and controls
Code
def random_records(*, rows: int, seed: int, minimum: int=1, maximum: int= TRAIN_MAX) -> Iterator[dict]:"""Draw variable-length numerical bags and their mean and sum."""ifnot1<= minimum <= maximum <= CAPACITY:raiseValueError(f"length range must satisfy 1 <= minimum <= maximum <= {CAPACITY}") rng = np.random.default_rng(seed)for _ inrange(rows): length =int(rng.integers(minimum, maximum +1)) values = np.repeat(rng.uniform(-1.0, 1.0), length) row: dict[str, object] = {"items": [{"amount": float(value)} for value in values],"mean_amount": float(values.mean()),"total": float(values.sum()), } row["item_count"] = lengthyield rowdef equal_value_probes(*, value: float, lengths: tuple[int, ...]) ->list[dict]:"""Create matched bags that differ only in repetition count."""ifnot lengths ormin(lengths) <1ormax(lengths) > CAPACITY:raiseValueError(f"probe lengths must be within 1..{CAPACITY}, got {lengths!r}") rows: list[dict[str, object]] = []for length in lengths: row: dict[str, object] = {"items": [{"amount": value}] * length, "mean_amount": value, "total": length * value} row["item_count"] = length rows.append(row)return rowsdef prediction(model: rf.Model, observations: list[dict]) -> np.ndarray: inputs = [{"items": row["items"], "item_count": row["item_count"]} for row in observations] output = model.predict(inputs)["predictions"].to_pylist()return np.asarray([row["record/total"]["content"] for row in output], dtype=np.float64)def rmse(actual: np.ndarray, predicted: np.ndarray |float) ->float:returnfloat(np.sqrt(np.mean(np.square(actual - predicted))))def score(*, train: list[dict], test: list[dict], predicted: np.ndarray) ->dict[str, float]:"""Compare held-out RMSE with the constant training-target mean.""" actual = np.asarray([row["total"] for row in test], dtype=np.float64) baseline = rmse(actual, float(np.asarray([row["total"] for row in train], dtype=np.float64).mean())) measured = rmse(actual, predicted)return {"rmse": measured, "baseline_rmse": baseline, "nrmse": measured / baseline}
Model tree
Figure 1: Mean with item attention off removes multiplicity; a visible root count supplies the missing factor.
How it works
Every item in a record repeats one random amount. The branch uses attention=None and rf.Mean(), so its summary does not change with repetition count. A visible root item_count supplies the missing factor, and learned root attention combines both inputs to predict their product.
Train and test lengths are one through six. Matched probes repeat 0.7 once or six times, requiring totals 0.7 and 4.2. Their predictions must separate by more than 2.5 and stay close to those targets. This isolates learning from a supplied count; the count-free Attention proof tests structural recovery of multiplicity.
Repeat across seeds and test nonidentical bags, missing items, and nested collections. Unseen visible counts have a separate proof; this case checks only the trained count range.
The family’s promotion target is at least three core seeds and ten lightweight calibration seeds.
Reproduce
Run by stable ID from the repository root:
uv run python proofs/run.py P004
Or run the self-contained script directly:
PYTHONPATH=proofs uv run python proofs/aggregation/visible_count_sum.py
Add --accelerator gpu for CUDA or --seed 42 for another seeded experiment. --steps 2 checks execution with a short training budget; it is recorded as a smoke run.