super_tweeteval / process /tempo_wic.py
asahi417's picture
init
1f8eb0e
raw
history blame
1.38 kB
import json
import os
import pandas as pd
os.makedirs("data/tempo_wic", exist_ok=True)
for s in ['train', 'validation', 'test']:
if s == 'test':
with open(f"misc/TempoWiC/data/test-codalab-10k.data.jl") as f:
data = pd.DataFrame([json.loads(i) for i in f.read().split("\n") if len(i) > 0])
df = pd.read_csv(f"misc/TempoWiC/data/test.gold.tsv", sep="\t")
else:
with open(f"misc/TempoWiC/data/{s}.data.jl") as f:
data = pd.DataFrame([json.loads(i) for i in f.read().split("\n") if len(i) > 0])
df = pd.read_csv(f"misc/TempoWiC/data/{s}.labels.tsv", sep="\t")
df.columns = ["id", "label"]
df.index = df.pop("id")
data = data[[i in df.index for i in data['id']]]
data['label'] = [df.loc[i].values[0] for i in data['id'] if i in df.index]
assert len(df) == len(data)
data_jl = []
for _, i in data.iterrows():
i = i.to_dict()
tmp = {"id": i['id'], "word": i["word"], "label_binary": i["label"]}
tmp.update({f"{k}_1": v for k, v in i['tweet1'].items()})
tmp.update({f"{k}_2": v for k, v in i['tweet2'].items()})
tmp['text_1_tokenized'] = tmp.pop('tokens_1')
tmp['text_2_tokenized'] = tmp.pop('tokens_2')
data_jl.append(tmp)
with open(f"data/tempo_wic/{s}.jsonl", "w") as f:
f.write("\n".join([json.dumps(i) for i in data_jl]))