from statistics import mean import pandas as pd from datasets import load_dataset data = load_dataset("cardiffnlp/relentless", split='test') cor = [] for d in data: true_rank = sorted(d['ranks']) corr_tmp = [] for a in range(7): single_pred = [x[a] for x in d['scores_all']] rank_map = {p: n for n, p in enumerate(sorted(single_pred), 1)} single_pred = [rank_map[p] for p in single_pred] pred = [mean(_x for n, _x in enumerate(x) if n != a) for x in d['scores_all']] rank_map = {p: n for n, p in enumerate(sorted(pred), 1)} pred = [rank_map[p] for p in pred] corr_tmp.append(pd.DataFrame([single_pred, pred]).T.corr("spearman").values[1][0]) cor.append({"relation": d['relation_type'], "Avg.\ of others": mean(corr_tmp)}) df = pd.DataFrame(cor) df.index = df.pop("relation").values df = df.sort_index() df = df.T df['average'] = df.mean(axis=1).round(1) print(df.to_markdown()) print(df.to_latex()) df.to_csv("results/oracle.csv")