asahi417's picture
README
dcf770c
raw
history blame
1.41 kB
import pandas as pd
from datasets import load_dataset
data = load_dataset('relbert/semeval2012_relational_similarity_v3')
stats = []
for k in data.keys():
for i in data[k]:
stats.append(
{
'relation_type': i['relation_type'],
'split': k,
'positives': len(i['positives']),
'negatives': len(i['negatives']),
'level': i['level']
})
df = pd.DataFrame(stats)
df_train = df[df['split'] == 'train']
df_valid = df[df['split'] == 'validation']
stats = []
for (relation_type, level), r in df.groupby(['relation_type', 'level']):
_df_t = r[r['split'] == 'train']
_df_v = r[r['split'] == 'validation']
stats.append({
'relation_type': relation_type,
'level': level,
'positive (train)': 0 if len(_df_t) == 0 else _df_t['positives'].values[0],
'negative (train)': 0 if len(_df_t) == 0 else _df_t['negatives'].values[0],
'positive (validation)': 0 if len(_df_v) == 0 else _df_v['positives'].values[0],
'negative (validation)': 0 if len(_df_v) == 0 else _df_v['negatives'].values[0],
})
df = pd.DataFrame(stats).sort_values(by=['relation_type'])
df.index = df.pop('relation_type')
# sum_pairs = df.sum(0)
# df = df.T
# df['SUM'] = sum_pairs
# df = df.T
df.to_csv('stats.csv')
with open('stats.md', 'w') as f:
f.write(df.to_markdown())