-
Notifications
You must be signed in to change notification settings - Fork 35
add bfcl utility #174
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
lchen001
wants to merge
6
commits into
main
Choose a base branch
from
lingjiao/bfcl_util
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
add bfcl utility #174
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
682b1cc
add bfcl utility
lchen001 1f56767
update the doc strings and add some comments
lchen001 0469c8f
update setup for bfcl_eval
lchen001 03c5867
add bfcl_eval
lchen001 a65926e
incorporate feedback
lchen001 96c65d7
Merge branch 'main' into lingjiao/bfcl_util
lchen001 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
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,53 @@ | ||
| import re, json, ast | ||
| from dataclasses import dataclass | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from .transform import DFTransformBase | ||
|
|
||
| from bfcl_eval.eval_checker.multi_turn_eval.multi_turn_utils import ( | ||
lchen001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| execute_multi_turn_func_call | ||
| ) | ||
|
|
||
| @dataclass | ||
| class BFCLMultiturnExecuteCall(DFTransformBase): | ||
| model_output_column: str | ||
| model_answer_column: str | ||
|
|
||
| def transform(self, df: pd.DataFrame) -> pd.DataFrame: | ||
| df[self.model_answer_column] = df.apply(self.execuate_model_output,axis=1) | ||
| return df | ||
|
|
||
| @staticmethod | ||
| def execuate_model_output(response): | ||
| """ | ||
| Execute the model output to get the function output. | ||
|
|
||
| Parameters: | ||
| response (str): Input string containing answer X in the form of "Final Answer: X". | ||
lchen001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Returns: | ||
| numerical_value (float or str): A numeric value or JSON string representing the model's answer. | ||
| """ | ||
| test_entry = response | ||
| response_text = test_entry["model_output"] | ||
| initial_config: dict = eval(test_entry["initial_config"]) | ||
lchen001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| involved_classes: list = eval(test_entry["involved_classes"]) | ||
| test_entry_id: str = test_entry["id"] | ||
| test_category: str = test_entry_id.rsplit("_", 1)[0] | ||
|
|
||
| func_calls = re.findall(r'\w+\([^)]*\)', response_text) | ||
| if(len(func_calls)==0): | ||
| return "No call executed" | ||
|
|
||
| execution_results, involved_instances = execute_multi_turn_func_call( | ||
| func_call_list = func_calls, | ||
| initial_config = initial_config, | ||
| involved_classes = involved_classes, | ||
| model_name = "", | ||
| test_entry_id=test_entry_id, | ||
| long_context = ( | ||
| "long_context" in test_category or "composite" in test_category | ||
| ), | ||
| is_evaL_run=False, | ||
| ) | ||
| return " ".join(execution_results) | ||
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,51 @@ | ||
| from eureka_ml_insights.metrics.metrics_base import ClassicMetric | ||
|
|
||
| from bfcl_eval.eval_checker.multi_turn_eval.multi_turn_checker import ( | ||
| multi_turn_checker) | ||
|
|
||
| class BFCLMultiturnMatch(ClassicMetric): | ||
lchen001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """This metric class checks if two dictionary strings represent the same dictionary.""" | ||
|
|
||
| def __init__(self, model_output_col: str = "model_output", | ||
| ground_truth_col: str = "ground_truth", | ||
| initial_config_col:str = "initial_config", | ||
| involved_classes_col: str = "involved_classes", | ||
| test_entry_id_col: str = "id", | ||
| ): | ||
| super().__init__() | ||
| self.model_output_col = model_output_col | ||
| self.ground_truth_col = ground_truth_col | ||
| self.initial_config_col = initial_config_col | ||
| self.involved_classes_col = involved_classes_col | ||
| self.test_entry_id_col = test_entry_id_col | ||
|
|
||
| def __evaluate__(self, answer_text, target_text,initial_config,involved_classes,test_entry_id): | ||
| test_entry = {"initial_config":eval(initial_config), | ||
| "involved_classes":eval(involved_classes), | ||
| "id":test_entry_id, | ||
| } | ||
| test_entry = test_entry | ||
lchen001 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test_category = "" | ||
| model_name = "" | ||
| multi_turn_ground_truth_list = eval(target_text) | ||
lchen001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| accuracy_checker_result = multi_turn_checker( | ||
| answer_text, | ||
| multi_turn_ground_truth_list, | ||
| test_entry, | ||
| test_category, | ||
| model_name, | ||
| ) | ||
| return str(accuracy_checker_result['valid']) | ||
|
|
||
| def evaluate(self, data): | ||
| self.validate_data(data) | ||
| data[self.__class__.__name__ + "_result"] = data.apply( | ||
| lambda x: self.__evaluate__(x[self.model_output_col], | ||
| x[self.ground_truth_col], | ||
| x[self.initial_config_col], | ||
| x[self.involved_classes_col], | ||
| x[self.test_entry_id_col], | ||
| ), axis=1 | ||
| ) | ||
| return data | ||
Oops, something went wrong.
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.