From e22384118359423cfc57de904a9946dd085a7cc4 Mon Sep 17 00:00:00 2001 From: Saqib Shamsi Date: Tue, 2 Nov 2021 19:56:38 +0530 Subject: [PATCH 1/2] Added default argument for instantiating ToxicityFilter class --- filters/toxicity/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filters/toxicity/filter.py b/filters/toxicity/filter.py index f958e8c54..2b27c7baf 100644 --- a/filters/toxicity/filter.py +++ b/filters/toxicity/filter.py @@ -24,7 +24,7 @@ class ToxicityFilter(SentenceOperation): def __init__( self, - toxicity_type: ToxicityTypes, + toxicity_type: ToxicityTypes = ToxicityTypes.TOXICITY, op: str = ">", threshold: float = 0.5, ): From 392b3ff77d9b78e8e4e6d6e690a38f93e7c06589 Mon Sep 17 00:00:00 2001 From: Saqib Shamsi Date: Tue, 7 Dec 2021 12:08:32 +0530 Subject: [PATCH 2/2] black changes --- filters/toxicity/filter.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/filters/toxicity/filter.py b/filters/toxicity/filter.py index 2b27c7baf..9d6210976 100644 --- a/filters/toxicity/filter.py +++ b/filters/toxicity/filter.py @@ -18,8 +18,14 @@ class ToxicityTypes(str, enum.Enum): class ToxicityFilter(SentenceOperation): + + """ + Filter to select sentences based on their toxicity. + """ + tasks = [TaskType.TEXT_TO_TEXT_GENERATION] languages = ["en"] + keywords = ["semantic", "social-reasoning"] heavy = True def __init__( @@ -28,6 +34,14 @@ def __init__( op: str = ">", threshold: float = 0.5, ): + """ + Initialize filter by specifying the type and threshold values for toxicity. + :param toxicity_type: One of ToxicityTypes.TOXICITY, ToxicityTypes.SEVERE_TOXICITY, + ToxicityTypes.OBSCENE, ToxicityTypes.IDENTITY_ATTACK, + ToxicityTypes.INSULT, ToxicityTypes.THREAT, ToxicityTypes.SEXUAL_EXPLICIT + :param op: Operator to compare the toxicity value to the threshold. One of ">", "<", ">=", "<=", "==". + :param threshold: A float value between 0.0 and 1.0 for comparing toxicity of an input text. + """ super().__init__() self.check_threshold_value(threshold)