

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

# 使用毒性言论检测
<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"
}
```