File size: 1,728 Bytes
aedba02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Build corpus_v2/: the v1 corpus relabelled onto the v2 set + the life/finance scenarios (generate_life_finance.py),
and the held-out eval set. Labels mapped by taxonomy_labels_v2.V1_TO_V2."""
import collections
import json
import random

from taxonomy_labels_v2 import QUESTIONS, V1_TO_V2

rng = random.Random(7)
CAPS = {"conversation": 1300, "transact": 1200}   # keep one class from pulling the head toward collapse


def rows(path):
    return [json.loads(l) for l in open(path) if l.strip()]


def item(state, label, src, id_):
    return {"state": state, "questions": QUESTIONS, "expected": {"loop": label}, "src": src, "id": id_}


train = [item(r["state"], V1_TO_V2[r["expected"]["loop"]], r["src"], r["id"]) for r in rows("corpus/train.jsonl")]
train += [item(r["state"], r["label"], r["src"], r["id"]) for r in rows("corpus_v2/life_finance.jsonl")]
rng.shuffle(train)
kept, count = [], collections.Counter()
for r in train:
    label = r["expected"]["loop"]
    if count[label] < CAPS.get(label, 10**9):
        count[label] += 1
        kept.append(r)
with open("corpus_v2/train.jsonl", "w") as fh:
    for r in kept:
        fh.write(json.dumps(r) + "\n")

# held out: the 24 taxonomy drills, mapped, plus hand-written life/finance boundary cases no template produced
held = [item(r["state"], V1_TO_V2[r["expected"]["loop"]], "drill", r["id"]) for r in rows("corpus/eval_drills.jsonl")]
for i, (text, label) in enumerate(rows_ := [tuple(x) for x in json.load(open("eval_life_finance.json"))]):
    held.append(item(text, label, "lf-eval", f"lfe-{i}"))
with open("corpus_v2/eval.jsonl", "w") as fh:
    for r in held:
        fh.write(json.dumps(r) + "\n")
print("train", len(kept), dict(count), "eval", len(held))