Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 3,282 Bytes
24ca5f7
 
a0c348d
 
24ca5f7
 
a0c348d
 
 
 
 
 
 
 
 
 
cb5b67d
 
a36a4f5
 
 
 
 
 
 
 
 
 
 
 
 
 
cb5b67d
 
a36a4f5
 
cb5b67d
a36a4f5
 
 
 
 
 
 
 
 
 
 
 
 
 
cb5b67d
 
a36a4f5
e0c7be5
cb5b67d
a36a4f5
cb5b67d
a36a4f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb5b67d
 
a36a4f5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import os
from itertools import combinations
from random import shuffle, seed
from datasets import load_dataset

# # create analogy from `relbert/semeval2012_relational_similarity`
# data = load_dataset("relbert/semeval2012_relational_similarity", split="validation")
# analogy_data = [{
#     "stem": i['positives'][0], "choice": i["negatives"] + [i['positives'][1]], "answer": 2, "prefix": i["relation_type"]
# } for i in data]
# os.makedirs("dataset/semeval2012_relational_similarity", exist_ok=True)
# with open("dataset/semeval2012_relational_similarity/valid.jsonl", "w") as f:
#     f.write("\n".join([json.dumps(i) for i in analogy_data]))


# # create analogy from `relbert/t_rex_relational_similarity`
# data = load_dataset("relbert/t_rex_relational_similarity", "filter_unified.min_entity_1_max_predicate_100", split="test")
# analogy_data = []
# for i in data:
#     if len(i['positives']) < 2:
#         continue
#     for m, (q, c) in enumerate(combinations(i['positives'], 2)):
#         if m > 5:
#             break
#         negative = i['negatives']
#         for n in range(6):
#             seed(n)
#             shuffle(negative)
#             analogy_data.append({
#                 "stem": q, "choice": [c] + negative[:5], "answer": 0, "prefix": i["relation_type"]
#             })
# os.makedirs("dataset/t_rex_relational_similarity", exist_ok=True)
# with open("dataset/t_rex_relational_similarity/test.jsonl", "w") as f:
#     f.write("\n".join([json.dumps(i) for i in analogy_data]))
#
# data = load_dataset("relbert/t_rex_relational_similarity", "filter_unified.min_entity_4_max_predicate_100", split="validation")
# analogy_data = []
# for i in data:
#     if len(i['positives']) < 5:
#         continue
#     for m, (q, c) in enumerate(combinations(i['positives'], 2)):
#         if m > 5:
#             break
#         negative = i['negatives']
#         for n in range(3):
#             seed(n)
#             shuffle(negative)
#             analogy_data.append({
#                 "stem": q, "choice": [c] + negative[:5], "answer": 0, "prefix": i["relation_type"]
#             })
# os.makedirs("dataset/t_rex_relational_similarity", exist_ok=True)
# with open("dataset/t_rex_relational_similarity/valid.jsonl", "w") as f:
#     f.write("\n".join([json.dumps(i) for i in analogy_data]))

# create analogy from `relbert/conceptnet_relational_similarity`
for s in ['test', 'validation']:
    data = load_dataset("relbert/conceptnet_relational_similarity", split=s)
    analogy_data = []
    for i in data:
        if len(i['positives']) < 2:
            continue
        for m, (q, c) in enumerate(combinations(i['positives'], 2)):
            if m > 5:
                break
            negative = i['negatives']
            for n in range(6):
                seed(n)
                shuffle(negative)
                analogy_data.append({
                    "stem": q, "choice": [c] + negative[:5], "answer": 0, "prefix": i["relation_type"]
                })
    print(len(analogy_data))
    os.makedirs("dataset/conceptnet_relational_similarity", exist_ok=True)
    with open(f"dataset/conceptnet_relational_similarity/{s if s == 'test' else 'valid'}.jsonl", "w") as f:
        f.write("\n".join([json.dumps(i) for i in analogy_data]))