Datasets:

Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
File size: 1,238 Bytes
37c1004
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import random

def winogrande_format(row):
    array = row["pronoun"]
    position_idx = json.loads(array)[1][0]
    # Turn unicode into proper chinese characters
    sent = str(u"{}".format(row["sent"]))
    start_idx = 0
    for i, tok in enumerate(json.loads(row["toks"])):
        tok = str(u"{}".format(tok))
        cur_start_idx = sent.find(tok)
        if i == position_idx:
            break
        sent = sent[cur_start_idx + len(tok):]
        start_idx += cur_start_idx + len(tok)
    # +1 to give room for an optional space
    row["sentence"] = row["sent"][:start_idx] + row["sent"][start_idx:start_idx+len(tok)+1].replace(tok, "_") + row["sent"][start_idx+len(tok)+1:]

    sol = json.loads(row["solution"])

    cor_answer_idx = random.choice([1, 2])
    incor_answer_idx = 2 if cor_answer_idx == 1 else 1

    cor_answer = str(u"{}".format(sol[0][0])) if sol[0][-1] == True else str(u"{}".format(sol[1][0]))
    incor_answer = str(u"{}".format(sol[0][0])) if sol[0][-1] == False else str(u"{}".format(sol[1][0]))

    row[f"option{cor_answer_idx}"] = cor_answer
    row[f"option{incor_answer_idx}"] = incor_answer
    row["answer"] = cor_answer_idx
    return row

# ds = ds.apply(winogrande_format, axis=1)