diff --git a/spatial/cli.py b/spatial/cli.py index 8999cb2..525033e 100644 --- a/spatial/cli.py +++ b/spatial/cli.py @@ -234,7 +234,7 @@ def main(argv=None) -> int: if name == "report": sp.add_argument("--n", type=int, default=128) sp.add_argument("--ablate", default=None, - choices=[None, "dangling", "scene", "edge_feat"]) + choices=[None, "dangling", "scene", "edge_feat", "dangling,scene"]) sp.set_defaults(fn=fn) args = p.parse_args(argv) return args.fn(args) diff --git a/spatial/report.py b/spatial/report.py index ed2bde3..768d55f 100644 --- a/spatial/report.py +++ b/spatial/report.py @@ -23,8 +23,11 @@ import torch from . import checker, generator from .data import collate +from .model import N_AXIS, N_EDGE from .train import load +DANGLING_BIT = N_EDGE + N_AXIS + 3 + ANSWERS = ("true", "false", "unknown") @@ -36,8 +39,16 @@ def family_row(model, family: str, seed: int, n: int, max_entities: int = 32, t = collate(batch, max_entities) t = {k: (v.to(device) if torch.is_tensor(v) else v) for k, v in t.items()} if ablate: - # a mechanism that survives its own removal was never used - t[ablate] = torch.zeros_like(t[ablate]) + # a mechanism that survives its own removal was never used. The dangling + # signal lives in two places -- the structural unknown slot and a flag on + # the edge itself -- so zeroing only one of them tests the other, not the + # mechanism. + for key in ablate.split(","): + if key == "dangling": + t["dangling"] = torch.zeros_like(t["dangling"]) + t["edge_feat"][..., DANGLING_BIT] = 0.0 + else: + t[key] = torch.zeros_like(t[key]) out = model(t["feat"], t["pad_mask"], t["edge_index"], t["edge_type"], t["edge_mask"], t["q_ents"], t["q_kind"], t["edit_op"], t["edit_idx"], t["edge_removed"], t["edge_feat"], t["scene"], t["dangling"])