Sentiment and Emotion Analysis API

What is Sentiment Analysis?

Sentiment analysis is the process of extracting a general sentiment from a block of text. Basically it's about determining whether the text is positive or negative.

For example, let's imagine our program finds the following Twit:

Look what's just come on the market in #ValThorens! A recently renovated, charming 6 bed duplex apartment in the heart of the resort with superb views!

This is a commercial Twit that clearly shows a positive sentiment.

The Natural Language Processing model in charge of sentiment analysis would return the main sentiment and its likelihood. Here we would get a positive sentiment with a high likelihood.

What is Emotion Analysis?

Emotion analysis is about detecting one or several emotions from a block of text: sadness, joy, love, anger, fear, surprise...

The Natural Language Processing model in charge of emotion analysis would return each emotion together with its likelihood.

Sentiment analysis

Why Use Sentiment/Emotion Analysis?

Sentiment and emotion analyses can be interesting in many situations. Let's give you a couple of examples.

Social Network Analysis

Imagine you're working in a marketing department that is regularly posting new content on social networks. You might want to automatically monitor the user reactions in order to quickly intervene in case of negative feedback.

Support

Some support requests might be more urgent than others, depending on how angry users are. Detecting the user's sentiment automatically can help support address critical tickets more quickly.

Public Relations

Gauging the sentiment of a couple of persons on the internet is easy, but understanding the global sentiment of thousands of persons is another thing. Automated sentiment analysis is the key solution here.

Product Launch

Right after launching a new product, it can be critical to react quickly in case of poor reception by customers, bloggers, journalists... Sentiment analysis can help in such situations.

Sentiment and Emotion Analyses with Transformers and Generative Models.

The Transformer, released by Google in 2017, is the corner stone architecture of many advanced AI models. Thanks to the Transformer, accuracy of AI models has improved dramatically. However this improvement comes at a cost: neural networks based on the Transformer are extremely computation intensive.

Hugging Face is a central repository regrouping many open-source Natural Language Processing Transformer-based models. Three of them, DistilBERT Base Uncased Finetuned SST-2, Distilbert Base Uncased Emotion, Prosus AI's Finbert, are perfectly suited for fast sentiment analysis. %}

For more advanced results, it is also possible to perform sentiment analysis with generative models like LLaMA 2, Dolphin, and ChatDolphin. These models give great results, even when no context is provided.

Sentiment/Emotion Analysis Inference API

Building an inference API for sentiment and emotion analyses is a necessary step as soon a you want to use sentiment/emotion analysis in production. But keep in mind that building such an API is not necessarily easy. First because you need to code the API (easy part) but also because you need to build a highly available, fast, and scalable infrastructure to serve your models behind the hood (hardest part). Machine learning models consume a lot of resources (memory, disk space, CPU, GPU...) which makes it hard to achieve high-availability and low latency at the same time.

Leveraging such an API is very interesting because it is completely decoupled from the rest of your stack (microservice architecture), so you can easily scale it independently and ensure high-availability of your models through redundancy. But an API is also the way to go in terms of language interoperability. Most machine learning frameworks are developed in Python, but it's likely that you want to access them from other languages like Javascript, Go, Ruby... In such situation, an API is a great solution.

NLP Cloud's Sentiment/Emotion Analysis API

NLP Cloud proposes a sentiment analysis API that gives you the opportunity to perform sentiment analysis and emotion analysis out of the box, based on DistilBERT Base Uncased Finetuned SST-2, Distilbert Base Uncased Emotion, Prosus AI's Finbert, LLaMA 2, Dolphin, and ChatDolphin, with excellent performances. The response time (latency) is very good for the DistilBERT and Finbert models and the accuracy of generative models on this task is very impressive. You can either use the pre-trained model or train your own model, or upload your own custom models!

For more details, see our documentation about sentiment analysis here. For advanced usage, see the text generation API endpoint here. And easily test sentiment analysis on our playground.

Testing sentiment/emotion analysis locally is one thing, but using it reliably in production is another thing. With NLP Cloud you can just do both!