File size: 1,140 Bytes
ba55817 53fb42f 1a38689 53fb42f b8d20b5 ba55817 b8d20b5 53fb42f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from itertools import chain
import pandas as pd
from datasets import load_dataset
def get_stats():
relation = []
entity = []
size = {}
data = load_dataset("relbert/nell")
splits = data.keys()
for split in splits:
df = data[split].to_pandas()
size[split] = len(df)
relation.append(df.groupby('relation')['head'].count().to_dict())
entity += [df.groupby('head_type')['head'].count().to_dict(), df.groupby('tail_type')['tail'].count().to_dict()]
relation = pd.DataFrame(relation, index=[f"number of pairs ({s})" for s in splits]).T
relation = relation.fillna(0).astype(int)
entity = pd.DataFrame(entity, index=list(chain(*[[f"head ({s})", f"tail ({s})"] for s in splits]))).T
entity = entity.fillna(0).astype(int)
size = pd.DataFrame([size], index=["number of pairs"])
return relation, entity, size
df_relation, df_entity, df_size = get_stats()
print(f"\n- Number of instances\n\n {df_size.to_markdown()}")
print(f"\n- Number of pairs in each relation type\n\n {df_relation.to_markdown()}")
print(f"\n- Number of entity types\n\n {df_entity.to_markdown()}")
|