Original Source Here
Companies that sell products or services online need to constantly monitor customer reviews left on their website after purchasing a product. The company’s marketing and customer service departments analyze these reviews to understand customer sentiment. For example, marketing could use this data to create campaigns targeting different customer segments. Customer service departments could use this data to spot customer dissatisfaction and take corrective action.
Traditionally, this data is collected via a batch process and sent to a data warehouse for storage, analysis, and reporting, and is made available to decision-makers after several hours, if not days. If this data can be analyzed immediately, it can provide opportunities for companies to react quickly to customer sentiment.
In this post, we describe an approach for analyzing the overall sentiment of customer feedback in near-real time (a few minutes). We also demonstrate how to understand the different sentiments associated with specific entities in the text (such as company, product, person, or brand) directly from the API.
Use cases for real-time sentiment analysis
Real-time sentiment analysis is very useful for companies interested in getting instant customer feedback on their products and services, such as:
- Retail or B2C companies selling various products or services
- Companies streaming online movies (OTT platforms), live concerts, or sports events
- Financial institutions
In general, any business that has customer touchpoints and needs to make real-time decisions can benefit from real-time feedback from customers.
Deploying a real-time approach to sentiment can be useful in the following use cases:
- Marketing departments can use the data to target customer segments better, or adjust their campaigns to specific customer segments.
- Customer service departments can reach out to dissatisfied customers immediately and try to resolve the problems, preventing customer churn.
- Positive or negative sentiment on a product can prove as a useful indicator of product demand in various locations. For example, for a fast-moving product, companies can use the real-time data to adjust their stock levels in warehouses, to avoid excess inventory or stockouts in specific regions.
It’s also useful to have a granular understanding of sentiment, as in the following use cases:
- A business can identify parts of the employee/customer experience that are enjoyable and parts that may be improved.
- Contact centers and customer service teams can analyze on-call transcriptions or chat logs to identify agent training effectiveness, and conversation details such as specific reactions from a customer and phrases or words that were used to elicit that response.
- Product owners and UI/UX developers can identify features of their product that users enjoy and parts that require improvement. This can support product roadmap discussions and prioritizations.
We present a solution that can help companies analyze customer sentiment (both full and targeted) in near-real time (usually in a few minutes) from reviews entered on their website. At its core, it relies on Amazon Comprehend to perform both full and targeted sentiment analysis.
The Amazon Comprehend sentiment API identifies the overall sentiment for a text document. As of October 2022, you can use targeted sentiment to identify the sentiment associated with specific entities mentioned in text documents. For example, in a restaurant review that says, “I loved the burger but the service was slow,” the targeted sentiment will identify positive sentiment for “burger” and negative sentiment for “service.”
For our use case, a large restaurant chain in North America wants to analyze reviews made by their customers on their website and via a mobile app. The restaurant wants to analyze their customers’ feedback on various items in the menu, the service provided at their branches, and the overall sentiment on their experience.
For example, a customer could write the following review: “The food at your restaurant located in New York was very good. The pasta was delicious. However, the service was very poor!” For this review, the location of the restaurant is New York. The overall sentiment is mixed—the sentiment for “food” and “pasta” is positive, but the sentiment for the service is negative.
The restaurant wants to analyze the reviews by customer profile, such as age and gender, to identify any trends across customer segments (this data could be captured by their web and mobile apps and sent to the backend system). Their customer service department wants to use this data to notify agents to follow up on the issue by creating a customer ticket in a downstream CRM system. Operations wants to understand which items are fast moving on a given day, so they can reduce the preparation time for those items.
Currently, all the analyses are delivered as reports by email via a batch process that takes 2–3 days. The restaurant’s IT department lacks sophisticated data analytics, streaming, or AI and machine learning (ML) capabilities to build such a solution.
The following architecture diagram illustrates the first steps of the workflow.
The entire solution can be hooked to the back of a customer website or a mobile app.
Amazon API Gateway exposes two endpoints:
- A customer endpoint where customer reviews are entered
- A service endpoint where a service department can look at any particular review and create a service ticket
The workflow includes the following steps:
- When a customer enters a review (for example, from the website), it’s sent to an API Gateway that is connected to an Amazon Simple Queue Service (Amazon SQS) queue. The queue acts as a buffer to store the reviews as they are entered.
- The SQS queue triggers an AWS Lambda function. If the message is not delivered to the Lambda function after a few retry attempts, it’s placed in the dead-letter queue for future inspection.
- The Lambda function invokes the AWS Step Functions state machine and passes the message from the queue.
The following diagram illustrates the Step Functions workflow.
Step Functions does the following steps in parallel.
- Step Functions analyzes the full sentiment of the message by invoking the detect_sentiment API from Amazon Comprehend.
- It invokes the following steps:
- It writes the results to an Amazon DynamoDB table.
- If the sentiment is negative or mixed, it performs the following actions:
- It sends a notification to Amazon Simple Notification Service (Amazon SNS), which is subscribed by one or more email addresses (such as the Director of Customer Service, Director of Marketing, and so on).
- It sends an event to Amazon EventBridge, which is passed on to another downstream systems to act on the review received. In the example, the EventBridge event is written to an Amazon CloudWatch log. In a real scenario, it could invoke a Lambda function to send the event to a downstream system inside or outside AWS (such as an inventory management system or scheduling system).
- It analyzes the targeted sentiment of the message by invoking the
detect_targeted_sentimentAPI from Amazon Comprehend.
- It writes the results to a DynamoDB table using the Map function (in parallel, one for each entity identified in the message).
The following diagram illustrates the workflow from Step Functions to downstream systems.
- The DynamoDB tables use Amazon DynamoDB Streams to perform change data capture (CDC). The data inserted into the tables is streamed via Amazon Kinesis Data Streams to Amazon Kinesis Data Firehose in near-real time (set to 60 seconds).
- Kinesis Data Firehose deposits the data into an Amazon Simple Storage Service (Amazon S3) bucket.
- Amazon QuickSight analyzes the data in the S3 bucket. The results are presented in various dashboards that can be viewed by sales, marketing, or customer service teams (internal users). QuickSight can also refresh the dashboard on a schedule (set to 60 minutes for this example).
The AWS CloudFormation templates to create the solution architecture are available on GitHub. Note that the templates don’t include the QuickSight dashboards, but provide instructions on how to create them in the README.md file. We provide some sample dashboards in the following section.
Dashboards are useful for marketing and customer service departments to visually analyze how their product or service is doing across key business metrics. In this section, we present some sample reports that were developed in QuickSight, using fictitious data for the restaurant. These reports are available to decision-makers in about 60 minutes (as per our refresh cycle). They can help answer questions like the following:
- How are customers perceiving the business as a whole?
- Are there any specific aspects of the service (such as time taken to deliver service, resolution provided on a customer complaint) that customers like or don’t like?
- How do customers like a specific newly introduced product (such as an item on the menu)? Are there any specific products that customers like or don’t like?
- Are there any observable patterns in customer sentiment across age groups, gender, or locations (such as what food items are popular in various locations today)?
The following figures show examples of full sentiment analysis.
The first graph is of the overall sentiment.
The next graph shows the sentiment across age groups.
The following graph shows sentiment across gender.
The final graph shows sentiment across restaurant locations.
The following figures show examples of targeted sentiment analysis.
The first graph shows sentiment by entity (service, restaurant, types of meal, and so on).
The following shows sentiment across age groups by entity.
The next graph shows sentiment across locations by entity.
The following screenshot is from a CRM ticketing system that could be used for more granular analysis of customer sentiment. For example, in our use case, we set up the customer service department to receive email notifications of negative sentiments. With the information from the email (the review ID of the customer sentiment), a service representative can drill down to more granular details of the sentiment.
This post described an architecture for real-time sentiment analysis using Amazon Comprehend and other AWS services. Our solution provides the following benefits:
- It’s delivered as a CloudFormation template with an API Gateway that can be deployed behind customer-facing apps or mobile apps
- You can build the solution using Amazon Comprehend, with no special knowledge of AI, ML, or natural language processing
- You can build reports using QuickSight with no special knowledge of SQL
- It can be completely serverless, which provides elastic scaling and consumes resources only when needed
Real-time sentiment analysis can be very useful for companies interested in getting instant customer feedback on their services. It can help the company’s marketing, sales, and customer service departments instantly review customer feedback and take corrective actions.
Use this solution in your company to detect and react to customer sentiments in near-real time.
To learn more about the key services described in this blog, visit the links below
About the Author
Varad G Varadarajan is a Senior Solutions Architect (SA) at Amazon Web Services, supporting customers in the US North East. Varad acts as a Trusted Advisor and Field CTO for Digital Native Businesses, helping them build innovative solutions at scale, using AWS. Varad’s areas of interest are IT Strategy Consulting, Architecture and Product Management. Outside of work, Varad enjoys creative writing, watching movies with family and friends, and traveling.
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot