Liyan06 commited on
Commit
a496016
·
1 Parent(s): 591028c

return ranked docs and scores

Browse files
Files changed (1) hide show
  1. handler.py +31 -2
handler.py CHANGED
@@ -1,11 +1,40 @@
1
  from minicheck_web.minicheck import MiniCheck
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class EndpointHandler():
4
  def __init__(self, path="./"):
5
  self.scorer = MiniCheck(path=path)
6
 
7
  def __call__(self, data):
8
 
9
- _, raw_prob, _, _ = self.scorer.score(data=data)
 
 
 
 
 
 
10
 
11
- return raw_prob
 
 
 
 
 
 
1
  from minicheck_web.minicheck import MiniCheck
2
 
3
+
4
+ def sort_chunks_single_doc_claim(used_chunk, support_prob_per_chunk):
5
+ '''
6
+ Sort the chunks in a single document based on the probability of "supported" in descending order.
7
+ This function is used when a user document is provided.
8
+ '''
9
+
10
+ flattened_docs = [doc for chunk in used_chunk for doc in chunk]
11
+ flattened_scores = [score for chunk in support_prob_per_chunk for score in chunk]
12
+
13
+ doc_score = list(zip(flattened_docs, flattened_scores))
14
+ ranked_doc_score = sorted(doc_score, key=lambda x: x[1], reverse=True)
15
+
16
+ ranked_docs, scores = zip(*ranked_doc_score)
17
+
18
+ return ranked_docs, scores
19
+
20
+
21
  class EndpointHandler():
22
  def __init__(self, path="./"):
23
  self.scorer = MiniCheck(path=path)
24
 
25
  def __call__(self, data):
26
 
27
+ _, _, used_chunk, support_prob_per_chunk = self.scorer.score(data=data)
28
+
29
+ # Using user-provided document to do fact-checking
30
+ if data['inputs']['docs'] != "":
31
+ ranked_docs, scores = sort_chunks_single_doc_claim(used_chunk, support_prob_per_chunk)
32
+ else:
33
+ raise NotImplementedError("Currently, only user-provided document is supported.")
34
 
35
+ outputs = {
36
+ 'ranked_docs': ranked_docs,
37
+ 'scores': scores
38
+ }
39
+
40
+ return outputs