RapidMiner

RapidMiner

How to Build a Dictionary Based Sentiment Model in RapidMiner

by RMStaff on ‎01-23-2017 07:02 AM - edited on ‎01-23-2017 10:13 AM by Community Manager

When you want to extract a sentiment from a text you usually have three options to go

  1. Use a prelearned model like the sentiment tools from Aylien and Rosette
  2. Use a supervised learning method on annotated texts to built your own sentiment scorer
  3. Use a predefined dictionary where each word has a weight

Every method has it's pros and cons. In this post we will focus on #3 and built a model. For english language you can use Wordnet, which has it's own extension. For german you can use SentiWS

This post describes a generic way to implement a custom dictionary based scoring.

 

In this example we assume, that you have a dictionary with two coloums:

 

Word        Weight

good 1.0 bad -1.5

 

 

Where a negative Weight means a negative sentiment. From this table we would like to built a scoring function like this:

 

score = 1.0 * good - 1.5 * bad

As we can see, this is a simple linear equation. We can use simple linear regression archive our results. To do so we need to prepare the table. First of all we need to invert all weights - this can be done using a Generate Attributes operator.

 

The next step is to bring the table into a form like this

good    bad
1.0        0
0            -1.5

This is in pinciple a task for the Pivot operator. We combine this with a GenerateID operator to get a unique group key and with a Rename by Replacing to get the correct naming conventions. A Replace Missing Values operator allows us to replace all missing values with zeros.

 

 

 

 The next step is to generate a label attribute. For this task we use a Generate Attributes and a Set Role operator. The resulting example set looks like this.

On this example set we learn a Vector Linear Regression to get a model with our desired equation.

 

 

This model can be used on texts. These texts can be transformed into the right shape using Process Documents (from Data), Tokenize and Transform Cases. An example is shown in the attached process.