File size: 1,858 Bytes
115c8c7
 
 
 
 
54e3764
115c8c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa0beeb
115c8c7
 
 
 
54e3764
 
115c8c7
 
 
 
 
 
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
80
81
"""
Convert the json data to a parquet file
"""

import json
import random

import pandas as pd


def load_domains_map():
    """
    Load the domain mapping from the json file
    """
    with open("oos-eval-master/data/domains.json", "r", encoding="utf8") as f:
        domains = json.loads(f.read())

    domain_map = []
    label_map = []

    label2domain = {"oos": ("oos", 0, 0)}  # domain, domain_id, label_id

    domain_map.append((0, "oos"))
    label_map.append((0, "oos"))

    domain_id = 1
    label_id = 1

    for domain, labels in domains.items():
        for label in labels:
            label2domain[label] = (domain, domain_id, label_id)
            label_map.append((label_id, label))
            label_id += 1

        domain_map.append((domain_id, domain))
        domain_id += 1

    with open("domain_map.txt", "w", encoding="utf8") as f:
        for domain_id, domain in domain_map:
            f.write(f"{domain_id}\t{domain}\n")

    with open("label_map.txt", "w", encoding="utf8") as f:
        for label_id, label in label_map:
            f.write(f"{label_id}\t{label2domain[label][0]}:{label}\n")

    return label2domain


LABEL_2_DOMAIN = load_domains_map()


def run():
    """
    Convert the json data to a parquet file
    """
    rows = []

    with open("oos-eval-master/data/data_full.json", "r", encoding="utf8") as f:
        data = json.loads(f.read())

    for split in data:
        for text, label in data[split]:

            rows.append(
                {
                    "text": text,
                    "domain": LABEL_2_DOMAIN[label][1],
                    "intent": LABEL_2_DOMAIN[label][2],
                    "split": split,
                }
            )

    random.shuffle(rows)

    df = pd.DataFrame(rows)
    df.to_csv("data_full.csv", index=False)


if __name__ == "__main__":
    run()