This workflow demonstrates how to do sentiment analysis by fine-tuning Google's BERT network.
The idea is straight forward: A small classification MLP is applied on top of BERT which is downloaded from TensorFlow Hub.
The full network is then trained end-to-end on the task at hand.
After 1 epoch of training, the network should already have more than 85% accuracy on the test set.
Once training is completed, the "Visualize Before vs After" component shows the difference between BERT embeddings before and after training. You should see that the training introduced a much clearer separation between the classes. The view also allows to interactively play with different classification thresholds.
The dataset used here consists of the first 10000 reviews in the IMDB Movie Reviews dataset (http://ai.stanford.edu/~amaas/data/sentiment/) from "Learning Word Vectors for Sentiment Analysis" by Maas et al.
If you want to train a better model, we recommend to download the full dataset and train on it instead of the subset that comes with the workflow.
Additional Notes:
The red flow variable connections are used to enforce a sequential execution of nodes that make use of TensorFlow in order to prevent memory issues (especially if you are using a GPU).
If you wish to track your training progress, you can go to File->Preferences->KNIME->KNIME GUI and set the console log level to Info. Then you can monitor the status of the training in the console view (typically at the bottom right of the KNIME workbench).
Required KNIME extensions:
- KNIME Python Integration
- KNIME Deep Learning - Keras Integration
- KNIME Deep Learning - TensorFlow 2 Integration
- KNIME Statistics Nodes (Labs)
- KNIME Machine Learning Interpretability Extension
Required Python packages (need to be available in your TensorFlow 2 Python environment):
- tensorflow_hub
- bert-for-tf2
To use this workflow in KNIME, download it from the below URL and open it in KNIME:
Download WorkflowDeploy, schedule, execute, and monitor your KNIME workflows locally, in the cloud or on-premises – with our brand new NodePit Runner.
Try NodePit Runner!Do you have feedback, questions, comments about NodePit, want to support this platform, or want your own nodes or workflows listed here as well? Do you think, the search results could be improved or something is missing? Then please get in touch! Alternatively, you can send us an email to mail@nodepit.com.
Please note that this is only about NodePit. We do not provide general support for KNIME — please use the KNIME forums instead.