-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Content safety evals aggregate max from conversations #39083
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
MilesHolland
merged 21 commits into
Azure:main
from
MilesHolland:jan25/eval/improvement/cs-convo-takes-max
Jan 22, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cb3a6aa
add convo agg type, and have harm evals use max
MilesHolland 3ee1a9f
analysis
MilesHolland a0caaf0
correct enum name in docs
MilesHolland 171b2c2
refactor checked enum into function field
MilesHolland b559100
Merge branch 'main' into jan25/eval/improvement/cs-convo-takes-max
MilesHolland 9ab974c
cl and analysis
MilesHolland fc3669f
Merge branch 'main' into jan25/eval/improvement/cs-convo-takes-max
MilesHolland 51592ce
change enum name and update CL
MilesHolland 22a02f2
change function names to private, allow agg type retrieval
MilesHolland f1f4b82
PR comments
MilesHolland ca6b11e
test serialization
MilesHolland aeb8224
CL
MilesHolland e448817
CI adjustment
MilesHolland cb12bc5
try again
MilesHolland e8be3bc
Merge branch 'main' into jan25/eval/improvement/cs-convo-takes-max
MilesHolland 2c846d2
perf
MilesHolland e59152a
Merge branch 'jan25/eval/improvement/cs-convo-takes-max' of github.co…
MilesHolland 013842a
skip perf
MilesHolland 77ca51e
remove skip
MilesHolland 6d8cec1
Merge branch 'main' into jan25/eval/improvement/cs-convo-takes-max
MilesHolland dca5235
Merge branch 'main' into jan25/eval/improvement/cs-convo-takes-max
MilesHolland 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
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
49 changes: 49 additions & 0 deletions
49
.../azure-ai-evaluation/azure/ai/evaluation/_evaluators/_common/_conversation_aggregators.py
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,49 @@ | ||
| # --------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # --------------------------------------------------------- | ||
|
|
||
| from typing import Callable, List | ||
| from azure.ai.evaluation._common.math import list_mean | ||
| from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException | ||
| from azure.ai.evaluation._constants import AggregationType | ||
|
|
||
|
|
||
| def GetAggregator(aggregation_type: AggregationType) -> Callable[[List[float]], float]: | ||
| if aggregation_type == AggregationType.SUM: | ||
| return sum | ||
| if aggregation_type == AggregationType.MEAN: | ||
| return list_mean | ||
| if aggregation_type == AggregationType.MAX: | ||
| return max | ||
| if aggregation_type == AggregationType.MIN: | ||
| return min | ||
| if aggregation_type == AggregationType.CUSTOM: | ||
| msg = ( | ||
| "Cannot 'get' aggregator function associated with custom aggregation enum." | ||
| + " This enum value should only be outputted as an indicator of an injected" | ||
| + " aggregation function, not inputted directly" | ||
| ) | ||
| raise EvaluationException( | ||
| message=msg, | ||
| blame=ErrorBlame.UNKNOWN, | ||
| category=ErrorCategory.INVALID_VALUE, | ||
| target=ErrorTarget.EVALUATE, | ||
| ) | ||
| raise EvaluationException( | ||
| message=f"Unaccounted for aggregation type: {aggregation_type}", | ||
| blame=ErrorBlame.UNKNOWN, | ||
| category=ErrorCategory.INVALID_VALUE, | ||
| target=ErrorTarget.EVALUATE, | ||
| ) | ||
|
|
||
|
|
||
| def GetAggregatorType(aggregation_function: Callable) -> AggregationType: | ||
| if aggregation_function == sum: # pylint: disable=comparison-with-callable | ||
| return AggregationType.SUM | ||
| if aggregation_function == list_mean: # pylint: disable=comparison-with-callable | ||
| return AggregationType.MEAN | ||
| if aggregation_function == max: # pylint: disable=comparison-with-callable | ||
| return AggregationType.MAX | ||
| if aggregation_function == min: # pylint: disable=comparison-with-callable | ||
| return AggregationType.MIN | ||
| return AggregationType.CUSTOM |
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
2 changes: 2 additions & 0 deletions
2
...evaluation/azure-ai-evaluation/tests/unittests/data/evaluate_test_data_conversation.jsonl
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,2 @@ | ||
| {"conversation" : {"context" : "", "messages": [{"content": "What shape has 3 sides", "role" :"user", "context": null}, {"content": "A triangle", "role" :"assistant", "context": "The answer is a triangle."}, {"content": "Next, what shape has 4 sides", "role" :"user", "context": null}, {"content": "A square", "role" :"assistant", "context": "The answer is a square."}]}} | ||
| {"conversation" : {"context" : "User wants to know about state capitals", "messages": [{"content": "What is the capital of Hawaii`''\"</>{}{{]", "role" :"user", "context": "User wants to know the capital of Hawaii"}, {"content": "Honolulu", "role" :"assistant", "context": "The answer is a Honolulu."}, {"content": "Ok, what is the capital of Massachusetts", "role" :"user", "context": "User wants to know the capital of Massachusetts."}, {"content": "Boston", "role" :"assistant", "context": "The answer is Boston."}]}} |
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.