|
import json
|
|
|
|
q_main_types = {}
|
|
q_sub_types = {}
|
|
|
|
for line in open('question_types.txt'):
|
|
if line.startswith(" "):
|
|
sub_type, sub_desc = line.strip().split(maxsplit=1)
|
|
q_sub_types[f"{main_type}:{sub_type}"] = f"{sub_desc}"
|
|
else:
|
|
main_type, main_desc = line.strip().split(maxsplit=1)
|
|
q_main_types[main_type] = main_desc
|
|
|
|
print(q_main_types)
|
|
print(q_sub_types)
|
|
|
|
label2int = {}
|
|
label2int_coarse = {}
|
|
|
|
def prepare(in_path, out_path):
|
|
with open(in_path, encoding='utf8') as fIn, open(out_path, "w") as fOut:
|
|
for line in fIn:
|
|
label, text = line.strip().split(maxsplit=1)
|
|
|
|
label_coarse = label.split(":")[0]
|
|
|
|
if label not in label2int:
|
|
label2int[label] = len(label2int)
|
|
|
|
if label_coarse not in label2int_coarse:
|
|
label2int_coarse[label_coarse] = len(label2int_coarse)
|
|
|
|
|
|
fOut.write(json.dumps({'text': text,
|
|
'label': label2int[label],
|
|
'label_text': q_sub_types[label],
|
|
'label_original': label,
|
|
'label_coarse': label2int_coarse[label_coarse],
|
|
'label_coarse_text': q_main_types[label_coarse],
|
|
'label_coarse_original': label_coarse})+"\n")
|
|
|
|
prepare("train_5500.label", "train.jsonl")
|
|
prepare("TREC_10.label", "test.jsonl") |