File size: 1,400 Bytes
1d0b885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from data import NODES, collate, make_data


def test_disjoint_graphs_correct_answers_and_reproducibility():
    splits = make_data(200, 60, seed=42)
    assert splits == make_data(200, 60, seed=42)
    graphs = {name: {row["graph_id"] for row in rows} for name, rows in splits.items()}
    assert graphs["train"].isdisjoint(graphs["validation"] | graphs["test"] | graphs["test_long"])
    assert graphs["validation"].isdisjoint(graphs["test"] | graphs["test_long"])
    for name, rows in splits.items():
        identities = set()
        for row in rows:
            mapping = dict(zip(NODES, row["graph_id"]))
            node = row["path"][0]
            for _ in range(row["hops"]):
                node = mapping[node]
            assert node == row["answer"].strip()
            assert len(row["path"]) == row["hops"] + 1
            assert row["hops"] in ((4, 5, 6) if name == "test_long" else (1, 2, 3))
            identity = (row["graph_id"], row["path"][0], row["hops"])
            assert identity not in identities
            identities.add(identity)


def test_collation_masks_prompt_and_padding():
    batch = collate([([3, 4, 5], [-100, -100, 5]), ([6, 7], [-100, 7])], 0)
    assert batch["input_ids"].tolist() == [[3, 4, 5], [6, 7, 0]]
    assert batch["labels"].tolist() == [[-100, -100, 5], [-100, 7, -100]]
    assert batch["attention_mask"].tolist() == [[1, 1, 1], [1, 1, 0]]