|
import json |
|
import pandas as pd |
|
from datasets import load_dataset |
|
|
|
pd.set_option('display.max_rows', None) |
|
pd.set_option('display.max_columns', None) |
|
|
|
data_valid = load_dataset("cardiffnlp/relentless", split="validation") |
|
lc_valid = pd.read_csv("results_validation/lm_lc/lm.csv", index_col=0) |
|
qa_valid = pd.read_csv("results_validation/lm_qa/lm.csv", index_col=0) |
|
|
|
data_test = load_dataset("cardiffnlp/relentless", split="test") |
|
lc = pd.read_csv("results/lm_lc/lm.csv", index_col=0) |
|
qa = pd.read_csv("results/lm_qa/lm.csv", index_col=0) |
|
|
|
target = { |
|
"flan-t5-xxl": "Flan-T5\textsubscript{XXL}", |
|
"flan-ul2": "Flan-UL2", |
|
"opt-13b": "OPT\textsubscript{13B}", |
|
"davinci": "GPT-3\textsubscript{davinci}" |
|
} |
|
pretty_name = { |
|
'competitor/rival of': "Rival", |
|
'friend/ally of': "Ally", |
|
'influenced by': "Inf", |
|
'known for': "Know", |
|
'similar to': "Sim" |
|
} |
|
p = 30 |
|
table = [] |
|
for prompt in ['qa', 'lc']: |
|
for i in target.keys(): |
|
if i in ['flan-t5-xxl', 'flan-ul2'] and prompt == 'lc': |
|
continue |
|
if i in ['opt-13b', 'davinci'] and prompt == 'qa': |
|
continue |
|
|
|
for d in data_test: |
|
with open(f"results/lm_{prompt}/{i}/ppl.{d['relation_type'].replace(' ', '_').replace('/', '__')}.jsonl") as f: |
|
negative_ppl = sorted([json.loads(x)['perplexity'] * -1 for x in f.read().split("\n") if len(x) > 0], reverse=True) |
|
top_pred = negative_ppl[int(len(negative_ppl) * p / 100)] |
|
bottom_pred = negative_ppl[-int(len(negative_ppl) * p / 100)] |
|
scores = sorted(d['scores_mean'], reverse=True) |
|
top = scores[int(len(scores) * p / 100)] |
|
bottom = scores[-int(len(scores) * p / 100)] |
|
|
|
with open(f"results_validation/lm_{prompt}/{i}/ppl.{d['relation_type'].replace(' ', '_').replace('/', '__')}.jsonl") as f: |
|
negative_ppl_valid = [json.loads(x)['perplexity'] * -1 for x in f.read().split("\n") if len(x) > 0] |
|
_d = [x for x in data_valid if x['relation_type'] == d['relation_type']][0] |
|
scores_val = _d['scores_mean'] |
|
false_top = ", ".join([":".join(_d['pairs'][n]) for n, (s, p) in enumerate(zip(scores_val, negative_ppl_valid)) if s <= bottom and p >= top_pred]) |
|
false_bottom = ", ".join([":".join(_d['pairs'][n]) for n, (s, p) in enumerate(zip(scores_val, negative_ppl_valid)) if s >= top and p <= bottom_pred]) |
|
|
|
table.append({ |
|
"prompt": prompt, "model": target[i], "relation": pretty_name[d['relation_type']], "top": false_top, "bottom": false_bottom |
|
}) |
|
|
|
table = pd.DataFrame(table) |
|
table.to_csv("results_validation/qualitative.csv", index=False) |
|
|