Icon

Group_​3_​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 document; 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 following 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 Evaluation- Use the Rule Engine node to extract the predictions- Convert the prediction and the true values into a string using the Number toString node- Use the Scorer node to evaluate the model Training and Predicting- Use the Keras Network Learner to train the network Suggested settings: Loss function: Binary Cross Entropy Epochs: 4 Batchsize: 32 Optimizer: Adam- Use the DL Network Executer to apply the network on the test set(Tip: Add output according to the output of the Keras network) Define Network- Define the structure of the network using the Keras Layer nodes- Suggested network structure Input Layer- Shape: max number of words per document; 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 following 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 Evaluation- Use the Rule Engine node to extract the predictions- Convert the prediction and the true values into a string using the Number toString node- Use the Scorer node to evaluate the model Training and Predicting- Use the Keras Network Learner to train the network Suggested settings: Loss function: Binary Cross Entropy Epochs: 4 Batchsize: 32 Optimizer: Adam- Use the DL Network Executer to apply the network on the test set(Tip: Add output according to the output of the Keras network)

Nodes

Extensions

Links