asahi417's picture
Update process.py
8196f05
raw
history blame
788 Bytes
import json
import os
from itertools import product
from statistics import mean
import pandas as pd
from datasets import load_dataset
def process(split, output):
data = load_dataset("relbert/t_rex", split=split)
df = data.to_pandas()
df.pop('text')
df.pop('title')
df['pairs'] = [[i, j] for i, j in zip(df.pop('head'), df.pop('tail'))]
rel_sim_data = [{
"relation_type": pred,
"positives": g['pairs'].values.tolist(),
"negatives": []
} for pred, g in df.groupby("relation") if len(g) >= 2]
with open(output, "w") as f:
f.write('\n'.join([json.dumps(i) for i in rel_sim_data]))
os.makedirs("data", exist_ok=True)
for s in ['train', 'validation', 'test']:
process(split=s, output=f"data/filter_unified.{s}.jsonl")