Commit c827e4ce authored by lintangsutawika's avatar lintangsutawika
Browse files

reformat

parent d1bb50e0
...@@ -200,7 +200,10 @@ def evaluate( ...@@ -200,7 +200,10 @@ def evaluate(
# aggregate Instances by LM method requested to get output. # aggregate Instances by LM method requested to get output.
reqtype = ( reqtype = (
"loglikelihood" "loglikelihood"
if (task.OUTPUT_TYPE == "multiple_choice" or task.OUTPUT_TYPE == "winograd_schema") if (
task.OUTPUT_TYPE == "multiple_choice"
or task.OUTPUT_TYPE == "winograd_schema"
)
else task.OUTPUT_TYPE else task.OUTPUT_TYPE
) # TODO: this is hacky, fix in task.py ) # TODO: this is hacky, fix in task.py
requests[reqtype].extend(task.instances) requests[reqtype].extend(task.instances)
......
...@@ -4,13 +4,11 @@ def doc_to_text(doc): ...@@ -4,13 +4,11 @@ def doc_to_text(doc):
ctxs, doc["question"], doc["final_decision"] ctxs, doc["question"], doc["final_decision"]
) )
def doc_to_target(doc): def doc_to_target(doc):
return " {}".format(doc["final_decision"]) return " {}".format(doc["final_decision"])
def gold_alias(doc): def gold_alias(doc):
dict_to_label = { dict_to_label = {"yes": 0, "no": 1, "maybe": 2}
'yes': 0, return dict_to_label[doc["final_decision"]]
'no': 1,
'maybe': 2
}
return dict_to_label[doc["final_decision"]]
\ No newline at end of file
import ast import ast
def process_ast(string): def process_ast(string):
return ast.literal_eval(string) return ast.literal_eval(string)
def last_problem(doc): def last_problem(doc):
return process_ast(doc["problems"])[-1] return process_ast(doc["problems"])[-1]
def get_answer_option(problem): def get_answer_option(problem):
letter_to_num = {"A": 0, "B": 1, "C": 2, "D": 3} letter_to_num = {"A": 0, "B": 1, "C": 2, "D": 3}
answer = letter_to_num[problem["answer"]] answer = letter_to_num[problem["answer"]]
return problem["options"][answer] return problem["options"][answer]
def create_choices(doc): def create_choices(doc):
problem = last_problem(doc) problem = last_problem(doc)
choices = [problem["options"][i] for i in range(4)] choices = [problem["options"][i] for i in range(4)]
return choices return choices
def doc_to_text(doc): def doc_to_text(doc):
text = "Article: " + doc["article"] + "\n\n" text = "Article: " + doc["article"] + "\n\n"
for problem in process_ast(doc["problems"])[:-1]: for problem in process_ast(doc["problems"])[:-1]:
if problem["question"][-6:] == " _ .": if problem["question"][-6:] == " _ .":
text += ( text += problem["question"][-5:] + get_answer_option(problem) + "\n"
problem["question"][-5:] + get_answer_option(problem) + "\n"
)
else: else:
question = "Question: " + problem["question"] + "\n" question = "Question: " + problem["question"] + "\n"
answer = "Answer: " + get_answer_option(problem) + "\n" answer = "Answer: " + get_answer_option(problem) + "\n"
...@@ -30,6 +33,7 @@ def doc_to_text(doc): ...@@ -30,6 +33,7 @@ def doc_to_text(doc):
text += last_problem(doc)["question"] text += last_problem(doc)["question"]
return text return text
def doc_to_target(doc): def doc_to_target(doc):
letter_to_num = {"A": 0, "B": 1, "C": 2, "D": 3} letter_to_num = {"A": 0, "B": 1, "C": 2, "D": 3}
answer = letter_to_num[last_problem(doc)["answer"]] answer = letter_to_num[last_problem(doc)["answer"]]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment