import pandas as pd from datasets import load_dataset data = load_dataset('relbert/semeval2012_relational_similarity_v2') 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'])}) df = pd.DataFrame(stats) df_train = df[df['split'] == 'train'] df_valid = df[df['split'] == 'validation'] stats = [] for r in df['relation_type'].unique(): _df_t = df_train[df_train['relation_type'] == r] _df_v = df_valid[df_valid['relation_type'] == r] stats.append({ 'relation_type': r, '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())