@@ -47,17 +47,29 @@ def bbh_mcq_postprocess(text: str) -> str:
4747@TEXT_POSTPROCESSORS .register_module ('bbh-freeform' )
4848def bbh_freeform_postprocess (text : str ) -> str :
4949 ans = text
50- ans_line = ans .split ('answer is ' )
50+ ans_line = re .split (r 'answer is\s*:?\s*' , ans , flags = re . IGNORECASE )
5151 if len (ans_line ) != 1 :
52- ans = ans_line [1 ].strip ()
52+ ans = ans_line [- 1 ].strip ()
5353 ans = ans .split ('\n ' )[0 ].strip ()
5454
5555 if ans .endswith ('.' ):
5656 ans = ans [:- 1 ].strip ()
5757
5858 match = re .search (r'\*\*(.*?)\*\*' , ans )
5959 if match :
60- return match .group (1 )
60+ ans = match .group (1 ).strip ()
61+
62+ match = re .match (r'^(yes|no)\b' , ans , flags = re .IGNORECASE )
63+ if match :
64+ return match .group (1 ).capitalize ()
65+
66+ match = re .match (r'^(true|false)\b' , ans , flags = re .IGNORECASE )
67+ if match :
68+ return match .group (1 ).capitalize ()
69+
70+ if not re .search (r'\d\s*,\s*\d' , ans ):
71+ ans = re .sub (r'\s*,\s*' , ' ' , ans )
72+ ans = re .sub (r'\s+' , ' ' , ans ).strip ()
6173
6274 return ans
6375
@@ -73,12 +85,13 @@ def score(self, predictions, references):
7385 }
7486
7587 predictions = [bbh_freeform_postprocess (pred ) for pred in predictions ]
88+ references = [bbh_freeform_postprocess (ref ) for ref in references ]
7689
7790 details = []
7891 cnt = 0
7992 for pred , ref in zip (predictions , references ):
8093 detail = {'pred' : pred , 'answer' : ref , 'correct' : False }
81- if pred == ref :
94+ if pred . casefold () == ref . casefold () :
8295 cnt += 1
8396 detail ['correct' ] = True
8497 details .append (detail )
0 commit comments