Spaces:
Running
Running
add suite
Browse files5 unmodified lines6789101121 unmodified lines33343536373839404142434445462 unmodified lines4950515253545516 unmodified lines727374757677787980143 unmodified lines2242252262272282292305 unmodified linesimport loggingfrom typing import Any, Optional, Protocol, Iterable, Callable# %%21 unmodified linesfrom evaluate import load@dataclassclass Task:dataset_name: str = "gsm8k"dataset_params: dict = field(default_factory=dict)# metrics: list[str] = field(default_factory=list)metric_name: str | tuple[str, str] = "gsm8k"input_column: str = "question"label_column: str = "reference"prompt: Optional[Callable | str] = None@cached_property2 unmodified lines@cached_propertydef dataset(self):ds = load_dataset(self.dataset_name, **self.dataset_params)if self.prompt is not None:ds = ds.map(lambda example: {16 unmodified lines)return metricdef run(self, pipeline: TextGenerationPipeline):outputs = pipeline(self.samples)return self.metric.compute(outputs, self.dataset[self.label_column])class Metrics:143 unmodified linesreturn results# %%load("sustech/tlem", "gsm8k")5 unmodified lines67891011121321 unmodified lines3536373839404142434445464748495051522 unmodified lines55565758596061626364656616 unmodified lines8384858687888990919293143 unmodified lines2372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762775 unmodified linesimport loggingfrom typing import Any, Optional, Protocol, Iterable, Callablefrom tqdm.auto import tqdmfrom evaluate.evaluation_suite import EvaluationSuite# %%21 unmodified linesfrom evaluate import loaddef fake_pipeline(prompts: Iterable[str]) -> list[str]:return [prompt for prompt in tqdm(prompts)]@dataclassclass Task:dataset_name: str | tuple[str, str] = ("gsm8k", "main")split: str = "test"# metrics: list[str] = field(default_factory=list)metric_name: str | tuple[str, str] = ("sustech/tlem", "gsm8k")input_column: str = "question"label_column: str = "answer"prompt: Optional[Callable | str] = None@cached_property2 unmodified lines@cached_propertydef dataset(self):ds = load_dataset(*self.dataset_nameif isinstance(self.dataset_name, tuple)else self.dataset_name,split=self.split)if self.prompt is not None:ds = ds.map(lambda example: {16 unmodified lines)return metricdef run(self, pipeline: TextGenerationPipeline = fake_pipeline):outputs = pipeline(self.samples)return self.metric.compute(responses=outputs, references=self.dataset[self.label_column])class Metrics:143 unmodified linesreturn resultsclass Suite(EvaluationSuite):def run(self, model_or_pipeline: Any, prompt: str = "{instruction}") -> dict[str, float]:self.assert_suite_nonempty()results_all = {}for task in tqdm(self.suite, desc="Running tasks"):task_name = task.nameresults = task.run(model_or_pipeline)results_all[task_name] = resultsreturn results_alldef __init__(self, name):super().__init__(name)self.suite = [Task(dataset_name=("gsm8k", "main"),metric_name=("sustech/tlem", "gsm8k"),input_column="question",label_column="answer",)# TASK_REGISTRY["gsm8k"],# TASK_REGISTRY["competition_math"],]# %%if __name__ == "__main__":# metric = load("sustech/tlem", "gsm8k")# output = metric.compute(responses=["answer is 2", "1+2"], references=["2", "3"])# logging.info(output)suite = EvaluationSuite.load("sustech/tlem")suite.run(fake_pipeline)# %%
tlem.py+56-9