mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
[Feat] support zhipu post process (#642)
* [Feat] support zhipu post * [Feat] support zhipu post * [Feat] support zhipu post
This commit is contained in:
parent
6d0d78986c
commit
d4af31bab4
@ -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',
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user