[Feat] support zhipu post process (#642)

* [Feat] support zhipu post

* [Feat] support zhipu post

* [Feat] support zhipu post
This commit is contained in:
Hubert 2023-11-27 19:57:36 +08:00 committed by GitHub
parent 6d0d78986c
commit d4af31bab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -13,6 +13,17 @@ datasets = [
*ceval_datasets,
]
# needs a special postprocessor for all
# except 'gsm8k' and 'strategyqa'
from opencompass.utils import general_eval_wrapper_postprocess
for _dataset in datasets:
if _dataset['abbr'] not in ['gsm8k', 'strategyqa']:
if hasattr(_dataset['eval_cfg'], 'pred_postprocessor'):
_dataset['eval_cfg']['pred_postprocessor']['postprocess'] = _dataset['eval_cfg']['pred_postprocessor']['type']
_dataset['eval_cfg']['pred_postprocessor']['type'] = general_eval_wrapper_postprocess
else:
_dataset['eval_cfg']['pred_postprocessor'] = {'type': general_eval_wrapper_postprocess}
models = [
dict(
abbr='chatglm_pro',

View File

@ -1,4 +1,5 @@
import re
from typing import Callable, Optional, Union
from opencompass.registry import TEXT_POSTPROCESSORS
@ -141,3 +142,29 @@ def first_number_postprocess(text: str) -> float:
def multiple_select_postprocess(text: str) -> str:
ret = set([t for t in text if t.isupper()])
return ''.join(sorted(ret))
def general_eval_wrapper_postprocess(text: str,
postprocess: Optional[Union[
str, Callable]] = None,
**kwargs) -> str:
"""Wrapper for eval text repr. Especially for chatglmpro.
Args:
text(str): Text to be postprocessed.
postprocess(Callable, optional): Original post processing function.
Defaults to None.
**kwargs: Other necessary kwargs for post processing function.
"""
try:
text = eval(text)
except Exception:
# in case empty input or other error, skip eval
pass
if postprocess:
if isinstance(postprocess, str):
postprocess = TEXT_POSTPROCESSORS.get(postprocess)
return postprocess(text, **kwargs)
else:
return text