File size: 3,498 Bytes
aa7e82c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from scripts.predictions_ground_truth import SCENES_CONFIG

problems = []

for cfg in SCENES_CONFIG:
    scene = ROOT / "data" / "scenes" / cfg["folder"]
    qs = json.loads((scene / cfg["query_file"]).read_text(encoding="utf-8"))
    if isinstance(qs, dict):
        qs = qs["queries"]
    tracks = {
        t["track_id"]: t
        for t in json.loads((scene / cfg["track_file"]).read_text(encoding="utf-8"))["tracks"]
    }
    all_ids = set(tracks)
    for q in qs:
        tids = q.get("target_track_ids") or []
        text = f"{q.get('text_en','')} {q.get('text_zh','')}"
        low = text.lower()
        for t in tids:
            if t not in tracks:
                problems.append((q["query_id"], "missing", t))
        if q.get("query_type") == "C" and tids:
            problems.append((q["query_id"], "C_nonempty", tids))
        if q.get("query_type") in ("A", "B") and not tids and not q.get("distractor"):
            problems.append((q["query_id"], "AB_empty", None))

        if ("everything except" in low) or ("除了" in text and "之外的所有" in text):
            excluded = sorted(all_ids - set(tids))
            print(f"\n{q['query_id']}: targets={len(tids)} excluded={len(excluded)}")
            print(f"  text: {q.get('text_en')}")
            for tid in excluded:
                print(f"  EXCL {tid} | {tracks[tid]['category']}")
            # sanity: excluded categories should match except clause keywords
            excl_blob = " ".join(tracks[t]["category"].lower() for t in excluded)
            clause = low.split("except", 1)[-1] if "except" in low else text.split("除了", 1)[-1]
            for word, toks in [
                ("dog", ["dog"]),
                ("window", ["window"]),
                ("book", ["book"]),
                ("shutter", ["shutter"]),
                ("hand", ["hand", "arm"]),
                ("board", ["board", "wooden"]),
                ("shirt", ["shirt"]),
                ("bottle", ["bottle"]),
                ("spinach", ["spinach"]),
                ("kettle", ["kettle"]),
                ("bowl", ["bowl"]),
            ]:
                if word in clause.lower() or word in clause:
                    if not any(tok in excl_blob for tok in toks):
                        # Chinese extras
                        if word == "hand" and ("手" in clause):
                            if not any(tok in excl_blob for tok in toks):
                                problems.append((q["query_id"], "except_missing_excluded", word))
                        elif word != "hand":
                            problems.append((q["query_id"], "except_missing_excluded", word))
            # wrongly kept in targets
            tgt_blob = " ".join((tracks[t]["category"] or "").lower() for t in tids)
            for word, toks in [
                ("dog", ["dog"]),
                ("window", ["window"]),
                ("book", ["book"]),
                ("shutter", ["shutter"]),
                ("shirt", ["shirt"]),
                ("spinach", ["spinach"]),
            ]:
                if word in clause.lower() and any(tok in tgt_blob for tok in toks):
                    problems.append((q["query_id"], "except_still_in_targets", word))

print("\nPROBLEMS", len(problems))
for p in problems:
    print(p)