Skip to content

Commit 4bdca0e

Browse files
committed
model output shape matches model input shape.
1 parent 034028c commit 4bdca0e

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

benchmarks/nn.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,19 @@ def init_weight(inp: int, out: int):
392392
f"train_acc {acc['train']:.3f} test_acc {acc['test']:.3f}"
393393
)
394394

395-
# The trained weights come back out as xarray as one relation: a ragged
396-
# weight(layer, inp, out) array (absent cells are NaN where layers are narrower).
397-
trained = (
398-
ctx.sql("SELECT layer, inp, out, val FROM weight")
399-
.to_dataset(dims=["layer", "inp", "out"])
400-
.rename({"val": "weight"})
395+
# The trained weights come back out as xarray in the *same shape as the input
396+
# model*: one data variable per layer with its own (inp_i, out_i) dims. Each
397+
# layer is read from the weight relation by its `layer` column, so the result
398+
# is a ragged set of per-layer matrices — no dense (layer, inp, out) array
399+
# padded with NaN.
400+
trained = xr.Dataset(
401+
{
402+
f"layer_{i}": ctx.sql(
403+
f"SELECT inp AS inp_{i}, out AS out_{i}, val AS layer_{i} "
404+
f"FROM weight WHERE layer = {i}"
405+
).to_dataset(dims=[f"inp_{i}", f"out_{i}"])[f"layer_{i}"]
406+
for i in range(len(WIDTHS) - 1)
407+
}
401408
)
402409
print(f"trained {WIDTHS} MLP; weights -> xarray {dict(trained.sizes)}.")
403410
print(trained)

0 commit comments

Comments
 (0)