preprocess_winogrande.py 731 Bytes
Newer Older
Benjamin Fattori's avatar
Benjamin Fattori committed
1
2
3
4
5
6
def partial_context(doc, option):
    # Substitute the pronoun in the sentence with the specified option
    # and ignore everything after.
    pronoun_loc = doc["sentence"].index("_")
    return doc["sentence"][:pronoun_loc] + option

lintangsutawika's avatar
lintangsutawika committed
7

Benjamin Fattori's avatar
Benjamin Fattori committed
8
9
10
11
12
def partial_target(doc):
    # The target is everything after the document specified pronoun.
    pronoun_loc = doc["sentence"].index("_") + 1
    return doc["sentence"][pronoun_loc:].strip()

lintangsutawika's avatar
lintangsutawika committed
13

Benjamin Fattori's avatar
Benjamin Fattori committed
14
15
16
17
18
19
20
def create_choices(doc):
    choices = []
    for option in [doc["option1"], doc["option2"]]:
        partial_ctx = partial_context(doc, option)
        choices.append(partial_ctx)
    return choices

lintangsutawika's avatar
lintangsutawika committed
21

Benjamin Fattori's avatar
Benjamin Fattori committed
22
23
def gold_alias(doc):
    answer_to_num = {"1": 0, "2": 1}
lintangsutawika's avatar
lintangsutawika committed
24
    return answer_to_num[doc["answer"]]