-
Notifications
You must be signed in to change notification settings - Fork 408
[EVAL] MultiChallenge #1075
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
Open
akshathmangudi
wants to merge
9
commits into
huggingface:main
Choose a base branch
from
akshathmangudi:akshath/issue-1019-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[EVAL] MultiChallenge #1075
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ffdf0c
initial commit
akshathmangudi d4cda44
multi challenge impl, ready for review
akshathmangudi f1d82ef
docstring fixes
akshathmangudi c8ff7d3
Merge branch 'main' into akshath/issue-1019-v2
akshathmangudi 4c572e5
addressed comments
akshathmangudi 4c87372
Merge branch 'main' into akshath/issue-1019-v2
akshathmangudi 23acb0c
Merge branch 'main' into akshath/issue-1019-v2
akshathmangudi d6aa381
addressed comments
akshathmangudi 5f70e1a
Merge branch 'main' into akshath/issue-1019-v2
akshathmangudi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| """ | ||
| name: | ||
| MultiChallenge | ||
|
|
||
| dataset: | ||
| nmayorga7/multichallenge | ||
|
|
||
| abstract: | ||
| MultiChallenge evaluates large language models (LLMs) on their ability to | ||
| conduct multi-turn conversations with human users. | ||
| The model is given a target question belonging to one or | ||
| more axes (categories) and must provide a free-form answer. | ||
| The evaluation uses a secondary judge model to determine if the | ||
| answer satisfies the pass criteria for that question. | ||
|
|
||
| languages: | ||
| english | ||
|
|
||
| tags: | ||
| conversational, generation | ||
|
|
||
| paper: | ||
| https://arxiv.org/abs/2501.17399 | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| import re | ||
|
|
||
| from inspect_ai.dataset import Sample | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from inspect_ai.model import get_model | ||
| from inspect_ai.scorer import Score, Target, accuracy, scorer, stderr | ||
| from inspect_ai.solver import TaskState, generate | ||
|
|
||
| from lighteval.tasks.lighteval_task import LightevalTaskConfig | ||
| from lighteval.tasks.requests import Doc | ||
|
|
||
|
|
||
| JUDGE_PROMPT = """You are tasked with evaluating a model response to see if it meets a specific criteria. | ||
| The criteria will always be YES/NO evaluation. | ||
|
|
||
| The model response is as follows: | ||
| <MODEL_RESPONSE> | ||
| {} | ||
| </MODEL_RESPONSE> | ||
|
|
||
| The criteria that the model response must meet is as follows. Be VERY STRICT!: | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <CRITERIA> | ||
| {} | ||
| </CRITERIA> | ||
|
|
||
| Print your reasoning followed by your verdict, either "YES" or "NO".""" | ||
|
|
||
|
|
||
| def format_conversation(conversation: list[dict]) -> str: | ||
| """Format conversation messages into a single string for model input.""" | ||
| formatted_messages = [] | ||
| for msg in conversation: | ||
akshathmangudi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| role = msg["role"].upper() | ||
| content = msg["content"] | ||
| formatted_messages.append(f"{role}:\n{content}") | ||
|
|
||
| return "\n\n".join(formatted_messages) | ||
akshathmangudi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def multi_challenge_prompt(line, task_name: str = None): | ||
| """Convert dataset to Doc object""" | ||
|
|
||
| conversation = line["CONVERSATION"] | ||
| formatted_conv = format_conversation(conversation) | ||
| return Doc( | ||
| task_name=task_name, | ||
| query=formatted_conv, | ||
| instruction=None, | ||
| specific={ | ||
| "question_id": line["QUESTION_ID"], | ||
| "axis": line["AXIS"], | ||
| "target_question": line["TARGET_QUESTION"], | ||
| "pass_criteria": line["PASS_CRITERIA"], | ||
| "conversation": conversation, | ||
| }, | ||
| ) | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @scorer(metrics=[accuracy(), stderr()]) | ||
| def multi_challenge_scorer(): | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async def score(state: TaskState, target: Target): | ||
| response = state.output.completion | ||
|
|
||
| target_question = target.text | ||
| pass_criteria = state.metadata.get("pass_criteria", "YES") | ||
|
|
||
| if not target_question: | ||
| return Score( | ||
| value="I", | ||
| answer=response, | ||
| explanation="Target question not found.", | ||
| ) | ||
|
|
||
| try: | ||
| judge_model = get_model("openai/gpt-4o-2024-08-06") | ||
| judge_prompt = JUDGE_PROMPT.format(response, target_question) | ||
|
|
||
| judge_result = await judge_model.generate(judge_prompt) | ||
| judge_output = judge_result.completion | ||
|
|
||
| verdict_match = re.search(r"\b(YES|NO)\b", judge_output, re.IGNORECASE) | ||
|
|
||
| if not verdict_match: | ||
| return Score( | ||
| value="I", | ||
| answer=response, | ||
| explanation=f"Could not extract verdict from judge output: {judge_output}.", | ||
| ) | ||
|
|
||
| judge_verdict = verdict_match.group(1).upper() | ||
| passed = judge_verdict == pass_criteria | ||
|
|
||
| return Score( | ||
| value="C" if passed else "I", | ||
| answer=response, | ||
| explanation=f"Judge verdict: {judge_verdict}, Expected: {pass_criteria}, Response: {response}.", | ||
| ) | ||
|
|
||
| except Exception as e: | ||
| return Score( | ||
| value="I", | ||
| answer=response, | ||
| explanation=f"Error during judge evaluation: {str(e)}.", | ||
| ) | ||
|
|
||
| return score | ||
|
|
||
|
|
||
| def record_to_sample(record: dict) -> Sample: | ||
| """Convert dataset record to inspect-ai Sample object.""" | ||
| conversation = record["CONVERSATION"] | ||
| formatted_conv = format_conversation(conversation) | ||
akshathmangudi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return Sample( | ||
| input=formatted_conv, | ||
| target=record["TARGET_QUESTION"], | ||
| metadata={ | ||
| "question_id": record["QUESTION_ID"], | ||
akshathmangudi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "axis": record["AXIS"], | ||
| "pass_criteria": record["PASS_CRITERIA"], | ||
| "conversation": conversation, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| multi_challenge = LightevalTaskConfig( | ||
| name="multi_challenge", | ||
| prompt_function=multi_challenge_prompt, | ||
| hf_repo="nmayorga7/multichallenge", | ||
| hf_subset="default", | ||
| hf_avail_splits=["train"], | ||
| evaluation_splits=["train"], | ||
| few_shots_split=None, | ||
| few_shots_select=None, | ||
| generation_size=2048, | ||
| stop_sequence=[], | ||
| version=0, | ||
| sample_fields=record_to_sample, | ||
| metrics=[], # Metrics are defined in the scorer decorator for inspect-ai tasks | ||
| solver=[generate(cache=True)], | ||
| scorer=multi_challenge_scorer(), | ||
| ) | ||
|
|
||
| TASKS_TABLE = [multi_challenge] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.