Skip to content

Commit

Permalink
Fix error experiments on RACE because of no all.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
twilightdema committed Mar 22, 2020
1 parent 9b733af commit 16fa2e6
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions race_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,44 @@ def read_examples(self, data_dir):
if level == "high" and self.middle_only: continue
cur_dir = os.path.join(data_dir, level)

cur_path = os.path.join(cur_dir, "all.txt")
with tf.gfile.Open(cur_path) as f:
for line in f:
cur_data = json.loads(line.strip())

answers = cur_data["answers"]
options = cur_data["options"]
questions = cur_data["questions"]
context = self.process_text(cur_data["article"])

for i in range(len(answers)):
label = ord(answers[i]) - ord("A")
qa_list = []

question = self.process_text(questions[i])
for j in range(4):
option = self.process_text(options[i][j])

if "_" in question:
qa_cat = question.replace("_", option)
else:
qa_cat = " ".join([question, option])

qa_list.append(qa_cat)

examples.append(
InputExample(
example_id=cur_data["id"],
context_sentence=context,
start_ending=None,
endings=[qa_list[0], qa_list[1], qa_list[2], qa_list[3]],
label=label
)
)
file_list = os.listdir(cur_dir)
for file_name in file_list:
if not file_name.endswith('.txt'):
continue
cur_path = os.path.join(cur_dir, file_name)
with tf.gfile.Open(cur_path) as f:
for line in f:
cur_data = json.loads(line.strip())

answers = cur_data["answers"]
options = cur_data["options"]
questions = cur_data["questions"]
context = self.process_text(cur_data["article"])

for i in range(len(answers)):
label = ord(answers[i]) - ord("A")
qa_list = []

question = self.process_text(questions[i])
for j in range(4):
option = self.process_text(options[i][j])

if "_" in question:
qa_cat = question.replace("_", option)
else:
qa_cat = " ".join([question, option])

qa_list.append(qa_cat)

examples.append(
InputExample(
example_id=cur_data["id"],
context_sentence=context,
start_ending=None,
endings=[qa_list[0], qa_list[1], qa_list[2], qa_list[3]],
label=label
)
)

return examples

Expand Down

0 comments on commit 16fa2e6

Please sign in to comment.