ChatGPT AI - Product Review Summary (Difficulty 4)
-
Introduction
AI models like ChatGPT can be used for much more than chat applications. For example, they can read, write and understand natural languages, so they can be used to build text-processing tools, such as text summarization. Today, we are surrounded by massive amounts of information — websites, books, blog posts — and reading everything is often impossible. A tool that can automatically generate a concise summary can save readers a lot of time.
In this tutorial, you’ll use ChatGPT to summarize product reviews. For example, a popular product on Amazon may have thousands of reviews in different languages. Since it’s not practical to read through them all, we’ll build a solution where ChatGPT reads the reviews and produces a summary for us.
As the tool runs, ChatGPT will continually refine the summary as it processes more reviews:
Step 1 - Start from a Template Project
Let’s begin by remixing the following starter project:play.creaticode.com/projects/ca4bbe666a1934bab795661b
This project already includes a table named “reviews” containing 100 reviews for a toy product. Each entry includes a star rating, subject and review details.
There are many ways to collect such review data, but that part is outside the scope of this tutorial. Here, we’ll focus on using ChatGPT to process and summarize the reviews.
Step 2 - Understand the Core Idea
Before we jump into coding, let’s break down the main challenge.We know ChatGPT can summarize any given text. The problem is that we can’t send a lot of reviews at once. For example, 1000 reviews averaging 20 words each would be 20,000 words total — far more than what ChatGPT can handle.
So, how do we make ChatGPT read all the reviews and still produce a single coherent summary?
Think of it like adding up 1000 numbers, but you can only add 2 numbers at a time. You’d add the first two, then add the result to the next number, and so on.
We’ll use the same strategy here:
- Get an initial summary of the first few reviews.
- Give ChatGPT a batch of new reviews along with the previous summary, and ask it to update the summary.
- Repeat this process until all reviews are processed.
This method is called incremental summarization — and we’re going to build it step by step.
Step 3 - Print the First Review
Let’s start small. Read the first review in the reviews table and print it out.We’ll ignore the star rating and just use the “subject” and “details” columns. Here’s how to store them in two variables, combine them, and print to the console:
Step 4 - Print the First 20 Reviews
Next, use a loop to read the first 20 rows of the reviews table, one by one. Start with an empty string in the reviews variable, then append each review to it:
Note that we include a “\n” after each review, so the next review will start on a new line. Here is what we get in the console panel:
Even with just 20 reviews, it’s already hard to read and find patterns. Let’s automate that.
Step 5 - Create a “get reviews” Block
Since we’ll be reading different sets of reviews many times, let’s turn this into a reusable block called get reviews.It should take two inputs: the first row number and the last row number, and store the result in the reviews variable:
Step 6 - Generate the Initial Summary
Now that we’ve collected 20 reviews, it’s time to generate the initial summary using ChatGPT. The prompt will start with "Summarize these product reviews: ", and then we will append the 20 reviews we have collected.
We’re using the waiting mode here for simplicity. You should get something like this printed:
Step 7 - Improve the Summary Format
The single long paragraph isn’t very readable. Let’s improve it by asking ChatGPT to return bullet points of pros and cons. Note this is a very concise prompt composed of a Task and an Instruction, based on the TIRE prompting method.
Now you’ll get something much easier to skim:
Step 8 - Reduce Duplicates
Now let’s tackle another common problem in the response: repetition. You may notice similar points like:- “Fragile and not made of sturdy plastic”
- “Not made as sturdy as old transformers”
We can try to ask ChatGPT to improve the answer like this:
Summarize these product reviews as bullet points with pros and cons. Skip similar points.
Still, you might get too many overlapping items:
It appears that ChatGPT is not well-trained in removing similar points. Can you find a clever way to solve this issue?
Better Fix: Limit the Number of Bullet Points
You can control this better by simply limiting the number of items:Summarize these product reviews as bullet points with the top 3 pros and cons.
Now the summary is cleaner and more focused:
Step 9 - Load the Next 20 Reviews
Let’s read the next 20 reviews and print them out:
They look like this in the console panel:
Step 10 - Update the Summary
Now we’ll use both the existing summary and the new reviews to create an updated summary.Your prompt will include:
- The current summary + the current summary
- The new batch of reviews + all the new reviews
- Instruction to update the summary
Here’s the structure:
Part 1:
Here is a summary of a product from some customer reviews:
Part 2:Here are some new customer reviews:
Part 3:Now please update the summary above based on the new customer reviews above. Use the same format of bullet points of the top 3 pros and cons.
And here’s the code to build and send this prompt by joining 5 variables into one prompt:Here is the updated summary we get, which is based on all 40 reviews:
Step 11 - Process All Reviews in Batches
Now loop through the remaining reviews. Use a variable called start row, and increment it by 20 each time (e.g., 21, 41, 61, 81). The end row is always start row plus 19 for each batch.
Step 12 - Show the Summary on Stage
Instead of printing the final summary to the console, display it in a textbox on the stage.Add the textbox at the start of your program and update its value with the summary:
Here is what we will get when we run the program:
Additional Challenges
Ready to extend the project? Try some of these ideas:- Filter by Category: Add a dropdown menu for users to choose a category (e.g., “ease of use”, “durability”, “appearance”). Summarize only reviews that match that category.
- Summarize Other Content: Apply this technique to summarize other sources — like school-wide survey responses, news articles, or even book chapters.
- Answer a Specific Question: Instead of creating a general summary, allow the user to input a custom question — such as “Is this toy suitable for 8-year-olds?” Then process all the reviews in batches and have ChatGPT generate an answer based on all the reviews.
-
info-creaticode