Icon

Building Sentiment Predictor - Deep Learning

<p><strong>Building a Sentiment Analysis Predictor - Deep Learning using an RNN-LSTM</strong><br><br>This workflow uses a Kaggle Dataset, including 14K customer tweets towards six US airlines: https://www.kaggle.com/crowdflower/twitter-airline-sentiment. Contributors annotated the valence of the tweet into positive, negative and neutral. Once users are satisfied with the model evaluation, they should export 1) Dictionary, 2) Category to Number Model, 3) Trained Network for deployment in non-annotated data. <br><br>Reference: <br>F. Villaroel Ordenes &amp; R. Silipo, “Machine learning for marketing on the KNIME Hub: The development of a live repository for marketing applications”, Journal of Business Research 137(1):393-410, DOI: 10.1016/j.jbusres.2021.08.036.</p>

URL: Twitter US Airline Sentiment (dataset) https://www.kaggle.com/datasets/crowdflower/twitter-airline-sentiment

Annotations and comments
  • Building a Sentiment Analysis Predictor - Deep Learning using an RNN-LSTM This workflow uses a Kaggle Dataset, including 14K customer tweets towards six US airlines: https://www.kaggle.com/crowdflower/twitter-airline-sentiment. Contributors annotated the valence of the tweet into positive, negative and neutral. Once users are satisfied with the model evaluation, they should export: 1) Dictionary, 2) Category to Number Model, 3) Trained Network for deployment to classify non-annotated data.
  • 1. Define the Network Architecture The Keras Layer nodes define an LSTM based recurrent neural network. The network structure can be extended by adding more Keras Layer nodes.
  • 4. Train and Apply Network The Keras Network Learner node trains the defined network. In the configuration window you can define the input column(s), target column(s), the loss function, and the training parameters, e.g. number of epochs, batch size, and optimizer. The Keras Network Executor node applies the trained network to the input data. In the configuration window you can select the input column(s) and define the output by clicking on the "add output" button. In this worklflow the softmax output layer is defined as output. This means that the output are the probabilities for the three classes. Extra: The Conda Environment Propagation node ensures the existence of a Conda environment with all packages. Another option is to setup your Python integration to use a Conda environment with all packages as described here.
  • 5. Evaluate and Save Trained Network The metanode Extract Predictions uses the probabilities produced by the Keras Network Executor node and extracts the class with the highest probability.
  • 2. Read annotated dataset For this example, 10 rows of the original dataset are filtered out and kept for deployment.
  • 3. Manipulate and Encode Data The metanode performs an index encoding to encode each word with an index. This blog post describes different encoding options: https://www.knime.com/blog/text-encoding-a-review. In general, RNNs can handle sequences with different lengths. During training though, all sequences must have the same length. Therefore, the metanode adds zeros to the end of the sequences, so that all sequences have the same length. This approach is known as zero padding.
  • Kaggle Dataset N=14630 tweets from consumers about airlines
  • Encode each class with an index
  • Set up a conda environment: dl_sentiment_keras
  • Extract class index from column header
  • Extract column header for the class with the highest probility
  • Split on space
  • Create one input seqeunce per review
  • Apply dictionary
  • Softmax with 3 units Note: An appropriate output layer for a multiclass classification task is a softmax layer with as many units as classes.
  • Input: # word in dictionary Output: 128 units
  • Shape: ? Note: Using ? as input shape allows to handle different sequence lengths
  • Units for cell state: 256
  • Output: Softmax layer => Probability for the different classes
  • Loss function: Categorical Cross Entropy Epochs: 50
  • Save network
  • Save model
  • 80% training 20% testing
  • 74% Accuracy (approx)
  • Save dictionary

Nodes

Extensions

Links