
We’ve all seen the rating systems on e-commerce sites such as Amazon. Whether based on stars or a point scale, such systems are an easy way for users to gauge the sentiment around a product. Many tech professionals are tasked with coding something similar for their own organizations, along with surveys and feedback platforms—and sometimes they run into issues around building out an accurate sentiment analysis.
Using Python and a few libraries, it’s surprisingly easy to build a sentiment analysis tool. You can use this to process internal reviews, survey answers, product feedback, and so on. Let’s walk through how you can create such an app.
Summary
What is Sentiment Analysis?
At its core, sentiment analysis involves using AI to determine the emotional tone of feedback, ideally bringing out nuances. On a trivial level, it might seem easy, especially in the context of product feedback and reviews. For example:
- I love this feature! This is obviously positive.
- It’s okay. Nothing great, but it works. This seems pretty neutral.
- This thing frustrated the daylights out of me! This is clearly negative.
But let’s look a bit more closely at that middle review. Is it neutral? The user seems like they could take or leave the product, but it’s definitely not bringing happiness to their life—and in the eyes of a marketing person or even CEO, that could be perceived as rather negative.
That’s where AI can help. AI excels in both interpreting what was said and digging out the deeper meaning.
In the case of your app that you’re building, maybe you want to go beyond just those three sentiment levels. What about outright rage at using your product? What if a review is sarcastic? Consider these two reviews:
- “I just loved this product! I’m taking it with me every day wherever I go. Seriously, this is a game changer for me.”
Versus:
- “I just LOVE this product. I’m going to take it with me every day wherever I go. I use it as a paperweight, which it seriously excels at. Who knew it had such hidden talents.”
In the early days of AI and reviews, it might have been difficult for a tool to distinguish the second from positive or negative. But today’s AI can easily detect sarcasm.
Try it yourself: Go to ChatGPT and put in the following:
- “Please tell me if this review is positive/neutral/negative and explain how you came to that conclusion: I just LOVE this product. I’m going to take it with me every day wherever I go. I use it as a paperweight, which it seriously excels at. Who knew it had such hidden talents.”
I fed the above into both ChatGPT and Google Gemini. ChatGPT’s “4o” model didn’t fall for it, starting its response with “This review is sarcastic, and its true sentiment is negative, despite sounding positive on the surface.”
Gemini, with it’s model “2.5 Flash” on the other hand, failed miserably, stating, “This review is positive”: It then gave a long-winded response, and even said, “Even though the user mentions using it as a "paperweight," which might seem unconventional for some products, the context of "seriously excels at" and "hidden talents" frames this usage in a highly favorable light, implying the product is so good it can even be repurposed successfully.”
But when we switched to Gemini’s “2.5 Pro” model, it got it right, easily detecting the sarcasm and pointing out: “The reviewer is using sarcasm to express disappointment.” Our conclusion? Test out such things with whatever GPT tool and model you prefer… but don’t be afraid to utilize another tool.
In any case, rapidly improving AI has made sentiment analysis even better, allowing a system to pick up on more nuances of user feedback.
When to Use Sentiment Analysis
When is sentiment analysis useful? Here are some places:
- Support tickets: Sentiment analysis is vital if users are reporting a huge problem.
- App reviews: As with any review, app reviews can make or break a product. Too many bad reviews can bring your product sales to a halt. Quickly analyzing sentiment and fixing the product (or issuing an explanation) can save a business.
- Third-party reviews: E-commerce apps depend on reviews of third-party products to help guide users.
- Internal feedback: Reading employee sentiment is absolutely crucial for everything from retention to planning company benefits.
- Social media mentions: Analyzing anything mentioned about your company online can help you respond to issues before they become crises.
Based on sentiment analysis, you can direct tech teams and other specialists throughout your organization to do everything from prioritize certain bugs to build new products.
Steps to Building the App
Here are the basic steps to building the app:
- Read user input. This can come in the form of reading the reviews right from your backend server’s database to using tools like Instagram’s or Amazon’s APIs.
- Analyze the sentiment. You have several options here, but the one you choose depends on how thorough you want to be (including detecting sarcasm as mentioned earlier). The issue here is that some AI models can be run locally on your own machines (likely with help from a GPU), and some models are simply too big and should be accessed through an API.
- Start with the API. This will help you build the first version of your app while connecting to an online API and model such as OpenAI’s APIs. After you’ve completed the project, you can try out some local models. Please realize that, given the potential decrease in computing power, your locally-run models might not be as adept at understanding the reviews, including potential sarcasm.
- Summarize the results. This can be vital, as this is the chance to break down the sentiment into a list of most common requests, both feature request and bug fix requests.
Working Remotely
As mentioned above, your best bet for starters is to start out working remotely. For this, you’ll send your reviews to an online service such as OpenAI’s API. You’ll need to decide whether to upload them all in a single batch, or to send them one by one.
If you want to gather up individual sentiment scores, you’ll likely want to send them up one by one. But if you’re just looking for an overview, you might send them all at once. (Make sure you don’t exceed the size of the API calls.)
This is where software development gets a little interesting: your app is pulling in a bunch of reviews and feedback, pushing them up to an API, and getting back results. You don’t need a lot of fancy algorithms, but you need to get a couple of things right:
- You need to provide the AI API with context. You need to state in detail what you’re hoping to get from it, as well as details about the item being reviewed. This means you’ll likely want to send up product information along with the reviews so the AI has a chance to figure out what the reviews are even about, and contextualize them appropriately.
- If you want additional information, such as potential feature requests and bug reports, be specific about that, as well. State it in your request, along with how you would like the data to be delivered. For example, do you want the AI to attempt to prioritize them, or do you want to? How many users should bring up a feature or bug for it to be included?
Working Locally
If you want to work locally instead of connecting to an API, you have options—but recognize that you will also likely have less access to deeper context and things like sarcasm detection; in addition, these local-based tools might struggle with advanced metrics like feature requests and bug fix requests.
But the benefit is that you can work locally, possibly faster, and potentially save a lot of money—provided you have a tolerance for ambiguity and outliers. For instance, is it okay if an occasional sarcastic response that’s a negative slips through as a positive? Here are two libraries you can use to build your app locally.
- VADER: This is a rule-based sentiment analysis that excels particularly with social media text (i.e., the kind of short blurbs people will typically post across their different social media platforms). It’s good at subtle comments but does struggle a bit with complex sentences, which might result in a false positive or false negative.
- TextBlob: This is an easy-to-use library built on top of other open-source libraries. It’s rather straightforward to use and great for basic sentiment analysis. However, like VADER, it’s limited in its contextual understanding.
Both of these libraries work locally, and can be an easy drop-in and provide basic sentiment analysis without the need for external libraries out on the broader web. But because of that, they’re also a bit more simplistic than what you might get with a full GPT.
In addition to the above, you have a few other options for working locally, but they require a bit more horsepower, including possible use of a GPU:
- Flair: This one is a good mix between working locally, since it downloads models from the web. But that’s the catch: Models can be huge, potentially several gigabytes, and they usually need a GPU. While Flair can technically run without a GPU, you’re going to see a severe drop in performance when running on a basic CPU.
- spaCy: This is a popular library for natural language processing, and while it’s not built specifically for sentiment analysis, it can be combined with a couple other libraries, in particular spaCyTextBlob and spacy-transformers. (spaCyTextBlog interacts with the TextBlog mentioned earlier, and spacy-transformers uses Hugging Face Transformers.) What’s particularly nice about these combinations is that they’re fast and efficient.
Conclusion
Sentiment analysis sounds like an advanced feature, but it’s certainly within reach. You don’t need many Python libraries to make it happen. Whether you’re analyzing user reviews, internal feedback, or social media mentions, building your own sentiment analysis app can help your app and products grow, as well as help provide direction for the development team.
And if you build your own app outside of a team—such as a personal app that gathers Amazon reviews—you could add it to your portfolio and snag some interest from hiring managers.