使用 Amazon Comprehend 对文本进行洞察分析

发布时间:2022 年 5 月 16 日
Amazon Comprehend
免费套餐
Olawale Olaleye
亚马逊云科技使用经验
100 - 初级
完成所需时间
10 分钟
前提条件

注册 / 登录 亚马逊云科技账户

所需费用

可通过 AWS 免费套餐试用

使用场景

机器学习

受众

开发人员

上次更新时间
2022 年 5 月 16 日
相关产品

在本分步教程中,您将学习如何使用 Amazon Comprehend 分析文本并获取洞察。

Amazon Comprehend 是一项自然语言处理 (NLP) 服务,它使用机器学习从文本中发现洞察和关系。Amazon Comprehend 利用机器学习帮助您发掘非结构化数据中的洞察和关系。该服务可识别文本的语言,提取关键短语、地点、人物、品牌或事件,了解文本的正负面程度,使用标记化和词性分析文本,并按主题自动组织文本文件集合。  

在本教程场景中,您正在计划一次旅行,希望找到有用的旅行书籍。您选择了一本书,现在想使用 Amazon Comprehend 处理一些评论,以了解其他客户是否认为这本书有价值。

在本教程中,您将学习如何:

  1. 登录 Amazon Comprehend 控制台
  2. 对三条客户评论运行内置文本分析
  3. 探索文本分析的洞察,包括情感、实体、关键短语、语言和语法
  4. 使用情感分析结果进行决策

您在此账户中创建的资源适用于 AWS 免费套餐。  

步骤 1:创建 AWS 账户

本教程需要您拥有 AWS 账户。您在此账户中创建的资源适用于 AWS 免费套餐。  

步骤 2:Amazon Comprehend 入门

在此步骤中,您将登录 Amazon Comprehend,并开始对书评进行实时分析。  

a. 在 AWS 管理控制台中登录 Amazon Comprehend

(或者,在 AWS 管理控制台中搜索 Comprehend,然后选择 Launch Amazon Comprehend(启动 Amazon Comprehend)。)

b. 在左侧导航栏中,选择 Real-time analysis(实时分析),然后向下滚动到 Input text(输入文本)。对于 Analysis type(分析类型),选择 Built-in(内置)。

借助 Amazon Comprehend 控制台,您可以分析多达 5,000 个字符的文档内容。结果将显示在控制台中,以便您查看分析。在本教程中,您将使用内置分析。要了解更多关于使用 Comprehend 端点进行自定义实时分析的信息,请参阅为自定义分类创建端点

在接下来的步骤中,您将使用 Amazon Comprehend Insights 分析这些书评的情感、语法等内容。情感分析的结果可帮助您确定这些客户是否认为这本书有价值。

评论 1:
“I just wanted to find some really cool new places such as Seattle in November.I’ve never visited before but no luck here.Some of these suggestions are just terrible… I had to laugh! Most suggestions were just your typical big cities, restaurants and bars.Nothing off the beaten path here.I don’t want to go these places for fun.Totally not worth getting this.”

评论 2:
“This was such a beautiful book.I wasn’t even planning any travel when I came across this and just started flipping through the pages.I really like the cover and all the large glossy photographs in this book.John Smith did a wonderful job with the photography.I’ve found a perfect home for this on my coffee table.I’m planning a trip to Paris and Barcelona soon and I know this will come in handy.In the meantime, it’s perfect for assisting this armchair traveler!”

评论 3:
“As a traveler, I really appreciated reading about these great places to visit.The author takes you all over the world.Even with all the free information online these days, I find I’m taking this book with me wherever I go and using it to discover hidden gems.”

步骤 3:使用 Amazon Comprehend Insights 分析文本

在此步骤中,您将使用 Amazon Comprehend Insights 分析第一条评论的正面、负面或混合情感、实体、关键短语、语言和语法检测。

a. 在 Input text(输入文本)框中,复制并粘贴 Review 1 中的文本,然后选择 Analyze(分析)。

“I just wanted to find some really cool new places such as Seattle in November.I’ve never visited before but no luck here.Some of these suggestions are just terrible… I had to laugh! Most suggestions were just your typical big cities, restaurants and bars.Nothing off the beaten path here.I don’t want to go these places for fun.Totally not worth getting this.” 

b. 在 Insights(洞察)框中,选择 Sentiment(情感)。

Sentiment(情感)选项卡显示文本的整体情感。情感可以评定为中性、正面、负面或混合。在这种情况下,每种情感都有一个置信度评级,由 Amazon Comprehend 提供某种情感占主导地位的估算值。有关更多信息,请参阅确定情感

对于这条评论,结果表明这是一条负面评论,正面或混合情感的得分较低。

c. 在 Insights(洞察)框中,选择 Entities(实体)。

Entities(实体)选项卡用不同颜色的文本表示不同的实体类型,如组织、地点、日期和人物。Results(结果)窗格显示有关文本的详细信息。每个条目显示实体、其类别以及 Amazon Comprehend 对此分析的置信度。如果要提取自定义实体,可以使用 Amazon Comprehend 自定义实体识别

您可以查看检测到的实体及其置信度评分。对于这条评论,西雅图被识别为一个具有置信度评分的地点,11 月被识别为一个具有置信度评分的日期。

d. 在 Insights(洞察)框中,选择 Key phrases(关键短语)。

Key phrases(关键短语)选项卡列出了 Amazon Comprehend 在输入文本中检测到的关键名词短语以及相关的置信度水平。在 Analyzed text(分析文本)框中,关键短语用下划线文本表示。Results(结果)部分列出了关键短语及其相应的置信度评分。

对于这条评论,您可以看到列出了多个关键短语。

e. 在 Insights(洞察)框中,选择 Language(语言)。

Language(语言)选项卡显示文本的主导语言以及置信度评级。Amazon Comprehend 可以识别 100 种语言。有关更多信息,请参阅检测主导语言

对于这条评论,您可以看到 Amazon Comprehend 以 0.99 的置信度检测到了英语。

f. 在 Insights(洞察)框中,选择 Syntax(语法)。

Syntax(语法)选项卡显示文本中每个元素的分解,以及其词性和相关的置信度评分。有关更多信息,请参阅分析语法

步骤 4:比较文本情感分析的结果

在此步骤中,您将重复步骤 3,分析第二条和第三条评论的正面、负面或混合情感。您可以根据结果决定是否购买这本书!还可以花点时间探索其他洞察,比如实体、关键短语、语言和语法检测。

a. 在 Input text(输入文本)框中,复制并粘贴 Review 2 中的文本,然后选择 Analyze(分析)。

“This was such a beautiful book.I wasn’t even planning any travel when I came across this and just started flipping through the pages.I really like the cover and all the large glossy photographs in this book.John Smith did a wonderful job with the photography.I’ve found a perfect home for this on my coffee table.I’m planning a trip to Paris and Barcelona soon and I know this will come in handy.In the meantime, it’s perfect for assisting this armchair traveler!”

b. 在 Insights(洞察)框中,选择 Sentiment(情感)。

您可以看到,第二条评论与第一条评论有很大不同。在这里,结果是正面的,这条评论没有负面或混合的结果。

探索这条评论的其他洞察,然后继续分析评论 3。

c. 在 Input text(输入文本)框中,复制并粘贴 Review 3 中的文本,然后选择 Analyze(分析)。

“As a traveler, I really appreciated reading about these great places to visit.The author takes you all over the world.Even with all the free information online these days, I find I’m taking this book with me wherever I go and using it to discover hidden gems.”

d. 在 Insights(洞察)框中,选择 Sentiment(情感)。

您可以看到,第三条评论与第二条非常相似。结果是正面的,这条评论没有负面或混合的结果。

在 3 条评论中,有 2 条结果是正面的。根据本教程中情感分析的结果,您可能想购买那本旅行指南!