Spaces:
Running
Running
FIX: fix conflicts
Browse files1234567891011---title: Tlememoji: 🏆colorFrom: yellowcolorTo: yellowsdk: staticpinned: falselicense: apache-2.0---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference12345# Transparent LLMs Evaluation Metrics> LLMs belong to *tout le monde*
13 unmodified lines141516171819202122232425262728293 unmodified lines3334353637383914 unmodified lines54555657585917 unmodified lines7778798081828344 unmodified lines128129130131132133368 unmodified lines50250350450550650750813 unmodified linesfrom collections import defaultdictimport sys# if sys.version_info >= (3, 9):# from functools import cache# else:# from functools import lru_cache as cachedisable_progress_bar()def fake_pipeline(prompts: Iterable[str]) -> list[str]:return [prompt for prompt in tqdm(prompts)]@dataclass3 unmodified lines# 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] = Nonefew_shot: int = 0few_shot_from: Optional[str] = None14 unmodified linesinput_column=example[self.input_column])}@cached_propertydef samples(self):17 unmodified linesif name in ds:self.few_shot_from = namebreak# if self.few_shot_from:shots = ds[self.few_shot_from].select(range(self.few_shot))# else:# shots = ds.select(range(self.few_shot))44 unmodified linesresult = self.metric.compute(responses=outputs, references=self.dataset[self.label_column])# if log:# name = name or pipeline.__name__# self.results[name] = result368 unmodified lines"psychology",],"other": ["other", "business", "health"],"Test": ["culture"],}@classmethod13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354553 unmodified lines5960616263646514 unmodified lines8081828384858617 unmodified lines10410510610710810911011144 unmodified lines156157158159160161162163368 unmodified lines53253353453553653713 unmodified linesfrom collections import defaultdictimport sys# if sys.version_info >= (3, 9):# from functools import cache# else:# from functools import lru_cache as cachedisable_progress_bar()def mt_bench_prompt(example):judge_prompt = "You are ChatGPT, a large language model trained by OpenAI. Please act as an impartial judge and evaluate the quality of the response provided by an AI assistant to the user question displayed below. The Your evaluation should consider factors such as the helpfulness, relevance, accuracy, depth, creativity, and level of detail of the response."judge_prompt = "You are ChatGPT, a large language model trained by OpenAI. Your task is to act as an impartial judge and evaluate the quality of the responses provided by an 'assistant' role in the displayed conversation. Your evaluation should focus on the helpfulness, relevance, accuracy, depth, creativity, language fluency, clarity, and level of detail in the assistant's responses. Please note that the evaluation should not consider the user's questions or the overall conversation, but solely the quality of the assistant's replies."multi_prompt = "You evaluation should focus on the assistant's answer to the second user question."ref_prompt = "In the conversation, you will encounter system messages labeled 'Reference Answer' followed by the assistant's response. Your task is to evaluate the quality of the assistant's response by comparing it with the reference answer."json_prompt = 'You must rate the response on a scale of 1 to 10 in JSON format, for example: {"rating": 5}.'prompt_list = [judge_prompt]conversations = example["conversation"]if example["turn"] == 2:prompt_list.append(multi_prompt)if example["reference"] is not None:conversations = []quesiotns = filter(lambda e: e["role"] == "user", example["conversation"])answers = filter(lambda e: e["role"] == "assistant", example["conversation"])for q, a, r in zip(quesiotns, answers, example["reference"]):conversations.append(q)conversations.append({"role": "system", "content": "Reference Answer: " + r})conversations.append(a)prompt_list.append(ref_prompt)prompt_list.append(json_prompt)messages = [{"role": "system", "content": " ".join(prompt_list)}] + conversationsreturn messages@dataclass3 unmodified lines# metrics: list[str] = field(default_factory=list)metric_name: str | tuple[str, str] = ("sustech/tlem", "gsm8k")input_column: str = "question"label_column: str = ""prompt: Optional[Callable | str] = Nonefew_shot: int = 0few_shot_from: Optional[str] = None14 unmodified linesinput_column=example[self.input_column])}self.label_column = self.label_column or self.input_column@cached_propertydef samples(self):17 unmodified linesif name in ds:self.few_shot_from = namebreakassert self.few_shot_from != self.splitshots = ds[self.few_shot_from].select(range(self.few_shot))# else:# shots = ds.select(range(self.few_shot))44 unmodified linesresult = self.metric.compute(responses=outputs, references=self.dataset[self.label_column])finally:result = outputs# if log:# name = name or pipeline.__name__# self.results[name] = result368 unmodified lines"psychology",],"other": ["other", "business", "health"],}@classmethod
69 unmodified lines70717273747576777879808182838431 unmodified lines1161171181191201211226 unmodified lines12913013113213313469 unmodified linesreturn resultsgsm8k = Task(dataset_name=("gsm8k", "main"),metric_name=("sustech/tlem", "gsm8k"),input_column="question",label_column="answer",)class Suite(EvaluationSuite):def run(self,model_or_pipeline: Any,31 unmodified linescase _ if name.startswith("cmmlu"):suite = CMMLU.suite(chat=chat)case "gsm8k":suite = [gsm8k]case "bbh":suite = BBH.suite()case "arc":6 unmodified linessuite = Winogrande.suite()case _ if name.startswith("ceval"):suite = CEVAL.suite(chat=chat)match name:case _ if "test" in name:suite = suite["Test"]69 unmodified lines70717273747576777831 unmodified lines1101111121131141151161171181191201216 unmodified lines12812913013113213313413513613713813914069 unmodified linesreturn resultsclass Suite(EvaluationSuite):task_class = Taskdef run(self,model_or_pipeline: Any,31 unmodified linescase _ if name.startswith("cmmlu"):suite = CMMLU.suite(chat=chat)case "gsm8k":suite = Task(dataset_name=("gsm8k", "main"),metric_name=("sustech/tlem", "gsm8k"),input_column="question",label_column="answer",)case "bbh":suite = BBH.suite()case "arc":6 unmodified linessuite = Winogrande.suite()case _ if name.startswith("ceval"):suite = CEVAL.suite(chat=chat)case "mt_bench":suite = Task(dataset_name="SUSTech/mt_bench_judge",split="train",prompt=mt_bench_prompt# metric_name=("sustech/tlem", "gsm8k"),)match name:case _ if "test" in name:suite = suite["Test"]
README.md+4-10
tasks.py+34-5
tlem.py+15-9