Skip to content

change: Update BiasConfig to accept multiple facet params #2243

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 9 commits into from
Jul 15, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/sagemaker/clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,34 @@ def __init__(
Args:
label_values_or_threshold (Any): List of label values or threshold to indicate positive
outcome used for bias metrics.
facet_name (str): Sensitive attribute in the input data for which we like to compare
metrics.
facet_name (Any): String or List of strings of sensitive attribute(s) in the input data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the type of this parameter now str or [str], not Any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about this, but I changed to "Any" instead of "str or [str]" to be consistent with the way that this is defined for other parameters. For example on the line just above, label_values_or_threshold is of type Any when it could take a limited number of types.
I will be updating as suggested shortly

for which we like to compare metrics.
facet_values_or_threshold (list): Optional list of values to form a sensitive group or
threshold for a numeric facet column that defines the lower bound of a sensitive
group. Defaults to considering each possible value as sensitive group and
computing metrics vs all the other examples.
If facet_name is a list, this needs to be None or a List consisting of lists or None
with the same length as facet_name list.
group_name (str): Optional column name or index to indicate a group column to be used
for the bias metric 'Conditional Demographic Disparity in Labels - CDDL' or
'Conditional Demographic Disparity in Predicted Labels - CDDPL'.
"""
facet = {"name_or_index": facet_name}
_set(facet_values_or_threshold, "value_or_threshold", facet)
if isinstance(facet_name, str):
facet = {"name_or_index": facet_name}
_set(facet_values_or_threshold, "value_or_threshold", facet)
facet_list = [facet]
elif facet_values_or_threshold is None or len(facet_name) == len(facet_values_or_threshold):
facet_list = []
for i, single_facet_name in enumerate(facet_name):
facet = {"name_or_index": single_facet_name}
if facet_values_or_threshold is not None:
_set(facet_values_or_threshold[i], "value_or_threshold", facet)
facet_list.append(facet)
else:
raise ValueError("Wrong combination of argument values passed")
self.analysis_config = {
"label_values_or_threshold": label_values_or_threshold,
"facet": [facet],
"facet": facet_list,
}
_set(group_name, "group_variable", self.analysis_config)

Expand Down