relational_similarity / process.py
asahi417's picture
init
b496325
raw
history blame contribute delete
855 Bytes
import json
import os
from itertools import chain
from datasets import load_dataset
os.makedirs('data', exist_ok=True)
data_list = [
'relbert/semeval2012_relational_similarity',
'relbert/nell_relational_similarity',
'relbert/t_rex_relational_similarity',
'relbert/conceptnet_relational_similarity',
]
for d in data_list:
if d == 'relbert/t_rex_relational_similarity':
data = load_dataset(d, "filter_unified.min_entity_4_max_predicate_10")
else:
data = load_dataset(d)
for k, v in data.items():
v = [i for i in v]
for _v in v:
_v['negatives'] = list(chain(*[x['positives'] for x in v if x['relation_type'] != _v['relation_type']])) + _v['negatives']
with open(f'data/{os.path.basename(d)}.{k}.jsonl', 'w') as f:
f.write('\n'.join([json.dumps(x) for x in v]))