Aws Comprehend — How it works

Introduction to analyze text services with AWS Comprehend.

I’ve been working with AWS for at least 2 years and I think that it has been an amazing journey, where I personally most enjoy the whole serverless environment, so I’m here to tell you a little bit of my experience.

In this post, we’ll take a closer look at some of the benefits of machine learning services, specifically AWS Comprehend, through a business case for the funniest and simplest understanding of how to build a useful solution along with other services of the same nature: Lambda, SNS and API Gateway.

We are going to create a small application that allows us to know the entities and sentiment from any text source, a tweet for example. So, we will first create an HTTP API with two endpoints (POST) called detectSentiment and detectEntities. We’ll directly pass the text in these request bodies and expect the respective analysis in the response.

Many folks in the community, and also in my team, prefer Serverless framework to manage “serverless” resources as code, which is a flexible and powerful tool for this purpose. I suggest finding more information on their official website and documentation.

Serverless Framework is open source software that builds, compiles, and packages code for serverless deployment, and then deploys the package to the cloud.

Amazon Comprehend provides natural language processing, topic modeling, and Custom Classification capabilities, enabling a broad range of applications that can analyze text.

Lambda is a computer service that lets you run code without provisioning or managing servers.

So, one of the first questions is how many languages Comprehend supports?

At the beginning, AWS Comprehend allowed six languages only: English, French, German, Italian, Portuguese, and Spanish. Nowadays there are six new languages as Chinese (Traditional), Chinese (Simplified), Korean, Hindi, Japanese, and Arabic.

I’ve worked with English and Spanish and both performance and results were very good: around 97% of processed conversations show excellent results in terms of understanding and classification.

We start writing a simple template declaring our Lambda functions, triggered when a POST HTTP event occurs. If you want to know more about this amazing technology you can visit this website:

Let’s create the functions detectSentiment and detectEntites using Node.js flavor. As you see, the names are referred to the two SDK Comprehend functions that we are using for this example.

Please follow the link for more information about how to use it and available programming languages:

This method allows us to inspect a batch of documents and returns an inference of the prevailing sentiments POSITIVE, NEUTRAL MIXED or NEGATIVE, in each one.

Here we use a method detectEntities that allows us to inspect the text of documents for named entities and returns information about them.

Let’s check how many entities and sentiments our methods can detect and analyze. You can try with many texts and languages (and let us know your results in the comments section) using a simple HTTP Client.

I was looking for several tweets in the account of Banks from Ecuador and I choose these. Let’s go to see how it work.

I have obtained very precise results for entities classification and sentiment scores into three categories (positive, neutral and negative). This results and very useful information to discover insights from your source texts and trigger some interesting actions based on metrics and analysis.

It is pretty easy to implement AWS Comprehend and make it available as a tool to the public. AWS serverless solutions bring good documentation for Node.js and other languages, allowing agile solutions development and testing. Also, you can explore in-depth and find some interesting features to attach new models for your analysis.

The Serverless Framework becomes an excellent ally to serverless development, allowing you to work with IaaC (Infrastructure as a Code) very easily. You can build APIs and their environment in record time, or trigger events from other AWS services, allowing you to perform a strong POC (Proof of Concept) and determine if your idea is really viable.

Collaboration: Erick Calle Castillo

Cloud Architect at Kushki — The best way to predict the future is to invent it