One of the exciting aspects of machine learning is how the boundaries are getting moved out all the time. It’s even more exciting if you can get a taste of new technology without having to go through a lot of hassle. Since hearing about the BERT (Bidirectional Encoder Representations from Transformers) language representation model, I’ve wanted to get a chance to exercise it. BERT struck me as an idea that was both elegant and practical. Thanks to this text sentiment classifier you can get a taste of the power of BERT from a standing start in a couple of hours.
After reviewing the text sentiment classifier article, I followed the associated github readme which led me flawlessly through the steps to get the model set up:
- Set up Docker — I have a brand new Windows 10 system, so I spent a good portion of the overall end-to-end time getting Docker going. It took a couple of restarts and toggling Hyper-V off and on to get Docker to work. It wasn’t too irritating but it didn’t do anything to dispel my impression of Docker being a diva on Windows.
- Deploy the model: run this command (e.g. in Powershell in Windows) to run the docker image and start the model serving API:
$ docker run -it -p 5000:5000 codait/max-text-sentiment-classifier
3. Load the model in a browser:
That’s it! Now you’re ready to score some text. To do so, you simply have to enter the text that you want to score in the payload field, with each sample surrounded by double quotes and separated by commas, and click on Execute:
The results show up in the response body field:
You can see for these two randomly chosen examples (from the Amazon video review dataset available here) that the model detects the sentiment accurately.
Other than having to fiddle a bit to get Docker going, the only other hitch I encountered was the need to finesse the sample text a bit in Excel to remove embedded double quotes and line feeds.
If you want to exercise this text sentiment classifier on larger set of samples, I’ve prepared a subset of the Amazon video reviews that you can score with the model. The CSV file contains sample text that is ready to go, along with the positive and negative scores the model produced for each.
Thanks to the text sentiment classifier described in this article, I was able to get a taste of the power of BERT from a standing start in little over two hours. It’s great to be able to exploit a state-of-the are language model with so little hassle.