If a callback is provided in this case, then it will be called for each of the checks that have been performed. For example, in the case above, if the Chain fails due to the presence of PII then the Toxicity and Intent checks will not be performed.You can override the execution order by passing moderation_config and simply specifying the desired order in the filters key of the configuration. In case you use moderation_config then the order of the checks as specified in the filters key will be maintained. For example, in the configuration below, first Toxicity check will be performed, then PII, and finally Intent validation will be performed. In this case, AmazonComprehendModerationChain will perform the desired checks in the specified order with default values of each model kwargs.moderation_config = {         "filters":[ BaseModerationFilters.TOXICITY,                     BaseModerationFilters.PII,                     BaseModerationFilters.INTENT]   }Model kwargs are specified by the pii, toxicity, and intent keys within the moderation_config dictionary. For example, in the moderation_config below, the default order of moderation is overriden and the pii & toxicity model kwargs have been overriden. For intent the chain's default kwargs will be used. moderation_config = {         "filters":[ BaseModerationFilters.TOXICITY,                     BaseModerationFilters.PII,                     BaseModerationFilters.INTENT],        "pii":{ "action": BaseModerationActions.ALLOW,                 "threshold":0.5,                 "labels":["SSN"],                 "mask_character": "X" },        "toxicity":{ "action": BaseModerationActions.STOP,                      "threshold":0.5 }   }For a list of PII labels see Amazon Comprehend Universal PII entity types - https://docs.aws.amazon.com/comprehend/latest/dg/how-pii.html#how-pii-typesFollowing are the list of available Toxicity labels-HATE_SPEECH: Speech that criticizes, insults, denounces or dehumanizes a person or a group
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity.
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity. ->: If a callback is provided in this case, then it will be called for each of the checks that have been performed. For example, in the case above, if the Chain fails due to the presence of PII then the Toxicity and Intent checks will not be performed.You can override the execution order by passing moderation_config and simply specifying the desired order in the filters key of the configuration. In case you use moderation_config then the order of the checks as specified in the filters key will be maintained. For example, in the configuration below, first Toxicity check will be performed, then PII, and finally Intent validation will be performed. In this case, AmazonComprehendModerationChain will perform the desired checks in the specified order with default values of each model kwargs.moderation_config = {         "filters":[ BaseModerationFilters.TOXICITY,                     BaseModerationFilters.PII,                     BaseModerationFilters.INTENT]   }Model kwargs are specified by the pii, toxicity, and intent keys within the moderation_config dictionary. For example, in the moderation_config below, the default order of moderation is overriden and the pii & toxicity model kwargs have been overriden. For intent the chain's default kwargs will be used. moderation_config = {         "filters":[ BaseModerationFilters.TOXICITY,                     BaseModerationFilters.PII,                     BaseModerationFilters.INTENT],        "pii":{ "action": BaseModerationActions.ALLOW,                 "threshold":0.5,                 "labels":["SSN"],                 "mask_character": "X" },        "toxicity":{ "action": BaseModerationActions.STOP,                      "threshold":0.5 }   }For a list of PII labels see Amazon Comprehend Universal PII entity types - https://docs.aws.amazon.com/comprehend/latest/dg/how-pii.html#how-pii-typesFollowing are the list of available Toxicity labels-HATE_SPEECH: Speech that criticizes, insults, denounces or dehumanizes a person or a group