29
29
from rouge_metric .rouge import Rouge
30
30
31
31
EMPTY = ''
32
- YESNO_LABELS = set (['None' , ' Yes' , 'No' , 'Depends' ])
32
+ YESNO_LABELS = set (['Yes' , 'No' , 'Depends' ])
33
33
34
34
35
35
def normalize (s ):
@@ -62,19 +62,18 @@ def data_check(obj, task):
62
62
assert 'question_type' in obj , \
63
63
"Missing 'question_type' field. question_id: {}" .format (obj ['question_type' ])
64
64
65
- #if task == 'yesno' and obj['question_type'] == 'YES_NO':
66
65
assert 'yesno_answers' in obj , \
67
66
"Missing 'yesno_answers' field. question_id: {}" .format (obj ['question_id' ])
68
67
assert isinstance (obj ['yesno_answers' ], list ), \
69
68
r"""'yesno_answers' field must be a list, if the 'question_type' is not
70
69
'YES_NO', then this field should be an empty list.
71
70
question_id: {}""" .format (obj ['question_id' ])
72
71
73
- #if task == 'entity' and obj['question_type'] == 'ENTITY':
74
- assert 'entities' in obj , \
75
- "Missing 'entities' field. question_id: {}" . format (obj ['question_id' ])
76
- assert isinstance ( obj [ 'entities' ], list ) and len (obj ['entities ' ]) > 0 , \
77
- r"""'entities ' field must be a list, and has at least one element,
72
+ assert 'entity_answers' in obj , \
73
+ "Missing 'entity_answers' field. question_id: {}" . format ( obj [ 'question_id' ])
74
+ assert isinstance (obj ['entity_answers' ], list ) \
75
+ and len (obj ['entity_answers ' ]) > 0 , \
76
+ r"""'entity_answers ' field must be a list, and has at least one element,
78
77
which can be a empty list. question_id: {}""" .format (obj ['question_id' ])
79
78
80
79
@@ -89,10 +88,10 @@ def read_file(file_name, task, is_ref=False):
89
88
Returns:
90
89
A dictionary mapping question_id to the result information. The result
91
90
information itself is also a dictionary with has four keys:
92
- - question_type: type of the question .
91
+ - question_type: type of the query .
93
92
- yesno_answers: A list of yesno answers corresponding to 'answers'.
94
93
- answers: A list of predicted answers.
95
- - entities : A list, each element is also a list containing the entities
94
+ - entity_answers : A list, each element is also a list containing the entities
96
95
tagged out from the corresponding answer string.
97
96
"""
98
97
def _open (file_name , mode , zip_obj = None ):
@@ -101,7 +100,7 @@ def _open(file_name, mode, zip_obj=None):
101
100
return open (file_name , mode )
102
101
103
102
results = {}
104
- keys = ['answers' , 'yesno_answers' , 'entities ' , 'question_type' ]
103
+ keys = ['answers' , 'yesno_answers' , 'entity_answers ' , 'question_type' ]
105
104
if is_ref :
106
105
keys += ['source' ]
107
106
@@ -194,8 +193,8 @@ def prepare_prf(pred_dict, ref_dict):
194
193
"""
195
194
Prepares data for calculation of prf scores.
196
195
"""
197
- preds = {k : v ['entities ' ] for k , v in pred_dict .items ()}
198
- refs = {k : v ['entities ' ] for k , v in ref_dict .items ()}
196
+ preds = {k : v ['entity_answers ' ] for k , v in pred_dict .items ()}
197
+ refs = {k : v ['entity_answers ' ] for k , v in ref_dict .items ()}
199
198
return preds , refs
200
199
201
200
@@ -477,7 +476,7 @@ def format_metrics(metrics, task, err_msg):
477
476
if err_msg is not None :
478
477
return {'errorMsg' : str (err_msg ), 'errorCode' : 1 , 'data' : []}
479
478
data = []
480
- if task != 'all' :
479
+ if task != 'all' and task != 'main' :
481
480
sources = ["both" ]
482
481
483
482
if task == 'all' :
0 commit comments