Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Query Classification on Steroids with BERT

“Machine learning can help you understand and predict intent in ways that simply aren’t possible manually. It can also help you find missed or unexpected connections between business goals and the habits of your key customer segments.”

  • Be the first to comment

Query Classification on Steroids with BERT

  1. 1. Query Classification on Steroids with BERT Hamlet Batista @hamletbatista
  2. 2. https://bit.ly/2UVebc1
  3. 3. https://bit.ly/2UVebc1
  4. 4. https://bit.ly/2UVebc1
  5. 5. “Machine learning can help you understand and predict intent in ways that simply aren’t possible manually. It can also help you find missed or unexpected connections between business goals and the habits of your key customer segments.” https://bit.ly/2UVebc1
  6. 6. Agenda • We will build a sophisticated deep learning model that can parse not just intent but also specific actions like the ones you give to Google Assistant, Siri and Alexa. • We will access the predictive model using a simple custom function in Google Sheets. • We will review the concepts that make this possible. • I will share resources you can use to learn more.
  7. 7. Our Toolkit https://colab.research.google.com/ We will type our commands in a Google Colab notebook.
  8. 8. Our Toolkit https://uber.github.io/ludwig/ Ludwig will help us build our deep learning model without writing code.
  9. 9. Our Toolkit https://github.com/howl-anderson/ATIS_dataset We will train our model using the ATIS dataset.
  10. 10. Our Toolkit https://ngrok.com/ Ngrok will help us expose the service URL inside our notebook.
  11. 11. Our Toolkit https://developers.google.com/apps-script We will code our Google Sheets function using Apps Script.
  12. 12. Setting up the notebook Downloading all required packages
  13. 13. Our Empty Notebook https://bit.ly/39Fkm9r
  14. 14. Installing Tensorflow %tensorflow_version 1.x !pip install tensorflow- gpu==1.15.2 import tensorflow as tf; print(tf.__version__)
  15. 15. !pip install ludwig !pip install ludwig[serve] Installing Ludwig
  16. 16. https://www.kaggle.com/siddhadev/atis-dataset-clean/home
  17. 17. Connect Google Drive from google.colab import drive drive.mount("/bert") %cd '/bert/My Drive/Writing/Query Classification on Steroids with BERT'
  18. 18. !wget https://bin.equinox.io/ c/4VmDzA7iaHb/ngrok- stable-linux-amd64.zip && unzip ngrok-stable- linux-amd64.zip Installing Ngrok
  19. 19. Preparing the training data Setting up the Ludwig configuration file
  20. 20. Creating model_definition. yaml https://gist.github.com/hamletbatista/b523424bb854372288b b2de325291a13
  21. 21. Building the predictive model Running Ludwig with our configuration file
  22. 22. !ludwig experiment --data_csv atis.train.csv -- model_definition_file model_definition.yaml Running Ludwig
  23. 23. Test the predictive model Running Ludwig serve
  24. 24. Python code snippet to test the model import pandas as pd test_df = pd.read_csv("atis.test.csv", index_col=0) model = LudwigModel.load("results/experiment_r un/model") predictions = model.predict(test_df) test_df.reset_index().join(predictions)[["to kens", "intent_predictions", "slots_predictions"]]
  25. 25. Serving the predictive model Running Ludwig serve
  26. 26. %%bash --bg nohup ludwig serve -m results/experiment_run /model > debug.log 2>&1 !tail debug.log Running Ludwig serve
  27. 27. !curl http://0.0.0.0:8000/pre dict -X POST -F 'tokens=BOS give me a flight from baltimore to newark EOS' Testing the service
  28. 28. %%bash --bg ./ngrok http 8000 2> ngrok.log !tail ngrok.log Running Ngrok
  29. 29. !curl -s http://localhost:4040/a pi/tunnels | python3 -c "import sys, json; print(json.load(sys.stdi n)['tunnels'][0]['public_ url'])" Extracting the Ngrok public URL
  30. 30. !curl https://e769db6e.ngro k.io/predict -X POST -F 'tokens=BOS explain meal codes sd d EOS' Testing the public service
  31. 31. Our journey so far 1.We built a travel specific intent prediction model 2.We can access the model using a temporary public URL 3.We need to access the URL from Apps Script and Google Sheets
  32. 32. Accessing the predictive model from Apps Script Creating a Google Sheets Custom Function
  33. 33. Creating fetchPrediction() https://gist.github.com/hamletbatista/fb7eae2e846ee8c43fff5 a433df2c672
  34. 34. Test fetchPre diction()
  35. 35. Testing in Google Sheets Calling our custom function fetchPrediction
  36. 36. Testing in Google Sheets
  37. 37. Testing in Google Sheets
  38. 38. Where is BERT?
  39. 39. Creating a BERT model_definition. yaml https://gist.github.com/hamletbatista/4d8e6d881b47c1d6b8d a7ce2cc494579
  40. 40. BERT performs worse!
  41. 41. Resources to learn more
  42. 42. Python and deep learning resources 1. https://www.searchenginejournal.c om/author/hamlet-batista/ 1. Automated Intent Classification Using Deep Learning in Google Sheets 2. Automated Intent Classification Using Deep Learning 3. Automated Intent Classification Using Deep Learning (Part 2) 2. https://www.jcchouinard.com/pyth on-for-seo/ 1. Python for SEO: Complete Guide (in 5 Chapters) 3. https://moz.com/blog/intro-to- python 1. Intro to Python - Whiteboard Friday
  43. 43. Thank You! @hamletbatista www.ranksense.com/free-tools/ www.linkedin.com/in/ hamletbatista/

×