

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 检测毒性言论
<a name="toxicity"></a>

 毒性言论检测旨在帮助管理涉及点对点对话的社交媒体平台，例如在线游戏和社交聊天平台。使用毒性言论可能对个人、同类群体和社区造成严重损害。标记毒性言论有助于组织保持对话的文明性，维护一个安全、包容的网络环境，让用户可以自由创建、分享和参与。

 Amazon Transcribe 毒性检测利用基于音频和文本的线索，对基于语音的毒性内容进行识别和分类，分为七个类别，包括性骚扰、仇恨言论、威胁、虐待、亵渎、侮辱和图片。除文本外，Amazon Transcribe 毒性检测还使用言论线索（例如语调和音高）来仔细研究言论中的毒性意图。这是对标准内容审核系统的改进，标准内容审核系统旨在仅关注特定术语，而不考虑意图。

 Amazon Transcribe 对毒性言论进行标记和分类，从而最大限度地减少必须手动处理的数据量。这使内容审阅者能够快速高效地管理其平台上的话语。

毒性言论类别包括：
+ **亵渎**：包含不礼貌、粗俗或令人反感的单词、短语或首字母缩略词的言论。
+ **仇恨言论**：基于身份（例如种族、民族、性别、宗教、性取向、能力和国籍）批评、侮辱、谴责或非人性化的言论。
+ **性**：通过直接或间接提及身体部位、身体特征或性别来表示性兴趣、活动或性唤起的言论。
+ **侮辱**：包括贬低、羞辱、嘲笑、侮辱或贬低语言的言论。这种语言也被标记为欺凌。
+ **暴力或威胁**：包括企图对个人或群体造成痛苦、伤害或敌意的威胁的言论。
+ **图形性言论**：使用视觉描述和令人不快的生动形象来表达的言论。这种语言通常故意过于详细，以加剧接受者的不适感。
+ **骚扰或虐待**：旨在影响接受者心理健康的言论，包括贬低和物化用语。这种语言也被标记为骚扰。

 毒性检测会分析语音片段（自然停顿之间的语音），并为这些片段分配置信度分数。置信度分数是介于 0 和 1 之间的值。置信度分数越大，表示内容属于关联类别毒性言论中的内容的可能性越大。您可以使用这些置信度分数为您的用例设置适当的毒性检测阈值。

**注意**  
 毒性检测仅适用于美国英语 (`(en-US)`) 的批量转录。

 查看 JSON 格式的[示例输出](toxicity-using.md#toxicity-using-output.title)。

# 使用毒性言论检测
<a name="toxicity-using"></a>

## 在批量转录中使用毒性言论检测
<a name="toxicity-using-batch"></a>

要将毒性言论检测与批量转录一起使用，请查看以下示例：

### AWS 管理控制台
<a name="toxicity-using-console-batch"></a>

1. 登录到 [AWS 管理控制台](https://console.aws.amazon.com/transcribe/)。

1. 在导航窗格中，选择**转录作业**，然后选择**创建作业**（右上角）。这将打开**指定作业详细信息**页面。  
![\[Amazon Transcribe 控制台屏幕截图：“指定作业详细信息”页面。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/toxicity-batch-details-1.png)

1.  在**指定作业详细信息**页面上，您也可以根据需要启用 PII 编辑。请注意，毒性检测不支持列出的其它选项。选择**下一步**。此时您将会看到**配置作业 - 可选**页面。在**音频设置** 面板中，选择**毒性检测**。  
![\[Amazon Transcribe 控制台屏幕截图：“配置作业”页面。\]](http://docs.aws.amazon.com/zh_cn/transcribe/latest/dg/images/toxicity-batch-details-2.png)

1. 选择**创建作业**以运行您的转录作业。

1. 转录作业完成后，您可以从转录作业详情页面的**下载**下拉菜单中下载转录。

### AWS CLI
<a name="toxicity-using-cli-batch"></a>

此示例使用 [start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html) 命令和 `ToxicityDetection` 参数。有关更多信息，请参阅 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html) 和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ToxicityDetection.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_ToxicityDetection.html)。

```
aws transcribe start-transcription-job \
--region us-west-2 \
--transcription-job-name my-first-transcription-job \
--media MediaFileUri=s3://amzn-s3-demo-bucket/my-input-files/my-media-file.flac \
--output-bucket-name amzn-s3-demo-bucket \
--output-key my-output-files/ \
--language-code en-US \
--toxicity-detection ToxicityCategories=ALL
```

以下是另一个使用 [start-transcription-job](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/transcribe/start-transcription-job.html) 命令的示例，以及包含毒性检测的请求正文。

```
aws transcribe start-transcription-job \
--region us-west-2 \
--cli-input-json file://filepath/my-first-toxicity-job.json
```

*my-first-toxicity-job.json* 文件包含以下请求正文。

```
{
  "TranscriptionJobName": "my-first-transcription-job",
  "Media": {
        "MediaFileUri": "s3://amzn-s3-demo-bucket/my-input-files/my-media-file.flac"
  },
  "OutputBucketName": "amzn-s3-demo-bucket",
  "OutputKey": "my-output-files/", 
  "LanguageCode": "en-US",
  "ToxicityDetection": [ 
      { 
         "ToxicityCategories": [ "ALL" ]
      }
   ]
}
```

### 适用于 Python (Boto3) 的 AWS SDK
<a name="toxicity-using-python-batch"></a>

 此示例使用 适用于 Python (Boto3) 的 AWS SDK 通过 [start\$1transcription\$1job](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.start_transcription_job) 方法启用 `ToxicityDetection`。有关更多信息，请参阅 [https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/API_StartTranscriptionJob.html) 和 [https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html](https://docs.aws.amazon.com/transcribe/latest/APIReference/Welcome.html)。

有关使用 AWS SDK 的其它示例，包括特定特征、场景和跨服务示例，请参阅[使用 Amazon Transcribe 的代码示例 AWS SDKs](service_code_examples.md)一章。

```
from __future__ import print_function
import time
import boto3
transcribe = boto3.client('transcribe', 'us-west-2')
job_name = "my-first-transcription-job"
job_uri = "s3://amzn-s3-demo-bucket/my-input-files/my-media-file.flac"
transcribe.start_transcription_job(
    TranscriptionJobName = job_name,
    Media = {
        'MediaFileUri': job_uri
    },
    OutputBucketName = 'amzn-s3-demo-bucket',
    OutputKey = 'my-output-files/', 
    LanguageCode = 'en-US', 
    ToxicityDetection = [ 
        { 
            'ToxicityCategories': ['ALL']
        }
    ]
)

while True:
    status = transcribe.get_transcription_job(TranscriptionJobName = job_name)
    if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
        break
    print("Not ready yet...")
    time.sleep(5)
print(status)
```

## 示例输出
<a name="toxicity-using-output"></a>

 在您的转录输出中，会对毒性言论进行标记和分类。对每个毒性言论进行分类并分配置信度分数（介于 0 和 1 之间的值）。置信度值越大，表示内容属于指定类别的毒性言论的可能性越大。

### 示例输出 (JSON)
<a name="toxicity-using-output-json"></a>

 以下是 JSON 格式的示例输出，显示了经过分类的毒性言论以及相关的置信度分数。

```
{
    "jobName": "my-toxicity-job",
    "accountId": "111122223333",
    "results": {
        "transcripts": [...],
        "items":[...],
        "toxicity_detection": [
            {
                "text": "What the * are you doing man? That's why I didn't want to play with your * .  man it was a no, no I'm not calming down * man. I well I spent I spent too much * money on this game.",
                "toxicity": 0.7638,
                "categories": {
                    "profanity": 0.9913,
                    "hate_speech": 0.0382,
                    "sexual": 0.0016,
                    "insult": 0.6572,
                    "violence_or_threat": 0.0024,
                    "graphic": 0.0013,
                    "harassment_or_abuse": 0.0249
                },
                "start_time": 8.92,
                "end_time": 21.45
            },
            Items removed for brevity
            {
                "text": "What? Who? What the * did you just say to me? What's your address? What is your * address? I will pull up right now on your * * man. Take your * back to , tired of this **.",
                "toxicity": 0.9816,
                "categories": {
                    "profanity": 0.9865,
                    "hate_speech": 0.9123,
                    "sexual": 0.0037,
                    "insult": 0.5447,
                    "violence_or_threat": 0.5078,
                    "graphic": 0.0037,
                    "harassment_or_abuse": 0.0613
                },
                "start_time": 43.459,
                "end_time": 54.639
            },
        ]
    },
    ...
    "status": "COMPLETED"
}
```