SamuelYang commited on
Commit
3082e6e
1 Parent(s): 0b8d685

Upload qa_pvalue.py

Browse files
Files changed (1) hide show
  1. qa_pvalue.py +48 -0
qa_pvalue.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from tqdm import tqdm
3
+ import scipy.stats as stats
4
+ def evaluate_retrieval(retrieval_file, topk):
5
+ retrieval = json.load(open(retrieval_file))
6
+ accuracy = { k : [] for k in topk }
7
+ max_k = max(topk)
8
+ for qid in tqdm(list(retrieval.keys())):
9
+ contexts = retrieval[qid]['contexts']
10
+ has_ans_idx = max_k # first index in contexts that has answers
11
+
12
+ for idx, ctx in enumerate(contexts):
13
+ if idx >= max_k:
14
+ break
15
+
16
+ if ctx['has_answer']:
17
+ has_ans_idx = idx
18
+ break
19
+
20
+ for k in topk:
21
+ accuracy[k].append(0 if has_ans_idx >= k else 1)
22
+
23
+ return accuracy
24
+
25
+ if __name__=="__main__":
26
+ topk = [5, 10, 20, 50, 100]
27
+ all_scores_a,all_scores_b=None,None
28
+ for DATA in ["nq","trivia","wq","curated","squad"]:
29
+ FileNameA="/data/t-junhanyang/InfoCSE/QA_TEST/InfoCSE_ICT_K1.{}.test.json".format(DATA)
30
+ FileNameB="/data/t-junhanyang/InfoCSE/QA_TEST/CONPONO.{}.test.json".format(DATA)
31
+ scores_a=evaluate_retrieval(FileNameA,topk)
32
+ if all_scores_a is None:
33
+ all_scores_a=scores_a
34
+ else:
35
+ for k in topk:
36
+ all_scores_a[k]+=scores_a[k]
37
+ print(FileNameB)
38
+ scores_b=evaluate_retrieval(FileNameB,topk)
39
+ if all_scores_b is None:
40
+ all_scores_b=scores_b
41
+ else:
42
+ for k in topk:
43
+ all_scores_b[k]+=scores_b[k]
44
+ print(len(all_scores_a[5]))
45
+ print(len(all_scores_a[100]))
46
+ for k in topk:
47
+ stat_val, p_val = stats.ttest_ind(all_scores_a[k], all_scores_b[k])
48
+ print(str(k)+': '+str(p_val/2))