import pandas as pd from datasets import load_dataset data = load_dataset("cardiffnlp/relentless_full") relation_types = [i['relation_type'] for i in data['test']] full_stats = [] for r in relation_types: size = [len([i for i in data[s] if i['relation_type'] == r][0]['pairs']) for s in ['validation', 'test']] x = [i for i in data['validation'] if i['relation_type'] == r][0] pairs = sorted(zip(x['pairs'], x['ranks']), key=lambda _x: _x[1]) top_pairs = [" / ".join(a) for a, _ in pairs[:2]] bottom_pairs = [" / ".join(a) for a, _ in pairs[:2]] middle_pairs = [" / ".join(a) for a, _ in pairs[int(len(pairs)/2)-1:int(len(pairs)/2) + 1]] full_stats += [{ "relation_type": r, "val.": size[0], "test": size[1], "top_pairs": t, "middle_pairs": m, "bottom_pairs": b} for t, m, b in zip(top_pairs, middle_pairs, bottom_pairs)] df = pd.DataFrame(full_stats) print(df[["relation_type", "val.", "test"]].to_markdown(index=False)) print(df.to_latex(index=False))