Datasets:

Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
File size: 2,547 Bytes
1bb8d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import pandas as pd
from datasets import load_dataset

data_valid = load_dataset("cardiffnlp/relentless_full", split="validation")
lc_valid = pd.read_csv("experiments/results_validation/lm_lc/lm.csv", index_col=0)
qa_valid = pd.read_csv("experiments/results_validation/lm_qa/lm.csv", index_col=0)

data_test = load_dataset("cardiffnlp/relentless_full", split="test")
lc = pd.read_csv("experiments/results/lm_lc/lm.csv", index_col=0)
qa = pd.read_csv("experiments/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 = {
    'is competitor/rival of': "Rival",
    'is friend/ally of': "Ally",
    'is influenced by': "Inf",
    'is known for': "Know",
    'is similar to': "Sim"
}
p = 30
table = []
for prompt in ['qa', 'lc']:
    for i in target.keys():
        for d in data_test:
            with open(f"experiments/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"experiments/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("experiments/results_validation/summary_validation.csv")