Test whether a model trained on smaller visible counts can extend the learned amount-times-count relationship.
Seed 3621 on gpu: 2 of 2 behavioral checks met. See the measurements below. The experiment code has changed since this run; these measurements describe its earlier version.
Insights
Supplying count lets this model extend its learned total to counts absent from training. Mean carries the repeated amount, while the visible count carries multiplicity. Doubling both the bag and its count checks whether predictions respond approximately like a product.
This separates numerical extrapolation from structural counting: the model is told how many items exist. It therefore answers a different question from the Attention proof without a count field. The result supports a limited extension of the amount-times-count relationship, using bags whose values are identical within each record. It does not establish wider mixed-value sums or reliable behavior at arbitrarily large counts.
Setup
Code
"""The explicit-count control should extrapolate more cleanly than hidden count.Require count-aware sum accuracy and duplication scaling out of range.Run: uv run python proofs/run.py P005"""from __future__ import annotationsfrom collections.abc import Iteratorfrom copy import deepcopyimport lightning.pytorch as litimport numpy as npimport torchfrom reporting import reportimport relflow as rfPROOF_ID ="P005"TRAIN_MAX =6CAPACITY =12
Examples
Targets use mask=True; the labels below are supervision hidden from the encoder.
The Mean summary stays the same, while item_count changes from four to eight and the correct total doubles from 1.0 to 2.0.
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 duplicate(observations: list[dict]) ->list[dict]:"""Duplicate every complete bag and update its algebraic targets.""" rows = deepcopy(observations)ifany((len(row["items"]) *2> CAPACITY for row in rows)):raiseValueError(f"duplicated collection exceeds configured capacity {CAPACITY}")for row in rows: row["items"] = [*row["items"], *row["items"]] row["total"] *=2.0 row["item_count"] *=2return 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: The branch uses Mean without item attention; a visible count distinguishes repeated amounts at unseen lengths.
How it works
The schema matches the in-range count control. A Mean item branch has no item attention; its equal-valued bags supply content but lose multiplicity. The root receives item_count as an ordinary Number.
Training counts are one through six. The test uses seven through ten, so accuracy measures count extrapolation. A separate complete-bag duplication intervention also doubles the visible count and requires approximately doubled predictions. It checks whether the learned relationship respects scaling, within a fixed branch capacity of twelve.
Repeat across seeds and broaden the input distributions beyond repeated values. This proof establishes a route with an explicitly supplied count; Attention without a count field covers the separate structural-cardinality claim.
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 P005
Or run the self-contained script directly:
PYTHONPATH=proofs uv run python proofs/aggregation/visible_count_unseen_lengths.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.