Icon

Solution_​Deep_​Learning

Sentiment Analysis

This workflow shows how to train a simple neural network for text classification, in this case sentiment analysis. The used network learns a 128 dimensional word embedding followed by an LSTM.

Define Network- Define the structure of the network using the Keras Layer nodes- Suggested network structure Input Layer- Shape: max number of words per documet; Data Type: Int32 Keras Embedding Layer - Input Dimension: Size of the reduced dictionary +2; Output Dimension: 128 Keras LSTM Layer - Units 128; Activation: Tanh; Dropout = 0.2; Recurrent Dropout =0.2; Keras Dense Layer - Units: 1; Activation Function: Sigmoid Reading and Preprocessing- Read the following datasets: Imdb.table Dictionary.table(Tip: Drag and drop the dataset from the KNIME Explorer to the Workflow Editor)- Use the Strings to Document node to create document objectsHint: Use the follwoing settings: Title Column = Empty string Full Text = Text Don't Activate "Use categories from column" - Truncate the documents using the "Truncate" wrapped metanode template upper import port: Table with Documents lower import port: Dictionary Define max number of words per document- Create a reduced dictionary using the "Reduce Dictionary" wrapped metanode template input port: Dictionary table- Use the Dict Replacer node to apply the reduced dictionary(Hint: Text is truncated using the values of equal length in the column Truncation instead of words)- Zero pad the documents unsing the "Zero Padding" wrapped metanode template- Create training and test data sets using the "Partitioning" wrapped metanode template Training and Predicting- Use the Keras Network Learner to train thenetwork Suggested settings: Loss function: Binary Cross Entropy Epochs: 4 Batchsize: 32 Optimizer: Adam- Use the DL Network Executer to apply thenetwork on the test set(Tip: Add output according to the output of theKeras network) Evaluation- Use the Rule Engine node to extract the predictions- Convert the prediction and the true values into a stringusing the Number to String node- Use the Scorer node to evaluate the model Node 2Apply DictionaryReadDictionary.tableimdb.tableShape: max number of words per documentsInput: # word in dictionary+2128 unitsActivation function:sigmoidtrain for 3 epochswith Adamprobability topredictionpredict testdata Strings To Document Dictionary Replacer Partitioning Table Reader Table Reader Keras Input Layer Reduce Dictionary Truncate Keras EmbeddingLayer Keras LSTM Layer Keras Dense Layer Keras NetworkLearner Rule Engine Scorer (JavaScript) Keras NetworkExecutor Zero Pad Number To String Define Network- Define the structure of the network using the Keras Layer nodes- Suggested network structure Input Layer- Shape: max number of words per documet; Data Type: Int32 Keras Embedding Layer - Input Dimension: Size of the reduced dictionary +2; Output Dimension: 128 Keras LSTM Layer - Units 128; Activation: Tanh; Dropout = 0.2; Recurrent Dropout =0.2; Keras Dense Layer - Units: 1; Activation Function: Sigmoid Reading and Preprocessing- Read the following datasets: Imdb.table Dictionary.table(Tip: Drag and drop the dataset from the KNIME Explorer to the Workflow Editor)- Use the Strings to Document node to create document objectsHint: Use the follwoing settings: Title Column = Empty string Full Text = Text Don't Activate "Use categories from column" - Truncate the documents using the "Truncate" wrapped metanode template upper import port: Table with Documents lower import port: Dictionary Define max number of words per document- Create a reduced dictionary using the "Reduce Dictionary" wrapped metanode template input port: Dictionary table- Use the Dict Replacer node to apply the reduced dictionary(Hint: Text is truncated using the values of equal length in the column Truncation instead of words)- Zero pad the documents unsing the "Zero Padding" wrapped metanode template- Create training and test data sets using the "Partitioning" wrapped metanode template Training and Predicting- Use the Keras Network Learner to train thenetwork Suggested settings: Loss function: Binary Cross Entropy Epochs: 4 Batchsize: 32 Optimizer: Adam- Use the DL Network Executer to apply thenetwork on the test set(Tip: Add output according to the output of theKeras network) Evaluation- Use the Rule Engine node to extract the predictions- Convert the prediction and the true values into a stringusing the Number to String node- Use the Scorer node to evaluate the model Node 2Apply DictionaryReadDictionary.tableimdb.tableShape: max number of words per documentsInput: # word in dictionary+2128 unitsActivation function:sigmoidtrain for 3 epochswith Adamprobability topredictionpredict testdata Strings To Document Dictionary Replacer Partitioning Table Reader Table Reader Keras Input Layer Reduce Dictionary Truncate Keras EmbeddingLayer Keras LSTM Layer Keras Dense Layer Keras NetworkLearner Rule Engine Scorer (JavaScript) Keras NetworkExecutor Zero Pad Number To String

Nodes

Extensions

Links