Amazon Comprehend

2023/11/09 - Amazon Comprehend - 1 new api methods

Changes  This release adds support for toxicity detection and prompt safety classification.

DetectToxicContent (new) Link ΒΆ

Performs toxicity analysis on the list of text strings that you provide as input. The analysis uses the order of strings in the list to determine context when predicting toxicity. The API response contains a results list that matches the size of the input list. For more information about toxicity detection, see Toxicity detection in the Amazon Comprehend Developer Guide

See also: AWS API Documentation

Request Syntax

client.detect_toxic_content(
    TextSegments=[
        {
            'Text': 'string'
        },
    ],
    LanguageCode='en'|'es'|'fr'|'de'|'it'|'pt'|'ar'|'hi'|'ja'|'ko'|'zh'|'zh-TW'
)
type TextSegments

list

param TextSegments

[REQUIRED]

A list of up to 10 text strings. The maximum size for the list is 10 KB.

  • (dict) --

    One of the of text strings. Each string has a size limit of 1KB.

    • Text (string) -- [REQUIRED]

      The text content.

type LanguageCode

string

param LanguageCode

[REQUIRED]

The language of the input text. Currently, English is the only supported language.

rtype

dict

returns

Response Syntax

{
    'ResultList': [
        {
            'Labels': [
                {
                    'Name': 'GRAPHIC'|'HARASSMENT_OR_ABUSE'|'HATE_SPEECH'|'INSULT'|'PROFANITY'|'SEXUAL'|'VIOLENCE_OR_THREAT',
                    'Score': ...
                },
            ],
            'Toxicity': ...
        },
    ]
}

Response Structure

  • (dict) --

    • ResultList (list) --

      Results of the content moderation analysis. Each entry in the results list contains a list of toxic content types identified in the text, along with a confidence score for each content type. The results list also includes a toxicity score for each entry in the results list.

      • (dict) --

        Toxicity analysis result for one string. For more information about toxicity detection, see Toxicity detection in the Amazon Comprehend Developer Guide

        • Labels (list) --

          Array of toxic content types identified in the string.

          • (dict) --

            Toxic content analysis result for one string. For more information about toxicity detection, see Toxicity detection in the Amazon Comprehend Developer Guide

            • Name (string) --

              The name of the toxic content type.

            • Score (float) --

              Model confidence in the detected content type. Value range is zero to one, where one is highest confidence.

        • Toxicity (float) --

          Overall toxicity score for the string.