Positive or Negative Sentiment?

We have published a new version of our REST Service for Sentiment Analysis. The machine learning model predicts whether the sentiment of a text is positive or negative. The model can predict sentiment for English, German and French texts. In conjunction with our Language Detection Service, the language of a text can be determined prior to the sentiment analysis.

Language detection
Sentiment Analysis in conjunction with Language Detection.

The machine learning model was implemented with Keras and trained with 50’000 english, 50’000 french and 30’000 german movie reviews. The measured accuracy of the predictions is 81.82% for german and 84.1% for english and french. The model consists of an embedding layer as input, a hidden layer with 400 LSTM units and an output layer with 1 unit. The maximum length of an input text is 400 words. For the word embedding the pre-trained word vectors of FacebookResearch were used.

Several texts can be posted to the REST service at once for analysis. You can start the sentiment analysis service to access a language detection service. The service then first determines the language of the texts and then passes them on to the corresponding sentiment analysis model

Scope of Application

The model was trained with movie reviews in english, german and french language. We also tested the model at random with product reviews and reader comments in those languages. The results were generally promising (but need further investigation).

Example Query

Queries use the following JSON format (German example;  English and French use the identical format):

{
    "texts": [
        "Dieser Film ist vom Anfang bis am Ende spannend! Die Schauspieler sind wirklich gut!",
        "Dieser Film ist vom Anfang bis am Ende langweilig! Die Schauspieler sind mässig bis schlecht!"
    ]
}

The answer will look something like this:

{
    "predictions": [
        {
            "lang": "de",
            "sentiment": {
                "label": "positiv",
                "probability": 0.9192836880683899
            },
            "text": "Dieser Film ist vom Anfang bis am Ende spannend! Die Schauspieler sind wirklich gut!"
        },
        {
            "lang": "de",
            "sentiment": {
                "label": "negativ",
                "probability": 0.020672615617513657
            },
            "text": "Dieser Film ist vom Anfang bis am Ende langweilig! Die Schauspieler sind mässig bis schlecht!"
        }
    ],
    "success": true
}

A probability towards 0 means negative, one towards 1 means positive.

Installation and Usage

Refer to the documentation on GitHub for installation and more application examples of the software.

Download

Download the Software including Premium Support. You can also download the Software under the Apache 2.0 License on GitHub for free.

About the author: Thomas studied computer linguistics and philosophy and graduated with a PhD in computer science. He has worked as a consultant for natural language processing and application development for major Swiss banks. Thomas is founder of ipublia. He lives with his family in Zürich.

Leave a Reply