Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add Codereval inference #658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions configs/datasets/CoderEval/CoderEval_gen_a33a69.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.openicl.icl_evaluator import AccEvaluator
from opencompass.datasets import CoderEvalDataset
from opencompass.utils.text_postprocessors import first_capital_postprocess


CoderEval_reader_cfg = dict(
input_columns="input",
output_column=None,
)

CoderEval_infer_cfg = dict(
prompt_template=dict(
type=PromptTemplate,
template=dict(
round=[
dict(role="HUMAN", prompt="Please help me complete the following function.\n**Note: only return the function to me, no other description.**\n```python\n{input}\n```"),
dict(role="BOT", prompt="{answer}"),
]
),
),
retriever=dict(type=ZeroRetriever),
inferencer=dict(type=GenInferencer),
)

CoderEval_eval_cfg = dict(evaluator=dict(type=AccEvaluator),
pred_role="BOT",
pred_postprocessor=dict(type=first_capital_postprocess))

files = ['CEPythonHumanLabel', 'CEPythonRaw']
CoderEval_datasets = []

for _file in files:
CoderEval_datasets.append(
dict(
type=CoderEvalDataset,
abbr=_file,
test_path=f"data/CoderEval/{_file}.jsonl",
reader_cfg=CoderEval_reader_cfg,
infer_cfg=CoderEval_infer_cfg,
eval_cfg=CoderEval_eval_cfg,
)
)

del _file
1 change: 1 addition & 0 deletions opencompass/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .cmmlu import * # noqa: F401, F403
from .cmnli import * # noqa: F401, F403
from .cmrc import * # noqa: F401, F403
from .codereval import * # noqa: F401, F403
from .commonsenseqa import * # noqa: F401, F403
from .commonsenseqa_cn import * # noqa: F401, F403
from .copa import * # noqa: F401, F403
Expand Down
20 changes: 20 additions & 0 deletions opencompass/datasets/codereval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json

from datasets import Dataset

from opencompass.registry import LOAD_DATASET

from .base import BaseDataset


@LOAD_DATASET.register_module()
class CoderEvalDataset(BaseDataset):

@staticmethod
def load(test_path):
datasets = []
with open(test_path, 'r', encoding='utf-8') as file:
for line in file:
dataset = json.loads(line.strip())
datasets.append(dataset)
return Dataset.from_list(datasets)