Deploying ML as self hosted apps
There are numerous studies on how to create a data pipeline - i.e get the data, clean the data, build a model, save the model, and score a model. With this first Linkedin blog, I'll attempt to encourage Data Scientists and Machine Learning engineers to think about creating solutions that could be thought of as a product. What it takes to take a trained model and deploy it as an app on your website - and provide a proof of concept, or the product itself. This could also be thought of as a Shiny alternative in Python. This question has been asked here, here and many other places, with this blog I want to start the conversation in this direction to see if it works for others.
Also, I started my career as a web developer and I understand the full stack of back-end and front-end development which is a combination of quite a few skills. f.x for front-end basics revolves around HTML/CSS/JS and for backend server-side development we have options to choose from Python, Ruby, Php. A better explanation here - https://www.learneroo.com/modules/3/nodes/571
End Result
Let's start with what you can achieve before you invest time in nuances of deployment - here are two demo apps I built recently where I revisited the deployment cycle after many years.
Many would have guessed, these are very similar apps - wrapped around a flask webserver and polished with a CSS theme.
Model
Let's start with a model, I will use my notes from clickbait detector app to get you started on a model and a scoring function. The scoring function looks like the screenshot below.
You can access the entire model building exercise here
V 0.1 - Hello Flask
Before we wrap our function as a web service, here is a gist for one-page flask setup. https://gist.github.com/shubhamkalra27/da267f1a39c495e58520aa27051536f0
Recommended by LinkedIn
If you are on this step - you are 5 minutes away from creating your own web-service.
V 0.5 - Adding custom functionality
If you have spent enough time with Python, this step is just a formality. Instead of calling the upper in the first file, you need to call your scoring function. This looks a lot like the output of my scoring function from the notebook
V 1.0 - Beautifying it
My go-to stylist is Bulma, a great HTML framework that allows for ready-made good looking components. The effort put in this step is directly proportional to your audience - If it is an internal team, the previous version is ok. If it is a Beta user, you might want to put on your design caps. Bootstrap is another famous framework for all things responsive.
V 1.1 - Final Steps, Creating a Web Application
Now for the final step - moving the app from the local machine to a public facing server. Here is a Reddit link to all available hosts with a freemium model - https://www.reddit.com/r/flask/comments/2321oc/easiest_and_fastest_way_to_host_flask_python/
I prefer pythonanywhere - there is no setup, and they create a hello world flask app for you without you every hitting the consoles. Once you have the app running, just replace the files with your own files through a web browser. You can get started here - https://help.pythonanywhere.com/pages/
More on the Clickbait idea can be found on my pages - https://shubhamkalra27.github.io/clickbait-detector/
Lately, I have been using these deployment skills at work to build proof of concepts, and get the model out to the business teams to get an early feedback etc. Our team also uses AWS lambda for creating a REST API, and Docker containers. I have set my mind on creating a part 2 and 3 to share those tricks too. Let me know your thoughts.
Great bog post on getting started with full stack machine learning development. I'll be using this as a resource to build my own hobby models. Look forward to the next steps as well!