-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
53 lines (53 loc) · 1.87 KB
/
utils.py
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
import pandas as pd
import json
# import xml.etree.ElementTree as et
# from datasets import load_dataset
# import re
#
#
# def readQuora() -> pd.DataFrame:
# quora = pd.read_csv("./data/quora dataset/train.csv")
# return quora
#
#
# def readSNLI(split:str="train") -> pd.DataFrame:
# ds = {"premise":[],"hypothesis":[],"label":[]}
# with open(f"./data/snli_1.0/snli_1.0_{split}.jsonl") as dataJson:
# data = [json.loads(dataJsonLine) for dataJsonLine in dataJson.readlines()]
# ds = [{k:v for (k,v) in i.items() if k in ["sentence1","sentence2","gold_label"]} for i in data]
# return pd.DataFrame(ds)
#
#
# def readRTE(setIndex:int)-> pd.DataFrame:
# xroot = et.parse(f"./data/rte/rte{setIndex}_dev.xml").getroot()
# ds = {"premise":[],"hypothesis":[],"label":[]}
# for i in xroot:
# premise = i[0].text
# hypothesis = i[1].text
# label = i.attrib.get("entailment")
# label = label if label is not None else i.attrib.get("value")
# if label == "YES" or label=="TRUE":
# label = 1
# elif label=="UNKNOWN":
# label = 2
# else:
# label = 0
# ds["premise"].append(premise)
# ds["hypothesis"].append(hypothesis)
# ds["label"].append(label)
# # xroot = et.parse(f"./data/rte/rte{setIndex}_test.xml").getroot()
# # for i in xroot:
# # premise = i[0].text
# # hypothesis = i[1].text
# # label = i.attrib.get("entailment")
# # label = label if label is not None else i.attrib.get("value")
# # if label == "YES" or label =="TRUE":
# # label = 1
# # elif label=="UNKNOWN":
# # label = 2
# # else:
# # label = 0
# # ds["premise"].append(premise)
# # ds["hypothesis"].append(hypothesis)
# # ds["label"].append(label)
# return pd.DataFrame(ds)