File size: 1,008 Bytes
1bb8d13 6584ee1 1bb8d13 954cbd4 |
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 31 |
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")
|