Sentiment 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 NLP 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.

Why Use Sentiment Analysis?

Sentiment analysis 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.


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 Analysis with Hugging Face Transformers.

Hugging Face transformers is an amazing library that has been recently released. It is based on either PyTorch or TensorFlow, depending on the model you're using. Transformers have clearly helped deep learning NLP make great progress in terms of accuracy. However this accuracy improvement comes at a cost: transformers are extremely demanding in terms of resources.

Hugging Face is a central repository regrouping all the newest open-source NLP transformer-based models. One of them, DistilBERT's Base Uncased Finetuned SST-2 English is perfectly suited for sentiment analysis.

Sentiment Analysis API

Building an inference API for sentiment analysis is a necessary step as soon a you want to use sentiment 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 independantly 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 Analysis API

NLP Cloud proposes a sentiment analysis API that gives you the opportunity to perform sentiment analysis out of the box, based on Hugging Face transformers' DistilBERT's Base Uncased Finetuned SST-2 English model, with excellent performances. The response time (latency) is very good for this model.

For more details, see our documentation about sentiment analysis.

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

As for all our NLP models, you can use sentiment analysis for free, up to 3 API requests per minute.