Skip to content

Latest commit

 

History

History
178 lines (111 loc) · 5.75 KB

File metadata and controls

178 lines (111 loc) · 5.75 KB

Amazon Comprehend code examples for the SDK for Python

Overview

Shows how to use the AWS SDK for Python (Boto3) to work with Amazon Comprehend.

Amazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents without the need of any special preprocessing.

⚠ Important

  • Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Code examples

Prerequisites

For prerequisites, see the README in the python folder.

Install the packages required by these examples by running the following in a virtual environment:

python -m pip install -r requirements.txt

Single actions

Code excerpts that show you how to call individual service functions.

Scenarios

Code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Cross-service examples

Sample applications that work across multiple AWS services.

Run the examples

Instructions

Detect document elements

This example shows you how to do the following:

  • Detect languages, entities, and key phrases in a document.
  • Detect personally identifiable information (PII) in a document.
  • Detect the sentiment of a document.
  • Detect syntax elements in a document.

Start the example by running the following at a command prompt:

python comprehend_detect.py

Run a topic modeling job on sample data

This example shows you how to do the following:

  • Run an Amazon Comprehend topic modeling job on sample data.
  • Get information about the job.
  • Extract job output data from Amazon S3.

Start the example by running the following at a command prompt:

python comprehend_topic_modeler.py

Train a custom classifier and classify documents

This example shows you how to do the following:

  • Create an Amazon Comprehend multi-label classifier.
  • Train the classifier on sample data.
  • Run a classification job on a second set of data.
  • Extract the job output data from Amazon S3.

Start the example by running the following at a command prompt:

python comprehend_classifier.py

Tests

⚠ Running tests might result in charges to your AWS account.

To find instructions for running these tests, see the README in the python folder.

Additional resources


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0