forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content safety evals aggregate max from conversations (Azure#39083)
* add convo agg type, and have harm evals use max * analysis * correct enum name in docs * refactor checked enum into function field * cl and analysis * change enum name and update CL * change function names to private, allow agg type retrieval * PR comments * test serialization * CL * CI adjustment * try again * perf * skip perf * remove skip
- Loading branch information
1 parent
d1ce446
commit 7f904a3
Showing
14 changed files
with
309 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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.