fix(spatial): 悬空消融要同时清掉结构槽位和边上的标志位
上一版只把 dangling 张量清零,边特征里的 dangling 位还在,于是"消融"测的是 另一条通路。现在 --ablate dangling 两处一起清,也可以传 dangling,scene 组合。
This commit is contained in:
1 parent
8146511a64
commit
f055851ac2
2 files changed
+14
-3
No files matched your search
+1
-1
@@ -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)
|
||||
|
||||
+13
-2
@@ -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"])
|
||||
|
||||
Reference in new issue
Block a user