feat(spatial): scope 进模型输入,并把泄漏位与合规位分成可分别消融的两片
This commit is contained in:
1 parent
762b4d347d
commit
efe1ee6801
4 files changed
+37
-5
No files matched your search
+3
-1
@@ -309,7 +309,9 @@ 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", "dangling,scene"])
|
||||
help="comma list of dangling | scene | hidden | edge_feat; "
|
||||
"hidden zeroes only the full-state-derived slice of "
|
||||
"the scene features, leaving the scope block intact")
|
||||
sp.set_defaults(fn=fn)
|
||||
args = p.parse_args(argv)
|
||||
return args.fn(args)
|
||||
|
||||
+22
-2
@@ -148,8 +148,28 @@ def scene_features(sc: Scenario) -> list:
|
||||
for kind, cnt in (hidden.get("edge") or {}).items():
|
||||
if kind in EDGE_KINDS:
|
||||
f[4 + len(ENTITY_KINDS) + EDGE_KINDS.index(kind)] = min(1.0, cnt / 3.0)
|
||||
f[-2] = 1.0 if (hidden.get("entity") or hidden.get("edge")) else 0.0
|
||||
f[-1] = len(sc.obs.entities) / 32.0
|
||||
base = 4 + len(ENTITY_KINDS) + len(EDGE_KINDS)
|
||||
f[base] = 1.0 if (hidden.get("entity") or hidden.get("edge")) else 0.0
|
||||
f[base + 1] = len(sc.obs.entities) / 32.0
|
||||
# the declared inventory: what the source says it has versus what it handed
|
||||
# over. No endpoints, so it can suspend an answer but never decide one. This
|
||||
# is the only availability channel the contract allows; the block above is
|
||||
# computed as "full minus visible" and therefore is not something a provider
|
||||
# can produce.
|
||||
scope = sc.obs.scope or {}
|
||||
parts = scope.get("parts") or {}
|
||||
rendered = scope.get("rendered") or {}
|
||||
rel = scope.get("relations") or {}
|
||||
rel_r = scope.get("rendered_relations") or {}
|
||||
tot_parts = sum(parts.values()) or 0
|
||||
tot_rel = sum(rel.values()) or 0
|
||||
f[base + 2] = (tot_parts - sum(rendered.values())) / tot_parts if tot_parts else 0.0
|
||||
f[base + 3] = (tot_rel - sum(rel_r.values())) / tot_rel if tot_rel else 0.0
|
||||
missing_layers = set(scope.get("layers") or []) - set(scope.get("rendered_layers") or [])
|
||||
f[base + 4] = min(1.0, len(missing_layers) / 4.0)
|
||||
f[base + 5] = 1.0 if (scope.get("layers") or []) and (
|
||||
tot_parts > sum(rendered.values()) or tot_rel > sum(rel_r.values())
|
||||
or missing_layers) else 0.0
|
||||
return f
|
||||
|
||||
|
||||
|
||||
+6
-1
@@ -58,7 +58,12 @@ FAR = HOP_MAX + 1 # unreachable, or "involves the query token"
|
||||
# the scene size. Without this the two worlds "no hidden branch exists" and "a
|
||||
# hidden branch exists off-view" are literally the same tensor, and no amount of
|
||||
# reasoning can separate them.
|
||||
SCENE_DIM = 4 + N_KIND + N_EDGE + 2
|
||||
SCENE_DIM = 4 + N_KIND + N_EDGE + 2 + 4
|
||||
# the first block is derived from the full state (what is hidden by kind);
|
||||
# the last four are derived from the declared inventory (scope), which a real
|
||||
# provider can state without endpoints. They live in separate slices so an
|
||||
# ablation can remove one without touching the other.
|
||||
SCENE_HIDDEN = slice(0, 4 + N_KIND + N_EDGE + 2)
|
||||
|
||||
UNK = 1 # position of the unknown slot
|
||||
ENT0 = 2 # first entity position
|
||||
|
||||
+6
-1
@@ -23,7 +23,7 @@ import torch
|
||||
|
||||
from . import checker, generator
|
||||
from .data import collate
|
||||
from .model import N_AXIS, N_EDGE
|
||||
from .model import N_AXIS, N_EDGE, SCENE_HIDDEN
|
||||
from .train import load
|
||||
|
||||
DANGLING_BIT = N_EDGE + N_AXIS + 3
|
||||
@@ -47,6 +47,11 @@ def family_row(model, family: str, seed: int, n: int, max_entities: int = 32,
|
||||
if key == "dangling":
|
||||
t["dangling"] = torch.zeros_like(t["dangling"])
|
||||
t["edge_feat"][..., DANGLING_BIT] = 0.0
|
||||
elif key == "hidden":
|
||||
# the full-state-derived block only: what is withheld *by kind*.
|
||||
# The scope block at the end stays, so this measures exactly the
|
||||
# leak's contribution rather than "any availability signal".
|
||||
t["scene"][:, SCENE_HIDDEN] = 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"],
|
||||
|
||||
Reference in new issue
Block a user