-
Notifications
You must be signed in to change notification settings - Fork 11
feat: added optional multiple metrics #108
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e6ffe61
feat: added optional multiple metrics
Darinochka 3556b99
fix: change metric to decision_metric
Darinochka 31147a9
fix: fixed type
Darinochka dcee174
fix: typing
Darinochka 0bcef43
refactor: decision metric to target metric
Darinochka 0201399
fix: target metric
Darinochka c2b778e
fix: fixed tests
Darinochka f62bba9
fix: test_logreg
Darinochka ebfdd3e
fix: fixed unit test
Darinochka f22efbf
fix: fixed test
Darinochka 06e6cd1
feat: update guides
Darinochka e4e7bab
feat: update guides
Darinochka 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
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 |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| # TODO: make up a better and more versatile config | ||
| - node_type: embedding | ||
| metric: retrieval_hit_rate_intersecting | ||
| target_metric: retrieval_hit_rate_intersecting | ||
| search_space: | ||
| - module_name: retrieval | ||
| k: [10] | ||
| embedder_name: | ||
| - deepvk/USER-bge-m3 | ||
| - node_type: scoring | ||
| metric: scoring_roc_auc | ||
| target_metric: scoring_roc_auc | ||
| search_space: | ||
| - module_name: knn | ||
| k: [3] | ||
| weights: ["uniform", "distance", "closest"] | ||
| - module_name: linear | ||
| - node_type: decision | ||
| metric: decision_accuracy | ||
| target_metric: decision_accuracy | ||
| search_space: | ||
| - module_name: threshold | ||
| thresh: [0.5] | ||
| - module_name: adaptive | ||
| - module_name: adaptive |
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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -19,7 +19,13 @@ | |
| class NodeOptimizer: | ||
| """Node optimizer class.""" | ||
|
|
||
| def __init__(self, node_type: NodeType, search_space: list[dict[str, Any]], metric: str) -> None: | ||
| def __init__( | ||
| self, | ||
| node_type: NodeType, | ||
| search_space: list[dict[str, Any]], | ||
| target_metric: str, | ||
| metrics: list[str] | None = None, | ||
| ) -> None: | ||
| """ | ||
| Initialize the node optimizer. | ||
|
|
||
|
|
@@ -29,7 +35,12 @@ def __init__(self, node_type: NodeType, search_space: list[dict[str, Any]], metr | |
| """ | ||
| self.node_type = node_type | ||
| self.node_info = NODES_INFO[node_type] | ||
| self.metric_name = metric | ||
| self.decision_metric_name = target_metric | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему у нас тут остался все равно decision_metric_name? |
||
|
|
||
| self.metrics = metrics if metrics is not None else [] | ||
| if self.decision_metric_name not in self.metrics: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А если он не в наших метриках то что происходит? |
||
| self.metrics.append(self.decision_metric_name) | ||
|
|
||
| self.modules_search_spaces = search_space # TODO search space validation | ||
| self._logger = logging.getLogger(__name__) # TODO solve duplicate logging messages problem | ||
|
|
||
|
|
@@ -61,14 +72,10 @@ def fit(self, context: Context) -> None: | |
| self.module_fit(module, context) | ||
|
|
||
| self._logger.debug("scoring %s module...", module_name) | ||
| metrics = module.score(context, "validation") | ||
| metric_value = metrics[self.metric_name] | ||
|
|
||
| # some metrics can produce error. When main metric produces error raise it. | ||
| if isinstance(metric_value, str): | ||
| raise Exception(metric_value) # noqa: TRY004, TRY002 | ||
| metrics_score = module.score(context, "validation", self.metrics) | ||
| metric_value = metrics_score[self.decision_metric_name] | ||
|
|
||
| context.callback_handler.log_metrics(metrics) | ||
| context.callback_handler.log_metrics(metrics_score) | ||
| context.callback_handler.end_module() | ||
|
|
||
| dump_dir = context.get_dump_dir() | ||
|
|
@@ -84,7 +91,7 @@ def fit(self, context: Context) -> None: | |
| module_name, | ||
| module_kwargs, | ||
| metric_value, | ||
| self.metric_name, | ||
| self.decision_metric_name, | ||
| module.get_assets(), # retriever name / scores / predictions | ||
| module_dump_dir, | ||
| module=module if not context.is_ram_to_clear() else None, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| - node_type: embedding | ||
| metric: retrieval_hit_rate | ||
| target_metric: retrieval_hit_rate | ||
| search_space: | ||
| - module_name: retrieval | ||
| k: [10] | ||
| embedder_name: | ||
| - sentence-transformers/all-MiniLM-L6-v2 | ||
| - node_type: scoring | ||
| metric: scoring_roc_auc | ||
| target_metric: scoring_roc_auc | ||
| search_space: | ||
| - module_name: description | ||
| temperature: [1.0, 0.5, 0.1, 0.05] | ||
| - node_type: decision | ||
| metric: decision_accuracy | ||
| target_metric: decision_accuracy | ||
| search_space: | ||
| - module_name: argmax |
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Докстринги нигде не обновлены