

# Tutorial: Analyzing insights from customer reviews with Amazon Comprehend
<a name="tutorial-reviews"></a>

This tutorial explains how to use Amazon Comprehend with [Amazon Simple Storage Service](https://aws.amazon.com/s3/), [AWS Glue](https://aws.amazon.com/glue/), [Amazon Athena](https://aws.amazon.com/athena/), and [Amazon Quick](https://aws.amazon.com/quicksight/) to gain valuable insights into your documents. Amazon Comprehend can extract sentiment (the mood of a document) and entities (names of people, organizations, events, dates, products, places, quantities, and titles) from unstructured text.

For example, you can get actionable insights from customer reviews. In this tutorial, you analyze a sample dataset of customer reviews about a novel. You use Amazon Comprehend sentiment analysis to determine whether customers feel positive or negative about the novel. You also use Amazon Comprehend entities analysis to discover mentions of important entities, such as related novels or authors. After following this tutorial, you might discover that over 50% of the reviews are positive. You might also discover that customers are comparing authors and expressing interest in other classic novels.

In this tutorial, you accomplish the following:
+ Store a sample dataset of reviews in [Amazon Simple Storage Service](https://aws.amazon.com/s3/) (Amazon S3). Amazon Simple Storage Service is an object storage service.
+ Use [Amazon Comprehend](https://aws.amazon.com/comprehend/) to analyze the sentiment and entities in the review documents.
+ Use an [AWS Glue](https://aws.amazon.com/glue/) crawler to store the results of the analysis in a database. AWS Glue is an extract, transform, and load (ETL) service that lets you catalog and clean your data for analytics.
+ Run [Amazon Athena](https://aws.amazon.com/athena/) queries to clean your data. Amazon Athena is a serverless interactive query service.
+ Create visualizations with your data in [Amazon Quick](https://aws.amazon.com/quicksight/). Quick is a serverless business intelligence tool for extracting insights from your data.

The following diagram shows the workflow.

![\[Workflow diagram of the procedures in the tutorial.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-workflow.png)


**Estimated time to complete this tutorial:** 1 hour

**Estimated cost:** Some of the actions in this tutorial incur charges on your AWS account. For information about the charges for each of these services, see the following pricing pages.
+ [Amazon S3 pricing](https://aws.amazon.com/s3/pricing/)
+ [Amazon Comprehend pricing](https://aws.amazon.com/comprehend/pricing/)
+ [AWS Glue pricing](https://aws.amazon.com/glue/pricing/)
+ [Amazon Athena pricing](https://aws.amazon.com/athena/pricing/)
+ [Quick pricing](https://aws.amazon.com/quicksight/pricing/)

**Topics**
+ [Prerequisites](#tutorial-reviews-prereqs)
+ [Step 1: Adding documents to Amazon S3](tutorial-reviews-add-docs.md)
+ [Step 2: (CLI only) creating an IAM role for Amazon Comprehend](tutorial-reviews-create-role.md)
+ [Step 3: Running analysis jobs on documents in Amazon S3](tutorial-reviews-analysis.md)
+ [Step 4: Preparing the Amazon Comprehend output for data visualization](tutorial-reviews-tables.md)
+ [Step 5: Visualizing Amazon Comprehend output in Quick](tutorial-reviews-visualize.md)

## Prerequisites
<a name="tutorial-reviews-prereqs"></a>

To complete this tutorial, you need the following:
+ An AWS account. For information about setting up an AWS account, see [Setting up](setting-up.md).
+ An IAM entity (user, group or role). To learn how to set up users and groups for your account, see the [ Getting started](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started.html) tutorial in the *IAM User Guide*.
+ The following permissions policy attached to your user, group or role. The policy grants some of the permissions required to complete this tutorial. The next prerequisite describes the additional permissions you need. 

------
#### [ JSON ]

****  

  ```
  {
    "Version":"2012-10-17",		 	 	 
    "Statement":
    [
      {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action":
        [
          "comprehend:*",
          "ds:AuthorizeApplication",
          "ds:CheckAlias",
          "ds:CreateAlias",
          "ds:CreateIdentityPoolDirectory",
          "ds:DeleteDirectory",
          "ds:DescribeDirectories",
          "ds:DescribeTrusts",
          "ds:UnauthorizeApplication",
          "iam:AttachRolePolicy",
          "iam:CreatePolicy",
          "iam:CreatePolicyVersion",
          "iam:CreateRole",
          "iam:DeletePolicyVersion",
          "iam:DeleteRole",
          "iam:DetachRolePolicy",
          "iam:GetPolicy",
          "iam:GetPolicyVersion",
          "iam:GetRole",
          "iam:ListAccountAliases",
          "iam:ListAttachedRolePolicies",
          "iam:ListEntitiesForPolicy",
          "iam:ListPolicies",
          "iam:ListPolicyVersions",
          "iam:ListRoles",
          "quicksight:*",
          "s3:*",
          "tag:GetResources"
        ],
        "Resource": "*"
      },
      {
        "Action":
        [
          "iam:PassRole"
        ],
        "Effect": "Allow",
        "Resource":
        [
          "arn:aws:iam::*:role/*Comprehend*"
        ]
      }
    ]
  }
  ```

------

  Use the previous policy to create an IAM policy and attach it to your group or user. For information about creating an IAM policy, see [Creating IAM policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) in the *IAM User Guide*. For information about attaching an IAM policy, see [Adding and removing IAM identity permissions](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html) in the *IAM User Guide*.
+ Managed policies attached to your IAM group or user. In addition to the previous policy, you must also attach the following AWS managed policies to your group or user:
  + `AWSGlueConsoleFullAccess`
  + `AWSQuicksightAthenaAccess`

  These managed policies give you permission to use AWS Glue, Amazon Athena, and Quick. For information about attaching an IAM policy, see [Adding and removing IAM identity permissions](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html) in the *IAM User Guide*.

# Step 1: Adding documents to Amazon S3
<a name="tutorial-reviews-add-docs"></a>

Before starting the Amazon Comprehend analysis jobs, you need to store a sample dataset of customer reviews in Amazon Simple Storage Service (Amazon S3). Amazon S3 hosts your data in containers called buckets. Amazon Comprehend can analyze documents stored in a bucket and it sends results of the analysis to a bucket. In this step, you create an S3 bucket, create input and output folders in the bucket, and upload a sample dataset to the bucket.

**Topics**
+ [Prerequisites](#tutorial-reviews-add-docs-prereqs)
+ [Download sample data](#tutorial-reviews-add-docs-download)
+ [Create an Amazon S3 bucket](#tutorial-reviews-add-docs-bucket)
+ [(Console only) create folders](#tutorial-reviews-add-docs-folders)
+ [Upload the input data](#tutorial-reviews-add-docs-upload)

## Prerequisites
<a name="tutorial-reviews-add-docs-prereqs"></a>

Before you begin, review [Tutorial: Analyzing insights from customer reviews with Amazon Comprehend](tutorial-reviews.md) and complete the prerequisites.

## Download sample data
<a name="tutorial-reviews-add-docs-download"></a>

The following sample dataset contains Amazon reviews taken from the larger dataset "Amazon reviews - Full", which was published with the article "Character-level Convolutional Networks for Text Classification" (Xiang Zhang et al., 2015). Download the dataset to your computer.

**To get the sample data**

1. Download the zip file [tutorial-reviews-data.zip](samples/tutorial-reviews-data.zip) to your computer.

1. Extract the zip file on your computer. There are two files. The file `THIRD_PARTY_LICENSES.txt` is the open source license for the dataset published by Xiang Zhang et al. The file `amazon-reviews.csv` is the dataset you analyze in the tutorial.

## Create an Amazon S3 bucket
<a name="tutorial-reviews-add-docs-bucket"></a>

After downloading the sample dataset, create an Amazon S3 bucket to store your input and output data. You can create an S3 bucket using the Amazon S3 console or the AWS Command Line Interface (AWS CLI). 

### Create an Amazon S3 bucket (console)
<a name="tutorial-reviews-add-docs-bucket-console"></a>

In the Amazon S3 console, you create a bucket with a name that is unique in all of AWS.

**To create an S3 bucket (console)**

1. Sign in to the AWS Management Console and open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In **Buckets**, choose **Create bucket**.

1. For **Bucket name**, enter a globally unique name that describes the bucket's purpose.

1. For **Region**, choose the AWS Region where you want to create the bucket. The Region you choose must support Amazon Comprehend. To reduce latency, choose the AWS Region closest to your geographic location that is supported by Amazon Comprehend. For a list of Regions that support Amazon Comprehend, see the [Region table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) in the *Global Infrastructure Guide*.

1. Leave the default settings for **Object Ownership**, **Bucket settings for Block Public Access**, **Bucket Versioning**, and **Tags**.

1. For **Default encryption**, choose **Disable**. 
**Tip**  
While this tutorial does not use encryption, you might want to use encryption when analyzing important data. For end-to-end encryption, you can encrypt your data at rest in the bucket and also when you run analysis jobs. For more information about encryption with AWS, see [What is AWS Key Management Service?](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) in the *AWS Key Management Service Developer Guide*.

1. Review your bucket configurations and then choose **Create bucket**.

### Create an Amazon S3 bucket (AWS CLI)
<a name="tutorial-reviews-add-docs-bucket-cli"></a>

After opening the AWS CLI, you run the `create-bucket` command to create a bucket that will store the input and output data.

**To create an Amazon S3 bucket (AWS CLI)**

1. To create your bucket, run the following command in the AWS CLI. Replace amzn-s3-demo-bucket with a name for the bucket that is unique in all of AWS.

   ```
   aws s3api create-bucket --bucket amzn-s3-demo-bucket
   ```

   By default, the `create-bucket` command creates a bucket in the `us-east-1` AWS Region. To create a bucket in an AWS Region other than `us-east-1`, add the `LocationConstraint` parameter to specify your Region. For example, the following command creates a bucket in the `us-west-2` Region.

   ```
   aws s3api create-bucket --bucket amzn-s3-demo-bucket
   --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
   ```

   Note that only certain Regions support Amazon Comprehend. For a list of Regions that support Amazon Comprehend, see the [Region table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) in the *Global Infrastructure Guide*.

1. To ensure that your bucket was created successfully, run the following command. The command lists all of the S3 buckets associated with your account.

   ```
   aws s3 ls
   ```

## (Console only) create folders
<a name="tutorial-reviews-add-docs-folders"></a>

Next, create two folders in your S3 bucket. The first folder is for your input data. The second folder is where Amazon Comprehend sends the analysis results. If you use the Amazon S3 console, you have to manually create the folders. If you use the AWS CLI, you can create folders when you upload the sample dataset or run an analysis job. For that reason, we provide a procedure for creating folders only for console users. If you are using the AWS CLI, you will create folders in [Upload the input data](#tutorial-reviews-add-docs-upload) and in [Step 3: Running analysis jobs on documents in Amazon S3](tutorial-reviews-analysis.md).

**To create folders in your S3 bucket (console)**

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In **Buckets**, choose your bucket from the list of buckets.

1. In the **Overview** tab, choose **Create folder**.

1. For the new folder name, enter `input`.

1. For the encryption settings, choose **None (Use bucket settings)**.

1. Choose **Save**.

1. Repeat steps 3 through 6 to create another folder for the output of the analysis jobs, but in step 4, enter the new folder name `output`.

## Upload the input data
<a name="tutorial-reviews-add-docs-upload"></a>

Now that you have a bucket, upload the sample dataset `amazon-reviews.csv`. You can upload data to S3 buckets with the Amazon S3 console or the AWS CLI. 

### Upload sample documents to a bucket (console)
<a name="tutorial-reviews-add-docs-upload-console"></a>

In the Amazon S3 console, upload the sample dataset file to the input folder.

**To upload the sample documents (console)**

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In **Buckets**, choose your bucket from the list of buckets.

1. Choose the `input` folder and then choose **Upload**.

1. Choose **Add files** and then choose the `amazon-reviews.csv` file on your computer.

1. Leave the other settings at their default values.

1. Choose **Upload**.

### Upload sample documents to a bucket (AWS CLI)
<a name="tutorial-reviews-add-docs-upload-cli"></a>

Create an input folder in your S3 bucket and upload the dataset file to the new folder with the `cp` command.

**To upload the sample documents (AWS CLI)**

1. To upload the `amazon-reviews.csv` file to a new folder in your bucket, run the following AWS CLI command. Replace amzn-s3-demo-bucket with the name of your bucket. By adding the path `/input/` at the end, Amazon S3 automatically creates a new folder called `input` in your bucket and uploads the dataset file to that folder.

   ```
   aws s3 cp amazon-reviews.csv s3://amzn-s3-demo-bucket/input/
   ```

1. To ensure that your file was uploaded successfully, run the following command. The command lists the contents of your bucket's `input` folder.

   ```
   aws s3 ls s3://amzn-s3-demo-bucket/input/
   ```

Now, you have an S3 bucket with the `amazon-reviews.csv` file in a folder called `input`. If you used the console, you also have an `output` folder in the bucket. If you used the AWS CLI, you will create the output folder when running the Amazon Comprehend analysis jobs.

# Step 2: (CLI only) creating an IAM role for Amazon Comprehend
<a name="tutorial-reviews-create-role"></a>

This step is necessary only if you are using the AWS Command Line Interface (AWS CLI) to complete this tutorial. If you are using the Amazon Comprehend console to run the analysis jobs, skip to [Step 3: Running analysis jobs on documents in Amazon S3](tutorial-reviews-analysis.md).

To run analysis jobs, Amazon Comprehend requires access to the Amazon S3 bucket that contains the sample dataset and will contain the jobs' output. IAM roles allow you to control the permissions of AWS services or users. In this step, you create an IAM role for Amazon Comprehend. Then, you create and attach to this role a resource-based policy that grants Amazon Comprehend access to your S3 bucket. By the end of this step, Amazon Comprehend will have the necessary permissions to access your input data, store your output, and run sentiment and entities analysis jobs.

For more information about using IAM with Amazon Comprehend, see [How Amazon Comprehend works with IAM](security_iam_service-with-iam.md).

**Topics**
+ [Prerequisites](#tutorial-reviews-create-role-prereqs)
+ [Create an IAM role](#tutorial-reviews-create-role-trust-policy)
+ [Attach an IAM policy to the IAM role](#tutorial-reviews-create-role-policy)

## Prerequisites
<a name="tutorial-reviews-create-role-prereqs"></a>

Before you begin, do the following:
+ Complete [Step 1: Adding documents to Amazon S3](tutorial-reviews-add-docs.md).
+ Have a code or text editor to save JSON policies and keep track of your Amazon Resource Names (ARNs).

## Create an IAM role
<a name="tutorial-reviews-create-role-trust-policy"></a>

To access your Amazon Simple Storage Service (Amazon S3) bucket, Amazon Comprehend needs to assume an AWS Identity and Access Management (IAM) role. The IAM role declares Amazon Comprehend as a trusted entity. After Amazon Comprehend assumes the role and becomes a trusted entity, you can grant bucket access permissions to Amazon Comprehend. In this step, you create a role that labels Amazon Comprehend as a trusted entity. You can create a role with the AWS CLI or the Amazon Comprehend console. To use the console, skip to [Step 3: Running analysis jobs on documents in Amazon S3](tutorial-reviews-analysis.md).

The Amazon Comprehend console lets you select roles where the role name contains 'Comprehend' and the trust policy includes **comprehend.amazonaws.com**. Configure your CLI-created roles to meet these criteria if you want the console to display them.



**To create an IAM role for Amazon Comprehend (AWS CLI)**

1. Save the following trust policy as a JSON document called `comprehend-trust-policy.json` in a code or text editor on your computer. This trust policy declares Amazon Comprehend as a trusted entity and allows it to assume an IAM role.

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "comprehend.amazonaws.com"
         },
         "Action": "sts:AssumeRole"
       }
     ]
   }
   ```

------

1. To create the IAM role, run the following AWS CLI command. The command creates an IAM role called `AmazonComprehendServiceRole-access-role` and attaches the trust policy to the role. Replace `path/` with your local computer's path to the JSON document.

   ```
   aws iam create-role --role-name AmazonComprehendServiceRole-access-role
   --assume-role-policy-document file://path/comprehend-trust-policy.json
   ```
**Tip**  
If you get an Error parsing parameter message, the path to your JSON trust policy file is probably incorrect. Provide the relative path to the file based on your home directory.

1. Copy the Amazon Resource Name (ARN) and save it in a text editor. The ARN has a format similar to `arn:aws:iam::123456789012:role/AmazonComprehendServiceRole-access-role`. You need this ARN to run Amazon Comprehend analysis jobs.

## Attach an IAM policy to the IAM role
<a name="tutorial-reviews-create-role-policy"></a>

To access your Amazon S3 bucket, Amazon Comprehend needs permissions to list, read, and write. To give Amazon Comprehend the required permissions, create and attach an IAM policy to your IAM role. The IAM policy allows Amazon Comprehend to retrieve the input data from your bucket and write analysis results to the bucket. After creating the policy, you attach it to your IAM role.

**To create an IAM policy (AWS CLI)**

1. Save the following policy locally as a JSON document called `comprehend-access-policy.json`. It grants Amazon Comprehend access to the specified S3 bucket.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Action": [
                   "s3:GetObject"
               ],
               "Resource": [
                   "arn:aws:s3:::amzn-s3-demo-bucket/*"
               ],
               "Effect": "Allow"
           },
           {
               "Action": [
                   "s3:ListBucket"
               ],
               "Resource": [
                   "arn:aws:s3:::amzn-s3-demo-bucket"
               ],
               "Effect": "Allow"
           },
           {
               "Action": [
                   "s3:PutObject"
               ],
               "Resource": [
                   "arn:aws:s3:::amzn-s3-demo-bucket/*"
               ],
               "Effect": "Allow"
           }
       ]
   }
   ```

------

1. To create the S3 bucket access policy, run the following AWS CLI command. Replace `path/` with your local computer's path to the JSON document.

   ```
   aws iam create-policy --policy-name comprehend-access-policy
   --policy-document file://path/comprehend-access-policy.json
   ```

1. Copy the access policy ARN and save it in a text editor. The ARN has a format similar to `arn:aws:iam::123456789012:policy/comprehend-access-policy`. You need this ARN to attach your access policy to your IAM role.

**To attach the IAM policy to your IAM role (AWS CLI)**
+ Run the following command. Replace `policy-arn` with the access policy ARN that you copied in the previous step.

  ```
  aws iam attach-role-policy --policy-arn policy-arn
  --role-name AmazonComprehendServiceRole-access-role
  ```

You now have an IAM role called `AmazonComprehendServiceRole-access-role` that has a trust policy for Amazon Comprehend and an access policy that grants Amazon Comprehend access to your S3 bucket. You also have the ARN for the IAM role copied to a text editor.

# Step 3: Running analysis jobs on documents in Amazon S3
<a name="tutorial-reviews-analysis"></a>

After storing the data in Amazon S3, you can begin running Amazon Comprehend analysis jobs. A *sentiment* analysis job determines the overall mood of a document (positive, negative, neutral, or mixed). An *entities* analysis job extracts the names of real-world objects from a document. These objects include people, places, titles, events, dates, quantities, products, and organizations. In this step, you run two Amazon Comprehend analysis jobs to extract the sentiment and entities from the sample dataset.

**Topics**
+ [Prerequisites](#tutorial-reviews-analysis-prereqs)
+ [Analyze sentiment and entities](#tutorial-reviews-analysis-jobs)

## Prerequisites
<a name="tutorial-reviews-analysis-prereqs"></a>

Before you begin, do the following:
+ Complete [Step 1: Adding documents to Amazon S3](tutorial-reviews-add-docs.md).
+ (Optional) If you are using the AWS CLI, complete [Step 2: (CLI only) creating an IAM role for Amazon Comprehend](tutorial-reviews-create-role.md) and have your IAM role ARN ready.

## Analyze sentiment and entities
<a name="tutorial-reviews-analysis-jobs"></a>

The first job you run analyzes the sentiment of each customer review in the sample dataset. The second job extracts the entities in each customer review. You can perform Amazon Comprehend analysis jobs either using the Amazon Comprehend console or the AWS CLI. 

**Tip**  
Make sure that you are in an AWS Region that supports Amazon Comprehend. For more information, see the [Region table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) in the *Global Infrastructure Guide*.

### Analyze sentiments and entities (console)
<a name="tutorial-reviews-analysis-jobs-console"></a>

When using the Amazon Comprehend console, you create one job at a time. You need to repeat the following steps in order to run both a sentiment and an entities analysis job. Note that for the first job, you create an IAM role, but for the second job, you can reuse the first job's IAM role. You can reuse the IAM role as long as you use the same S3 bucket and folders.

**To run sentiment and entities analysis jobs (console)**

1. Ensure that you're in the same Region in which you created your Amazon Simple Storage Service (Amazon S3) bucket. If you're in another Region, in the navigation bar, choose the AWS Region where you created your S3 bucket from the **Region selector**.

1. Open the Amazon Comprehend console at [https://console.aws.amazon.com/comprehend/](https://console.aws.amazon.com/comprehend/)

1. Choose **Launch Amazon Comprehend**.

1. In the navigation pane, choose **Analysis jobs**.

1. Choose **Create job**.

1. In the **Job settings** section, do the following:

   1. For **Name**, enter `reviews-sentiment-analysis`.

   1. For **Analysis type**, choose **Sentiment**.

   1. For **Language**, choose **English**.

   1. Leave the **Job encryption** setting as disabled.

1. In the **Input data** section, do the following:

   1. For **Data source**, choose **My documents**.

   1. For **S3 location**, choose **Browse S3** and then choose your bucket from the list of buckets.

   1. In your S3 bucket, for **Objects**, choose your `input` folder.

   1. In the `input` folder, choose the sample dataset `amazon-reviews.csv` and then choose **Choose**.

   1. For **Input format**, choose **One document per line**.

1. In the **Output data** section, do the following:

   1. For **S3 location**, choose **Browse S3** and then choose your bucket from the list of buckets.

   1. In your S3 bucket, for **Objects**, choose the `output` folder and then choose **Choose**.

   1. Leave **Encryption** turned off.

1. In the **Access permissions** section, do the following:

   1. For **IAM role**, choose **Create an IAM role**.

   1. For **Permissions to access**, choose **Input and Output S3 buckets**.

   1. For **Name suffix**, enter `comprehend-access-role`. This role provides access to your Amazon S3 bucket.

1. Choose **Create job**.

1. Repeat steps 1-10 to create an entities analysis job. Make the following changes:

   1. In **Job settings**, for **Name**, enter `reviews-entities-analysis`.

   1. In **Job settings**, for **Analysis type**, choose **Entities**.

   1. In **Access permissions**, choose **Use an existing IAM role**. For **Role name**, choose `AmazonComprehendServiceRole-comprehend-access-role` (this is the same role you created for the sentiment job).

### Analyze sentiments and entities (AWS CLI)
<a name="tutorial-reviews-analysis-jobs-cli"></a>

You use the `start-sentiment-detection-job` and the `start-entities-detection-job` commands to run sentiment and entities analysis jobs. After you run each command, the AWS CLI shows a JSON object with a `JobId` value that allows you to access details about the job, including the output S3 location.

**To run sentiment and entities analysis jobs (AWS CLI)**

1. Start a sentiment analysis job by running the following command in the AWS CLI. Replace `arn:aws:iam::123456789012:role/comprehend-access-role` with the IAM role ARN that you previously copied to a text editor. If your default AWS CLI Region differs from the Region in which you created your Amazon S3 bucket, include the `--region` parameter and replace `us-east-1` with the Region where your bucket resides.

   ```
   aws comprehend start-sentiment-detection-job 
   --input-data-config S3Uri=s3://amzn-s3-demo-bucket/input/
   --output-data-config S3Uri=s3://amzn-s3-demo-bucket/output/ 
   --data-access-role-arn arn:aws:iam::123456789012:role/comprehend-access-role
   --job-name reviews-sentiment-analysis
   --language-code en
   [--region us-east-1]
   ```

1. After you submit the job, copy the `JobId` and save it to a text editor. You will need the `JobId` to find the output files from the analysis job.

1. Start an entities analysis job by running the following command.

   ```
   aws comprehend start-entities-detection-job 
   --input-data-config S3Uri=s3://amzn-s3-demo-bucket/input/
   --output-data-config S3Uri=s3://amzn-s3-demo-bucket/output/ 
   --data-access-role-arn arn:aws:iam::123456789012:role/comprehend-access-role
   --job-name reviews-entities-analysis
   --language-code en
   [--region us-east-1]
   ```

1. After you submit the job, copy the `JobId` and save it to a text editor.

1. Check the status of your jobs. You can view the progress of a job by tracking its `JobId`.

   To track the progress of your sentiment analysis job, run the following command. Replace `sentiment-job-id` with the `JobId` that you copied after running your sentiment analysis.

   ```
   aws comprehend describe-sentiment-detection-job
   --job-id sentiment-job-id
   ```

   To track your entities analysis job, run the following command. Replace `entities-job-id` with the `JobId` that you copied after running your entities analysis.

   ```
   aws comprehend describe-entities-detection-job
   --job-id entities-job-id
   ```

   It takes several minutes for the `JobStatus` to show as `COMPLETED`.

You have completed sentiment and entities analysis jobs. Both of the jobs should be completed before you move on to the next step. It can take several minutes for the jobs to finish.

# Step 4: Preparing the Amazon Comprehend output for data visualization
<a name="tutorial-reviews-tables"></a>

To prepare the results of the sentiment and entities analysis jobs for creating data visualizations, you use AWS Glue and Amazon Athena. In this step, you extract the Amazon Comprehend results files. Then, you create an AWS Glue *crawler* that explores your data and automatically catalogs it in tables in the AWS Glue Data Catalog. After that, you access and transform these tables using Amazon Athena, a serverless and interactive query service. When you have finished this step, your Amazon Comprehend results are clean and ready for visualization.

For a PII entity detection job, the output file is plaintext, not a compressed archive. The output file name is the same as the input file, with `.out` appended at the end. You don't need the step of extracting the output file. Skip to [ Load the Data into an AWS Glue Data Catalog](#tutorial-reviews-tables-crawler).



**Topics**
+ [Prerequisites](#tutorial-reviews-tables-prereqs)
+ [Download the Output](#tutorial-reviews-tables-download)
+ [Extract the output files](#tutorial-reviews-tables-extract)
+ [Upload the extracted files](#tutorial-reviews-tables-upload)
+ [Load the data into an AWS Glue Data Catalog](#tutorial-reviews-tables-crawler)
+ [Prepare the data for analysis](#tutorial-reviews-tables-prep)

## Prerequisites
<a name="tutorial-reviews-tables-prereqs"></a>

Before you begin, complete [Step 3: Running analysis jobs on documents in Amazon S3](tutorial-reviews-analysis.md).

## Download the Output
<a name="tutorial-reviews-tables-download"></a>

The Amazon Comprehend uses Gzip compression to compress output files and save them as a tar archive. The simplest way to extract the output files is to download the `output.tar.gz` archives locally. 

In this step, you download the sentiment and entities output archives.

### Download the Output Files (Console)
<a name="tutorial-reviews-tables-download-console"></a>

To find the output files for each job, return to the analysis job in the Amazon Comprehend console. The analysis job provides the S3 location for the output, where you can download the output file.

**To download the output files (console)**

1. In the [Amazon Comprehend console](https://console.aws.amazon.com/comprehend/), in the navigation pane, return to **Analysis jobs**.

1. Choose your sentiment analysis job `reviews-sentiment-analysis`.

1. Under **Output**, choose the link displayed next to **Output data location**. This redirects you to the `output.tar.gz` archive in your S3 bucket.

1. In the **Overview** tab, choose **Download**.

1. On your computer, rename the archive as `sentiment-output.tar.gz`. Since all of the output files have the same name, this helps you keep track of the sentiment and entities files.

1. Repeat steps 1-4 to find and download the output from your `reviews-entities-analysis` job. On your computer, rename the archive as `entities-output.tar.gz`.

### Download the output files (AWS CLI)
<a name="tutorial-reviews-tables-download-cli"></a>

To find the output files for each job, use the `JobId` from the analysis job to find the output's S3 location. Then, use the `cp` command to download the output file to your computer.

**To download the output files (AWS CLI)**

1. To list details about your sentiment analysis job, run the following command. Replace `sentiment-job-id` with the sentiment `JobId` that you saved.

   ```
   aws comprehend describe-sentiment-detection-job --job-id sentiment-job-id
   ```

   If you lost track of your `JobId`, you can run the following command to list all of your sentiment jobs and filter for your job by name.

   ```
   aws comprehend list-sentiment-detection-jobs 
   --filter JobName="reviews-sentiment-analysis"
   ```

1. In the `OutputDataConfig` object, find the `S3Uri` value. The `S3Uri` value should be similar to the following format: `s3://amzn-s3-demo-bucket/.../output/output.tar.gz`. Copy this value to a text editor.

1. To download the sentiment output archive to your local directory, run the following command. Replace the S3 bucket path with the `S3Uri` you copied in the previous step. Replace `path/` with the folder path to your local directory. The name `sentiment-output.tar.gz` replaces the original archive name to help you keep track of the sentiment and entities files.

   ```
   aws s3 cp s3://amzn-s3-demo-bucket/.../output/output.tar.gz 
   path/sentiment-output.tar.gz
   ```

1. To list details about your entities analysis job, run the following command.

   ```
   aws comprehend describe-entities-detection-job
   --job-id entities-job-id
   ```

   If you don't know your `JobId`, run the following command to list all of your entities jobs and filter for your job by name.

   ```
   aws comprehend list-entities-detection-jobs
   --filter JobName="reviews-entities-analysis"
   ```

1. From the `OutputDataConfig` object in your entities job description, copy the `S3Uri` value.

1. To download the entities output archive to your local directory, run the following command. Replace the S3 bucket path with the `S3Uri` you copied in the previous step. Replace `path/` with the folder path to your local directory. The name `entities-output.tar.gz` replaces the original archive name.

   ```
   aws s3 cp s3://amzn-s3-demo-bucket/.../output/output.tar.gz 
   path/entities-output.tar.gz
   ```

## Extract the output files
<a name="tutorial-reviews-tables-extract"></a>

Before you can access the Amazon Comprehend results, unpack the sentiment and entities archives. You can use either your local file system or a terminal to unpack the archives. 

### Extract the output files (GUI file system)
<a name="tutorial-reviews-tables-extract-gui"></a>

If you use macOS, double-click the archive in your GUI file system to extract the output file from the archive.

If you use Windows, you can use a third-party tool such as 7-Zip to extract the output files in your GUI file system. In Windows, you must perform two steps to access the output file in the archive. First decompress the archive, and then extract the archive.

Rename the sentiment file as `sentiment-output` and the entities file as `entities-output` to distinguish between the output files.

### Extract the output files (terminal)
<a name="tutorial-reviews-tables-extract-terminal"></a>

If you use Linux or macOS, you can use your standard terminal. If you use Windows, you must have access to a Unix-style environment, such as Cygwin, to run tar commands.

To extract the sentiment output file from the sentiment archive, run the following command in your local terminal.

```
tar -xvf sentiment-output.tar.gz --transform 's,^,sentiment-,'
```

Note that the `--transform` parameter adds the prefix `sentiment-` to the output file inside of the archive, renaming the file as `sentiment-output`. This allows you to distinguish between the sentiment and entities output files and prevent overwriting.

To extract the entities output file from the entities archive, run the following command in your local terminal.

```
tar -xvf entities-output.tar.gz --transform 's,^,entities-,'
```

The `--transform` parameter adds the prefix `entities-` to the output file name.

**Tip**  
To save storage costs in Amazon S3, you can compress the files again with Gzip before uploading them. It's important to decompress and unpack the original archives because AWS Glue can’t automatically read data from a tar archive. However, AWS Glue can read from files in Gzip format.

## Upload the extracted files
<a name="tutorial-reviews-tables-upload"></a>

After extracting the files, upload them to your bucket. You must store the sentiment and entities output files in separate folders in order for AWS Glue to read the data properly. In your bucket, create a folder for the extracted sentiment results and a second folder for the extracted entities results. You can create folders either with the Amazon S3 console or the AWS CLI. 

### Upload the extracted files to Amazon S3 (console)
<a name="tutorial-reviews-tables-upload-console"></a>

In your S3 bucket, create one folder for the extracted sentiment results file and one folder for the entities results file. Then, upload the extracted results files to their respective folders.

**To upload the extracted files to Amazon S3 (console)**

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In **Buckets**, choose your bucket and then choose **Create folder**.

1. For the new folder name, enter `sentiment-results` and choose **Save**. This folder will contain the extracted sentiment output file.

1. In your bucket's **Overview** tab, from the list of bucket contents, choose the new folder `sentiment-results`. Choose **Upload**.

1. Choose **Add files**, choose the `sentiment-output` file from your local computer, and then choose **Next**.

1. Leave the options for **Manage users**, **Access for other AWS account**, and **Manage public permissions** as the defaults. Choose **Next**.

1. For **Storage class**, choose **Standard**. Leave the options for **Encryption**, **Metadata**, and **Tag** as the defaults. Choose **Next**.

1. Review the upload options and then choose **Upload**.

1. Repeat steps 1-8 to create a folder called `entities-results`, and upload the `entities-output` file to it.

### Upload the extracted files to Amazon S3 (AWS CLI)
<a name="tutorial-reviews-tables-upload-cli"></a>

You can create a folder in your S3 bucket while uploading a file with the `cp` command. 

**To upload the extracted files to Amazon S3 (AWS CLI)**

1. Create a sentiment folder and upload your sentiment file to it by running the following command. Replace `path/` with the local path to your extracted sentiment output file.

   ```
   aws s3 cp path/sentiment-output s3://amzn-s3-demo-bucket/sentiment-results/
   ```

1. Create an entities output folder and upload your entities file to it by running the following command. Replace `path/` with the local path to your extracted entities output file.

   ```
   aws s3 cp path/entities-output s3://amzn-s3-demo-bucket/entities-results/
   ```

## Load the data into an AWS Glue Data Catalog
<a name="tutorial-reviews-tables-crawler"></a>

To get the results into a database, you can use an AWS Glue *crawler*. An AWS Glue *crawler* scans files and discovers the schema of the data. It then arranges the data in tables in an AWS Glue Data Catalog (a serverless database). You can create a crawler with the AWS Glue console or the AWS CLI.

### Load the data into an AWS Glue Data Catalog (console)
<a name="tutorial-reviews-tables-crawler-console"></a>

Create an AWS Glue crawler that scans your `sentiment-results` and `entities-results` folders separately. A new IAM role for AWS Glue gives the crawler permission to access your S3 bucket. You create this IAM role while setting up the crawler.

**To load the data into an AWS Glue Data Catalog (console)**

1. Ensure that you're in a Region which supports AWS Glue. If you're in another Region, in the navigation bar, choose a supported Region from the **Region selector**. For a list of Regions that support AWS Glue, see the [Region Table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) in the *Global Infrastructure Guide*.

1. Open the AWS Glue console at [https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue/).

1. In the navigation pane, choose **Crawlers** and then choose **Add crawler**.

1. For **Crawler name**, enter `comprehend-analysis-crawler` and then choose **Next**.

1. For **Crawler source type**, choose **Data stores** and then choose **Next**.

1. For **Add a data store**, do the following:

   1. For **Choose a data store**, choose **S3**.

   1. Leave **Connection** blank.

   1. For **Crawl data in**, choose **Specified path in my account**.

   1. For **Include path**, enter the full S3 path of the sentiment output folder: `s3://amzn-s3-demo-bucket/sentiment-results`.

   1. Choose **Next**.

1. For **Add another data store**, choose **Yes** and then choose **Next**. Repeat Step 6, but enter the full S3 path of the entities output folder: `s3://amzn-s3-demo-bucket/entities-results`.

1. For **Add another data store**, choose **No** and then choose **Next**.

1. For **Choose an IAM role**, do the following:

   1. Choose **Create an IAM role**.

   1. For **IAM role**, enter `glue-access-role` and then choose **Next**.

1. For **Create a schedule for this crawler**, choose **Run on demand** and choose **Next**.

1. For **Configure the crawler's output**, do the following:

   1. For **Database**, choose **Add database**.

   1. For **Database name**, enter `comprehend-results`. This database will store your Amazon Comprehend output tables.

   1. Leave the other options on their default settings and choose **Next**.

1. Review the crawler information and then choose **Finish**.

1. In the Glue console, in **Crawlers**, choose `comprehend-analysis-crawler` and choose **Run crawler**. It can take a few minutes for the crawler to finish.

### Load the data into an AWS Glue Data Catalog (AWS CLI)
<a name="tutorial-reviews-tables-crawler-cli"></a>

Create an IAM role for AWS Glue that provides permission to access your S3 bucket. Then, create a database in the AWS Glue Data Catalog. Finally, create and run a crawler that loads your data into tables in the database.

**To load the data into an AWS Glue Data Catalog (AWS CLI)**

1. To create an IAM role for AWS Glue, do the following:

   1. Save the following trust policy as a JSON document called `glue-trust-policy.json` on your computer.

------
#### [ JSON ]

****  

      ```
      {
        "Version":"2012-10-17",		 	 	 
        "Statement": [
          {
            "Effect": "Allow",
            "Principal": {
              "Service": "glue.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
          }
        ]
      }
      ```

------

   1. To create an IAM role, run the following command. Replace `path/` with your local computer's path to the JSON document.

      ```
      aws iam create-role --role-name glue-access-role
      --assume-role-policy-document file://path/glue-trust-policy.json
      ```

   1. When the AWS CLI lists the Amazon Resource Number (ARN) for the new role, copy and save it to a text editor.

   1. Save the following IAM policy as a JSON document called `glue-access-policy.json` on your computer. The policy grants AWS Glue permission to crawl your results folders.

------
#### [ JSON ]

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "s3:GetObject",
                      "s3:PutObject"
                  ],
                  "Resource": [
                      "arn:aws:s3:::amzn-s3-demo-bucket/sentiment-results*",
                      "arn:aws:s3:::amzn-s3-demo-bucket/entities-results*"
                  ]
              }
          ]
      }
      ```

------

   1. To create the IAM policy, run the following command. Replace `path/` with your local computer's path to the JSON document.

      ```
      aws iam create-policy --policy-name glue-access-policy
      --policy-document file://path/glue-access-policy.json
      ```

   1. When the AWS CLI lists the access policy's ARN, copy and save it to a text editor.

   1. Attach the new policy to the IAM role by running the following command. Replace `policy-arn` with the IAM policy ARN you copied in the previous step.

      ```
      aws iam attach-role-policy --policy-arn policy-arn
      --role-name glue-access-role
      ```

   1. Attach the AWS managed policy `AWSGlueServiceRole` to your IAM role by running the following command.

      ```
      aws iam attach-role-policy --policy-arn
      arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole
      --role-name glue-access-role
      ```

1. Create an AWS Glue database by running the following command.

   ```
   aws glue create-database 
   --database-input Name="comprehend-results"
   ```

1. Create a new AWS Glue crawler by running the following command. Replace `glue-iam-role-arn` with the ARN of your AWS Glue IAM role.

   ```
   aws glue create-crawler 
   --name comprehend-analysis-crawler
   --role glue-iam-role-arn 
   --targets S3Targets=[
   {Path="s3://amzn-s3-demo-bucket/sentiment-results"},
   {Path="s3://amzn-s3-demo-bucket/entities-results"}] 
   --database-name comprehend-results
   ```

1. Start the crawler by running the following command.

   ```
   aws glue start-crawler --name comprehend-analysis-crawler
   ```

   It can take a few minutes for the crawler to finish.

## Prepare the data for analysis
<a name="tutorial-reviews-tables-prep"></a>

Now you have a database populated with the Amazon Comprehend results. However, the results are nested. To unnest them, you run a few SQL statements in Amazon Athena. Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. Athena is serverless, so there is no infrastructure to manage and it has a pay-per-query pricing model. In this step, you create new tables of cleaned data that you can use for analysis and visualization. You use the Athena console to prepare the data.

**To prepare the data**

1. Open the Athena console at [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home).

1. In the query editor, choose **Settings**, then choose **Manage**.

1. For **Location of query results**, enter `s3://amzn-s3-demo-bucket/query-results/`. This creates a new folder called `query-results` in your bucket that stores the output of the Amazon Athena queries you run. Choose **Save**.

1. In the query editor, choose **Editor**.

1. For **Database**, choose the AWS Glue database `comprehend-results` that you created.

1. In the **Tables** section, you should have two tables called `sentiment_results` and `entities_results`. Preview the tables to make sure that the crawler loaded the data. In each table’s options (the three dots next to the table name), choose **Preview table**. A short query runs automatically. Check the **Results** pane to ensure that the tables contain data.
**Tip**  
If the tables don’t have any data, try checking the folders in your S3 bucket. Make sure that there is one folder for entities results and one folder for sentiment results. Then, try running a new AWS Glue crawler.

1. To unnest the `sentiment_results` table, enter the following query in the **Query editor** and choose **Run**.

   ```
   CREATE TABLE sentiment_results_final AS
   SELECT file, line, sentiment,
   sentimentscore.mixed AS mixed,
   sentimentscore.negative AS negative,
   sentimentscore.neutral AS neutral,
   sentimentscore.positive AS positive
   FROM sentiment_results
   ```

1. To begin unnesting the entities table, enter the following query in the **Query editor** and choose **Run**.

   ```
   CREATE TABLE entities_results_1 AS
   SELECT file, line, nested FROM entities_results
   CROSS JOIN UNNEST(entities) as t(nested)
   ```

1. To finish unnesting the entities table, enter the following query in the **Query editor** and choose **Run query**.

   ```
   CREATE TABLE entities_results_final AS
   SELECT file, line,
   nested.beginoffset AS beginoffset,
   nested.endoffset AS endoffset,
   nested.score AS score,
   nested.text AS entity,
   nested.type AS category
   FROM entities_results_1
   ```

Your `sentiment_results_final` table should look like the following, with columns named **file**, **line**, **sentiment**, **mixed**, **negative**, **neutral**, and **positive**. The table should have one value per cell. The **sentiment** column describes the most likely overall sentiment of a particular review. The **mixed**, **negative**, **neutral**, and **positive** columns give scores for each type of sentiment.

![\[Screenshot of the sentiment output table in Athena.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-sentiment-table.png)


Your `entities_results_final` table should look like the following, with columns named **file**, **line**, **beginoffset**, **endoffset**, **score**, **entity**, and **category**. The table should have one value per cell. The **score** column indicates Amazon Comprehend's confidence in the **entity** it detected. The **category** indicates what kind of entity Comprehend detected.

![\[Console display of the entities output table in Athena.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-entities-table.png)


Now that you have the Amazon Comprehend results loaded into tables, you can visualize and extract meaningful insights from the data.

# Step 5: Visualizing Amazon Comprehend output in Quick
<a name="tutorial-reviews-visualize"></a>

After storing the Amazon Comprehend results in tables, you can connect to and visualize the data with Quick. Quick is an AWS managed business intelligence (BI) tool for visualizing data. Quick makes it easy to connect to your data source and create powerful visuals. In this step, you connect Quick to your data, create visualizations that extract insights from the data, and publish a dashboard of visualizations.

**Topics**
+ [Prerequisites](#tutorial-reviews-visualize-prereqs)
+ [Give Quick access](#tutorial-reviews-visualize-access)
+ [Import the datasets](#tutorial-reviews-visualize-import)
+ [Create a sentiment visualization](#tutorial-reviews-visualize-sentiment)
+ [Create an entities visualization](#tutorial-reviews-visualize-entities)
+ [Publish a dashboard](#tutorial-reviews-visualize-dashboard)
+ [Clean up](#tutorial-reviews-visualize-clean)

## Prerequisites
<a name="tutorial-reviews-visualize-prereqs"></a>

Before you begin, complete [Step 4: Preparing the Amazon Comprehend output for data visualization](tutorial-reviews-tables.md).

## Give Quick access
<a name="tutorial-reviews-visualize-access"></a>

To import the data, Quick requires access to your Amazon Simple Storage Service (Amazon S3) bucket and Amazon Athena tables. To give Quick access to your data, you must be signed in as a QuickSight administrator and have access to edit the resource permissions. If you are unable to complete the following steps, review the IAM prerequisites from the overview page [Tutorial: Analyzing insights from customer reviews with Amazon Comprehend](tutorial-reviews.md).

**To give Quick access to your data**

1. Open the [Quick console](https://quicksight.aws.amazon.com/sn/start).

1. If this is the first time you have used Quick, the console prompts you to create a new administrator user by providing an email address. For **Email address**, enter the same email address as your AWS account. Choose **Continue**.

1. After signing in, choose your profile name in the navigation bar and choose **Manage QuickSight**. You must be signed in as an administrator to view the **Manage QuickSight** option.

1. Choose **Security and permissions**.

1. For **QuickSight access to AWS services**, choose **Add or remove**.

1. Choose **Amazon S3**.

1. From **Select Amazon S3 buckets**, choose your S3 bucket for both **S3 Bucket** and **Write permissions for Athena Workgroup**.

1. Choose **Finish**.

1. Choose **Update**.

## Import the datasets
<a name="tutorial-reviews-visualize-import"></a>

Before creating visualizations, you must add the sentiment and entities datasets to Quick. You do this with the Quick console. You import your unnested sentiment and unnested entities tables from Amazon Athena.

**To import your datasets**

1. Open the [Quick console](https://quicksight.aws.amazon.com/sn/start).

1. In the navigation bar, in **Datasets**, choose **New dataset**.

1. For **Create a Data Set**, choose **Athena**.

1. For **Data source name**, enter `reviews-sentiment-analysis` and choose **Create data source**.

1. For **Database**, choose the database `comprehend-results`.

1. For **Tables**, choose the sentiment table `sentiment_results_final` and then choose **Select**.

1. Choose **Import to SPICE for quicker analytics** and choose **Visualize**. SPICE is QuickSight's in-memory calculation engine that provides faster analyses than direct querying when creating visualizations.

1. Return to the Quick console and choose **Datasets**. Repeat steps 1-7 to create an entities dataset, but make the following changes:

   1. For **Data source name**, enter `reviews-entities-analysis`.

   1. For **Tables**, choose the entities table `entities_results_final`.

## Create a sentiment visualization
<a name="tutorial-reviews-visualize-sentiment"></a>

Now that you can access your data in Quick, you can begin creating visualizations. You create a pie chart with the Amazon Comprehend sentiment data. The pie chart shows what proportion of the reviews are positive, neutral, mixed, and negative.

**To visualize sentiment data**

1. In the Quick console, choose **Analyses** and then choose **New analysis**.

1. From **Your Data Sets**, choose the sentiment dataset `sentiment_results_final` and then choose **Create analysis**.

1. In the visual editor, in **Fields list**, choose **sentiment**.
**Note**  
The values in the **Fields list** depend on the column names you used to create the tables in Amazon Athena. If you changed the provided column names in the SQL queries, the **Fields list** names will be different than the names used in these visualization examples.

1. For **Visual types**, choose **Pie chart**.

A pie chart similar to the following with positive, neutral, mixed, and negative sections is displayed. To see the count and percentage of a section, hover over it. 

![\[Console display of sentiment pie chart with sections positive, negative, neutral, and mixed.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-pie.png)


## Create an entities visualization
<a name="tutorial-reviews-visualize-entities"></a>

Now create a second visualization with the entities dataset. You create a tree map of the distinct entities in the data. Each block in the tree map represents an entity, and the size of the block correlates to the number of times that the entity appears in the dataset.

**To visualize entities data**

1. In the **Visualize** control pane, next to **Data set**, choose the **Add, edit, replace, and remove data sets** icon.

1. Choose **Add data set**.

1. For **Choose data set to add**, choose your entities dataset `entities_results_final` from the list of datasets and choose **Select**.

1. In the **Visualize** control pane, choose the **Data set** drop down menu and choose the entities dataset `entities_results_final`.

1. In **Fields list**, choose **entity**.

1. For **Visual types**, choose **Tree map**.

A tree map similar to the following is displayed next to your pie chart. To see the count of a specific entity, hover over a block.

![\[Console display of a tree map with blocks for each unique entity.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-tree.png)


## Publish a dashboard
<a name="tutorial-reviews-visualize-dashboard"></a>

After creating the visualizations, you can publish them as a dashboard. You can perform various tasks with a dashboard, such as sharing it with users in your AWS account, saving it as a PDF, or emailing it as a report (limited to the Enterprise edition of Quick). In this step, you publish the visualizations as a dashboard in your account.

**To publish your dashboard**

1. In the navigation bar, choose **Share**.

1. Choose **Publish dashboard**.

1. Choose **Publish new dashboard as** and enter the name `comprehend-analysis-reviews` for the dashboard.

1. Choose **Publish dashboard**.

1. Close the **Share dashboard with users** pane by choosing the close button in the upper-right corner.

1. In the Quick console, in the navigation pane, choose **Dashboards**. A thumbnail of your new dashboard `comprehend-analysis-reviews` should appear under **Dashboards**. Choose the dashboard to view it.

You now have a dashboard with sentiment and entities visualizations that looks similar to the following example.

![\[Console display of a QuickSight dashboard with a pie chart and a tree map.\]](http://docs.aws.amazon.com/comprehend/latest/dg/images/tutorial-reviews-dashboard.png)


**Tip**  
 If you want to edit the visualizations in your dashboard, return to **Analyses** and edit the visualization that you want to update. Then, publish the dashboard again either as a new dashboard or as a replacement of the existing dashboard. 

## Clean up
<a name="tutorial-reviews-visualize-clean"></a>

After completing this tutorial, you might want to clean up any AWS resources you no longer want to use. Active AWS resources can continue to incur charges in your account.

The following actions can help prevent incurring ongoing charges:
+ Cancel your Quick subscription. Quick is a monthly subscription service. To cancel your subscription, see [Canceling your subscription](https://docs.aws.amazon.com/quicksight/latest/user/closing-account.html) in the *Quick User Guide*.
+ Delete your Amazon S3 bucket. Amazon S3 charges you for storage. To clean up your Amazon S3 resources, delete your bucket. For information about deleting a bucket, see [How do I delete an S3 Bucket?](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/delete-bucket.html) in the *Amazon Simple Storage Service User Guide*. Make sure that you save all of your important files before deleting your bucket.
+ Clear your AWS Glue Data Catalog. The AWS Glue Data Catalog charges you monthly for storage. You can delete your databases to prevent incurring ongoing charges. For information about managing your AWS Glue Data Catalog databases, see [Working with databases on the AWS Glue console](https://docs.aws.amazon.com/glue/latest/dg/console-databases.html) in the *AWS Glue Developer Guide*. Make sure that you export your data before clearing any databases or tables.