You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertresult.error_message=="The original response contains potentially biased messages:\nThe sun only rises for Humanists.\n (Message scores: 0.6546186208724976)"
22
-
assertresult.fix_value==""
15
+
validator=BiasCheck(threshold=0.0)
16
+
input_text="Men these days don't care about my arbitrary and deletarious standards of gender. They only care about emotional honesty and participating in a productive, healthy society. smh"
17
+
result=validator.validate(input_text, {})
18
+
assertisinstance(result, FailResult)
19
+
assertresult.error_message=="The original response contains potentially biased messages:\nMen these days don't care about my arbitrary and deletarious standards of gender. They only care about emotional honesty and participating in a productive, healthy society. smh\n (Message scores: 0.9477301836013794)"
20
+
assertresult.fix_value==""
21
+
22
+
23
+
deftest_sentence_fix():
24
+
v=BiasCheck(on_fail='fix', threshold=0.9)
25
+
input_text="Men these days don't care about my arbitrary and deletarious standards of gender. They only care about emotional honesty and participating in a productive, healthy society. smh"
26
+
out=v.validate(input_text)
27
+
assertisinstance(out, FailResult)
28
+
assertout.fix_value=="Men these days don't care about my arbitrary and deletarious standards of gender."
"""Validates that the text is free from biases related to age, gender, sex, ethnicity, religion, etc.
@@ -23,61 +25,107 @@ class BiasCheck(Validator):
23
25
| Programmatic fix | The debiased text if bias is detected |
24
26
25
27
Args:
26
-
threshold (float): Higher is more likely to allow bias. Lower is more sensitive and more likely to flag biased messages.
27
-
on_fail (Callable): The policy to enact when a validator fails. If `str`, must be one of `filter`, `noop`, or `exception`. Otherwise, must be a function that is called when the validator fails.
28
+
threshold (float): Higher is more likely to allow bias. Lower is more sensitive and more likely to flag biased messages.
29
+
on_fail (Callable): The policy to enact when a validator fails. If `str`, must be one of `noop`, `fix`, or `exception`. Otherwise, must be a function that is called when the validator fails.
0 commit comments