Datasets:

Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
relentless / get_correlation_before.py
asahi417's picture
fix the logit overflow caused by pad_token https://github.com/asahi417/lmppl/issues/5
4a89ca9
import json
from itertools import permutations
from string import ascii_letters
from statistics import mean
import numpy as np
import pandas as pd
with open("data/data_processed.test.jsonl") as f:
data = [json.loads(line) for line in f]
with open("data/data_processed.validation.jsonl") as f:
data += [json.loads(line) for line in f]
tmp = {}
for i in data:
if i['relation_type'] not in tmp:
tmp[i['relation_type']] = i['scores_all']
else:
tmp[i['relation_type']] = i['scores_all'] + tmp[i['relation_type']]
num_annotators = len(list(tmp.values())[0][0])
df = None
for r, scores in tmp.items():
corr_matrix = np.ones((num_annotators, num_annotators)) * 100
for a, b in permutations(range(num_annotators), 2):
score_a = [s[a] for s in scores]
score_b = [s[b] for s in scores]
corr_matrix[a][b] = pd.DataFrame([score_a, score_b]).T.corr("spearman").values[0][1] * 100
corr_df = pd.DataFrame(corr_matrix, columns=[ascii_letters[i].upper() for i in range(num_annotators)],
index=[ascii_letters[i].upper() for i in range(num_annotators)])
corr_df['Others'] = [pd.DataFrame([
[s[a] for s in scores],
[mean(_s for _n, _s in enumerate(s) if _n != a) for s in scores]
]).T.corr("spearman").values[0][1] * 100 for a in range(num_annotators)]
corr_df = corr_df.T
corr_df['Avg'] = corr_df.mean(1)
corr_df = corr_df.T
print(r)
print(corr_df.round(0).astype(int).to_latex())
print()
if df is None:
df = corr_df
else:
df += corr_df
df = df/5
df = df.T
df.pop("Avg")
df['Avg'] = df.mean(1)
df = df.T
print("ALL")
print(df.round(0).astype(int).to_latex())