Production and Deployment of Machine Learning Models – III

Architecture Framework implemented to carry out an end to end prediction.

In order to establish an out-and-out machine learning system, where we get the data, train our model and then deploy the model to serve customers we need a suitable designed architecture. We should straightway explore few important design architectures.

We will touch upon all the structures and elaborate on the one on which, I worked. But first I wish to intuitively explain the operation.

Assuming that in general, people now have developed a fair understanding of model building process. And I am assuming that we have trained and tested our model and it turned out to be Model (M). This is the model that we will persist.

What do you mean by model persistence?

Model persistence means saving your model to a disk.

In simple terms model persistence means saving your model to a disk.

Technical definition: Model persistence is the ability to save and load the machine learning model. It is desirable to have a way to persist the model for future use without having to retrain.

Pickle and Joblib are the terms you will hear quite often during model persistence.

You can call your model a persistent python object. You can store this file into a hard disk or a solid state drive.

Model is saved on the disk at this point. Next step is to deploy the model.

What deployment means in simple terms is how your model interacts with the rest of the systems that are in place in a company or an organization’s architecture sounds vague! Hold on…

The Big Green circle is system architecture that the company has put in place. The two dark grey circle represents objects in that architecture. These objects can be individual boxes running different services and one particular box is where our model is stored depicted in the red.

Nothing does a better job of engaging people in the subject than an example.

Today, you are bored with those irritating cafeteria conversations (they are always about who is doing what and left versus right and god! People do have an opinion, frankly I am quite blasé about mostly everything). You come back home resting on your comfy chair by the bed, minutes later, you decide to watch a movie. You open a browser and type NETFLIX. As it opens with movie that you wanted to watch, you will see a recommendation of 5-6 more movies similar to that, at the bottom. The page has many things apart from recommendation of your movie.

I cannot use the actual Netflix page to illustrate the example. But I will try my best to give you enough insights that it will all start making sense to you.

You opened your browser and typed Netflix address. When Netflix opens with the movie of your choice ,the page has other details too (it has a join and a subscribe, it has another menu on the sidebar and a few more options . Here is what happens when you clicked on the website, website was connected to its server on which a lot of services were running which contributed to the page. The server will be connected to a database for one type of service, join and subscribe will be executed through different services, similarly the similar movies that you will get at the bottom will be executed through ML service box which is connected to the server. All these services are running simultaneously to give you the results.

In the picture above, you can consider a star or a triangle as different services and also similar movies at the bottom of the page, though ML service running on the system. There are many parts of a page, for each part, it will call a different service and fetch the data. The web server will pull the data from various services and collate it to give a page. And in that there will be one such service of ML, in our example it is the service which recommends similar movies (recommendation system).

This service is running on a different box like other services, it will not be on the actual server. It will be in the system where model “M” is running. The server calls the similar movies service from the box. It will send a request to this service(to the box where it is located consider blue box in the diagram) and the service would respond back with similar movies to occupy particular space on the page. This is more like service oriented architecture.

Design Approaches

This is one way, we deploy our model. The model is running on one box, and we push the request with data (the data we named as featurized data, discussed earlier) to the box and it will respond with an outcome (it could be recommendation of similar products, movies, predicting prices etc.). If both the server; the server that sends requests and ML server that gives output agree on the format of the data (format is critical to the process).

This is what happens, the intention was to give you an intuition and I will elaborate on the parts later.

The method I discussed is a Web Api method. In this method the Model is trained and persisted offline and then uploaded into web application that can give a real time predictions of similar movies when details about the a given movie is posted by a client to a rest Api. This is one type of architecture it needs more details but for the moment it is important to understand the idea.

One way is where you train your model offline, then as a request, for example client will upload a csv file of movies with the input details and then wait for some time for an email or a message telling them to check the website for results. This application would perform the batch prediction with an asynchronous task queue and those results would be saved to a shared database which could be then accessed by a web application to display the results.

You can also create your own example, try taking amazon page that page has so many services running from orders detail buttons to product details to people who bought this have also bought these, and try to frame the idea of deployment around it, I am sure you will be able to understand. Please give some valuable feedback in the comments so that I can improve. Thank you.

Leave a comment