Skip to content

Commit

Permalink
[Update] Dingo Dataset update (#1670)
Browse files Browse the repository at this point in the history
* [Update] Dingo Dataset update

* update
  • Loading branch information
MaiziXiao authored Nov 8, 2024
1 parent 835bf75 commit a0ef2fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 19 additions & 14 deletions opencompass/datasets/dingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from opencompass.openicl.icl_evaluator import BaseEvaluator
from opencompass.registry import ICL_EVALUATORS, LOAD_DATASET
from opencompass.utils import get_data_path

from .base import BaseDataset

Expand All @@ -19,6 +20,7 @@ class DingoDataset(BaseDataset):

@staticmethod
def load(path: str):
path = get_data_path(path, local_mode=True)
raw_data = []
with open(path, encoding='utf-8') as f:
reader = csv.reader(f, delimiter=';')
Expand All @@ -34,6 +36,7 @@ class DingoLongDataset(BaseDataset):

@staticmethod
def load(path: str):
path = get_data_path(path, local_mode=True)
raw_data = []
with open(path, 'r', encoding='utf-8') as f:
for line in f:
Expand All @@ -46,7 +49,6 @@ class DingoEvaluator(BaseEvaluator):

def score(self, origin_prompt: List, predictions: List) -> dict:
try:
# from dingo.model.model import Model
from dingo.exec import Executor
from dingo.io import InputArgs
except Exception:
Expand All @@ -58,27 +60,30 @@ def score(self, origin_prompt: List, predictions: List) -> dict:
current_time = time.strftime('%Y%m%d_%H%M%S', time.localtime())
file_data = [{'prompt': pmt, 'prediction': prd}
for pmt, prd in zip(origin_prompt, predictions)]
file_name = 'dingo_file_' + current_time + '.jsonl'
os.makedirs('tmp', exist_ok=True)
file_name = os.path.join('tmp', 'dingo_file_' + current_time + '.jsonl') # noqa: E501

with open(file_name, 'a', encoding='utf-8') as f:
for d in file_data:
json.dump(d, f, ensure_ascii=False)
f.write('\n')

input_data = {
'eval_models': ['llm_base'],
'eval_model': 'llm_base',
'input_path': file_name,
'output_path': './outputs/dingo/',
'save_data': True,
'dataset': 'local',
'datasource': 'local',
'data_format': 'jsonl',
'column_prompt': ['prompt'],
'column_content': ['prediction'],
'column_prompt': 'prompt',
'column_content': 'prediction',
}
# Model.apply_config(input_data["custom_config_path"])
input_args = InputArgs(**input_data)
executor = Executor.exec_map['local'](input_args)
result = executor.execute()
summary = result[0].to_dict()

os.remove(file_name)
try:
input_args = InputArgs(**input_data)
executor = Executor.exec_map['local'](input_args)
result = executor.execute()
summary = result[0].to_dict()
except Exception:
raise
finally:
os.remove(file_name)
return summary
3 changes: 2 additions & 1 deletion requirements/extra.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Alpaca-eval
alpaca-eval==0.6
cn2an
dingo-python
# Dingo
dingo-python==1.1.2
# Icl topk retriever
faiss_gpu==1.7.2
# Humaneval, Humaneval X
Expand Down

0 comments on commit a0ef2fd

Please sign in to comment.