|
""" |
|
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_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() |
|
|