Skip to content
Open
Changes from all 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
16 changes: 15 additions & 1 deletion filters/toxicity/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be great if you can add docstring for your classes and functions.

def __init__(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add keywords for your filter.

self,
toxicity_type: ToxicityTypes,
toxicity_type: ToxicityTypes = ToxicityTypes.TOXICITY,
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)
Expand Down