shivangibithel
commited on
Commit
•
a2e43c2
1
Parent(s):
39ddb78
Update sotab.py
Browse files
sotab.py
CHANGED
@@ -77,9 +77,13 @@ class WikiTableQuestions(datasets.GeneratorBasedBuilder):
|
|
77 |
CTA_Validation = os.path.join(dl_manager.download_and_extract(dev_url), "CTA_Validation")
|
78 |
CTA_Test = os.path.join(dl_manager.download_and_extract(test_url), "CTA_Test")
|
79 |
|
80 |
-
train_file = "{}.json.gz".format(self.config.name)
|
81 |
-
test_file = "{}.json.gz".format(self.config.name)
|
82 |
-
dev_file = "{}.json.gz".format(self.config.name)
|
|
|
|
|
|
|
|
|
83 |
|
84 |
return [
|
85 |
datasets.SplitGenerator(
|
@@ -100,56 +104,40 @@ class WikiTableQuestions(datasets.GeneratorBasedBuilder):
|
|
100 |
]
|
101 |
|
102 |
def _read_table_from_file(self, table_name: str, root_dir: str):
|
103 |
-
|
104 |
-
_vals =
|
105 |
-
# _vals = [_.replace("\n", " ").strip() for _ in _line.strip("\n").split("\t")]
|
106 |
-
return _vals
|
107 |
-
|
108 |
-
rows = []
|
109 |
-
df_gt = pd.read_csv('CTA_Test_MusicRecording.csv', encoding="utf8")
|
110 |
-
df = pd.read_json("./MusicRecording/"+df_gt.loc[i]["table_name"], compression='gzip', lines=True)
|
111 |
-
df = df.dropna().reset_index(drop=True)
|
112 |
-
correct_label = df_gt.loc[i]["label"]
|
113 |
-
|
114 |
-
if df.empty:
|
115 |
-
op = "None"
|
116 |
-
output_list.append(op)
|
117 |
-
continue
|
118 |
|
119 |
col = []
|
120 |
-
for j in range(len(
|
121 |
col.append("col" + str(j+1))
|
122 |
|
123 |
row = []
|
124 |
-
for index in range(len(
|
125 |
row.append(df.loc[index, :].values.tolist())
|
126 |
|
127 |
# {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
|
|
|
128 |
table_context = {}
|
129 |
table_context["header"] = col
|
130 |
table_context["rows"] = row
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
table_name = table_name.replace(".csv", ".tsv")
|
135 |
-
with open(os.path.join(root_dir, table_name), "r", encoding="utf8") as table_f:
|
136 |
-
table_lines = table_f.readlines()
|
137 |
-
# the first line is header
|
138 |
-
# header = _extract_table_content(table_lines[0])
|
139 |
-
for line in table_lines[1:]:
|
140 |
-
rows.append(_extract_table_content(line))
|
141 |
-
return {"header": header, "rows": rows, "name": table_name}
|
142 |
|
143 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
144 |
def _generate_examples(self, main_filepath, root_dir):
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
77 |
CTA_Validation = os.path.join(dl_manager.download_and_extract(dev_url), "CTA_Validation")
|
78 |
CTA_Test = os.path.join(dl_manager.download_and_extract(test_url), "CTA_Test")
|
79 |
|
80 |
+
# train_file = "{}.json.gz".format(self.config.name)
|
81 |
+
# test_file = "{}.json.gz".format(self.config.name)
|
82 |
+
# dev_file = "{}.json.gz".format(self.config.name)
|
83 |
+
|
84 |
+
train_file = "CTA_training_gt.csv".format(self.config.name)
|
85 |
+
test_file = "CTA_test_gt.csv".format(self.config.name)
|
86 |
+
dev_file = "CTA_validation_gt.csv".format(self.config.name)
|
87 |
|
88 |
return [
|
89 |
datasets.SplitGenerator(
|
|
|
104 |
]
|
105 |
|
106 |
def _read_table_from_file(self, table_name: str, root_dir: str):
|
107 |
+
df_ = pd.read_json(os.path.join(root_dir, table_name), compression='gzip', lines=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
col = []
|
110 |
+
for j in range(len(df_.loc[0])):
|
111 |
col.append("col" + str(j+1))
|
112 |
|
113 |
row = []
|
114 |
+
for index in range(len(df_)):
|
115 |
row.append(df.loc[index, :].values.tolist())
|
116 |
|
117 |
# {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
|
118 |
+
|
119 |
table_context = {}
|
120 |
table_context["header"] = col
|
121 |
table_context["rows"] = row
|
122 |
+
table_context["name"] = table_name
|
123 |
+
|
124 |
+
return table_context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
127 |
def _generate_examples(self, main_filepath, root_dir):
|
128 |
+
|
129 |
+
df = pd.read_csv(main_filepath, encoding="utf8")
|
130 |
+
for ind in df.index:
|
131 |
+
example_id = ind
|
132 |
+
table_name = df['table_name'][ind]
|
133 |
+
column_index = df['column_index'][ind]
|
134 |
+
label = df['label'][ind]
|
135 |
+
table_content = self._read_table_from_file(table_name, root_dir)
|
136 |
+
|
137 |
+
# for idx, line in enumerate(f):
|
138 |
+
# example_id, question, table_name, answer = line.strip("\n").split("\t")
|
139 |
+
# answer = answer.split("|")
|
140 |
+
# # must contain rows and header keys
|
141 |
+
# table_content = self._read_table_from_file(table_name, root_dir)
|
142 |
+
|
143 |
+
yield idx, {"id": example_id, "column_index": column_index, "label": label, "table": table_content}
|