File size: 868 Bytes
b789ed3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from glob import glob
from random import shuffle, seed

target = ['nell_relational_similarity', 'conceptnet_relational_similarity', 't_rex_relational_similarity']

for t in target:
    for i in glob(f"dataset/{t}/*.jsonl"):
        with open(i) as f:
            tmp = [json.loads(x) for x in f.read().split('\n') if len(x) > 0]
        for n, y in enumerate(tmp):
            answer_original = y['choice'][y['answer']]
            choice = y['choice']
            seed(n)
            shuffle(choice)
            index = list(range(len(y['choice'])))
            seed(n)
            shuffle(index)
            answer = index.index(y['answer'])
            assert answer_original == choice[answer]
            y['choice'] = choice
            y['answer'] = answer

        with open(i, 'w') as f:
            f.write("\n".join([json.dumps(x) for x in tmp]))