Devreal

Monitoring AI with AI

Event: Scale by the Bay

Scale By The Bay 2018: Stepan Pushkarev, Monitoring AI with AI

Recording: Scale By The Bay 2018: Stepan Pushkarev, Monitoring AI with AI

you hope you enjoyed your lunch yeah I apologize for - buzz words in the title of this talk but this actually makes sense I will explain why if you remember Industrial Revolution when machines helped us to build better machines then our like digital revolution web revolution then when our computer programs helped us to build better ProGear computer programs and the same analogy here that ok we're building AI and actually we started using like machine learning methods techniques to help us building better AI you might you probably like aware about some automated feature engineering efforts about meta learning and other cool stuff and today in particular I want to focus on monitoring aspects monitoring of machine learning models after they have been deployed in production yeah very short credits to this talk we the stock is based on the our open source efforts and this is the team which is which contributes main contributors to this to this project the hydrosphere IO so let's jump straight to the detail so what once the machine learning model has been built and it it is deployed to production what may what might be wrong there so these are just a very brief list of the possible reasons possible failures that may happen in production and you are probably aware about that so the main thing is like discrepancy between training data and and production data and other stuff that is listed here and one of the like best practices or recipes for providing observability and reliability of learning models in production is to use data contracts data contracts means like fraud above contracts that describe the inputs and outputs of your models of the or you will solidify the basically the contracting space of the o of machine learning models and you will be automatically building validating all the messages that is to be sent to the model in in online in real time in production the data profiling I will data profiling concept drift monitoring it's probably the like similar terms I will explain in details in this prayer in this presentation this the like talking in more details and I will skip the other two like smart subsampling in their active free training because the the talkest for 20 minutes just a little bit theory behind this so the the model has been trained on original data set imagine your model has been trained on an original data set and the you've trained a classifier that can classify between orange circles and green squares that's great this is like the concept that your model has been learned and actually that blank space here besides the the orange circles and green squares is a blind blank space that your morale has never seen before and this is why I call it uncertain see just because we are not sure how the what is the real world outside of this boundaries what may what may happen in this boundaries so there might be a gradient edge cases between two classes we have learned so far there might be a new concept in production so we we might discover and you type of traffic traffic signal for example that we have never seen before and we should we should monitor our traffic to discover those new concepts the user behavior the existing behavioural the world behavior is being changed over time and the concept might might be drifted so then given given that so the let's recall how the data science and machine learning process starts and what's what's the common workflow on a very high level so the data scientist makes some assumptions based on the results of data exploration basically engineers features and he makes like those assumptions and once the model has been pushed to production what if and only if the format and statistical properties of production data are the same as in research I think that's obvious for everyone everybody and the whole framework framework is clear so that means that in production we have to continuously do a data profiling and verification comparing it with the data profile of P our training data sets let's let's take a look how the how the servable and jeolban model might look like so it's not just a binary like what about file saved like 10 if you're familiar with tensorflow it's not it's not just a yeah a pro Tabo model with k if it's unsafe to the to the disk it's much more it's wrapped with all the infrastructure stuff and one piece I want to pay your attention to is that rep cube that deplorable and servable model has to be packaged with with training data statistics that might be like min max range and other statistical properties of the training data and some more like derivatives like quantiles and Odeon coders that represents a statistical snapshot of the multi-dimensional data sets so it it guarantees us a immutable deployment of our machine learning models because the machine learning model is tightly connected to the data that is that it has been trained with and moreover those once we version this like servable model the training data sets are also have to be versioned in this way so it's just a side note but let's let's see I I want to show you just just interrupt with slides and just want to show you how we basically design the this deployment component and how we package the the training data stats into the that servable model to be monitored and to be validated with later so we have so this is can you see it well okay so we let's let's see what's here this is a like basically a father when we have the model the model is being like just a by a simple Python model in this SRC SRC file and how we describe these like how do we describe the deployment mode for this is like serving llamo here and those are contracts don't pay much attention on this but I wanted to highlight this thing so it's it's a reference to the like training CSV so the training data that it comes with with the model itself to be packaged and deployed you know in immutable way there and once we like at HS upload we package it all together and send to the serving serving cluster and during this process you see the data profile computing is started with something so what with what we what we do would take this training data set and we'll start calculating all kind of statistics on this like min max quantiles and whatever and also we calculate such things like auto-encoders for example that represent the more powerful statistical snapshot of the multidimensional data it takes some time yeah it's finished just for the sake of this and the training data itself I will just show you it's just for the sake of this presentations just a a CSV file with feature vectors it's like 112 feature vectors of the curl of the of the profile of the client profile and once it's deployed so yeah on it so this this this new version has been just uploaded and deployed I will just we have the data profile here that has been calculated so what happened under the hood the these like common statistic quantile statistics and the descriptive statistics has been built and the histograms that's cool we know something about our training data what happens next in a in a like in production we we can similarly we can right now we can simulate extending a prediction request to this model and see how those prediction requests aesthetics were statistically different from the training data we have seen so far I've done that I've done that before the my presentation has started and today but it just pointed to the another model version we have here and yeah we gather some we gather some statistics here but and we apply some statistical checks like kolmogorov-smirnov test and so on and what we do is was I just picked up the different model version that has been you see we have some insights that there is a training data and there is production data distribute the distribution has been changed and we like we can make a decision out of it we can make a like provide an insight or alert to the machine learning engineer okay if something is going wrong you might be like pure maybe upstream by upstream pipeline has failed and start sending you like zeros instead of fire and instead of expect that data you to be used for the predictions this is cool this is this is already like step ahead towards more observable machine learning models in production but let's move further so this is a very basic first first step that we can we can do this is the same so imagine we have like 100 features as an input and every feature generates 20 per profile metrics to be watched and it means like 2,000 points to track on every input request so it's it's kind of impossible to to sit and watch those those metrics and see and figure out okay my my mean value of a particular feature number 97 has been changed and what does it mean it means nothing from him yeah so too much data to track we can squeeze this this like pipe points to track means using some well-known advanced statistical like methods like kolmogorov-smirnov test as I mentioned quantiles plot or PCA or principal component analytics so this is this this will give us a more holistic view of what's going on without like digging into every particular feature measure every particular feature and its statistics so but this is not like this is like one layer ahead then the next challenge so if we imagine we have trained and we have trained the image classification model and once it has been trained on a monkeys with black faces and what would happen in with our system if in production we will all of the sudden have will be both start receiving monkeys with red faces how can we map this this like fact into the the concept I have just described with that nuke with an with that plot because like the image is mall it has a like the 300 on 303 multi-dimensional vector when we start talking about the outliers detection and the analytics of the image data and in the anomaly detection in general so the first the first model that we have in mind is the auto encoder often auto-encoders classical autoencoders they have encoder that basically engineers features for you and decoder that tries to reconstruct the original image from those those features or intermediate representation and basically a reconstruction role means the level of anomaly of new of new image so if we trained our auto encoder on our training data and then score this in parallel with the main model we can have a kind of insight what's what's what what kind of anomaly we might we have in production this is good but the challenges we have just like red or false or true flag that it might be an anomaly we don't have we can't estimate a probability distribution of this intermediate intermediate representation so this is we can't we can't we can't dig deeper into the root cause analysis here there are another methods you can yeah there are other methods like Gans you probably seen we can use Gans as well for this concept drift detection and basically if you remember Ganz can distinguish between fake and real images in a you know like in a classical and canonical scenario in this case with Train Ganz to learn this and certain space so we this like black curve is it's something that again is aware about and if our prediction hits into this black curve we can say okay this is something like drifted words so the same you know to say we can use like discriminator and output of the discriminator might be like drift or drift or fake data or good data also don't have any explicit insights on actual probability distribution of this of this latent space I will just skip through others but okay but there is there are other many many methods are currently in the bleeding edge research like variational autoencoders when we can apply a certain concentrate on our training algorithm and all learn this latent space space probability distribution so we can probably figure out what's what's going on inside this these features mask it or encourage that for density estimation and possible votes gibbet and like globe bidirectional gains at the end of the day very simple all those methods try to build a histogram of your like histogram of your training data and histogram of your trail of your production data and you can like figure out what's the difference yeah and we we've been using those like combination of those methods to build to do the promising promising area it's in a proof-of-concept mode at this moment I would show you a video but I don't have a like a real real-time demo so what we've done so far so we've trained our original single-shot detector model on a Berkeley data set so with it trained to be ready to recognize traffic lights pedestrians cars from Berkeley and then we have deployed this model in a little bit different urban area and and and then deployed our like monitoring models in parallel to to analyze okay what's is there any difference in the in this like new urban area from the original Berkeley data set we have seen so far yeah and the traffic lights here so the you see we can like understand the that this particular traffic light is hard to we have never seen this traffic light this type of traffic lights before and we can convert it into actionable metric that or alert to be used for for future root cause analysis here and if we if you will dig deeper into the into the real why this like traffic lights are so hard to the to be recognized this like green errors are hard to be reconstructed so you see the like it's it's it is being reckoned reconstructed into the like a circle in this case yeah mostly in store in store so this the additional black green error section that has been added into the side of the that traffic light that caused pressure that it heated that uncertain blank space or of the model and yeah ability to detect it using other machine learning models that works like in offline not an offline works in a synchronously in parallel and analyzing this traffic is like a big deal for providing insights for for data scientists yeah and the future of course we can use we can add this it might be outlier it might be a new concept it might be something like some these scenarios might be different we can add those outliers to the next sample to the next retraining and relabeling workflow and train our models to be to be aware of this concept we have discovered in production so this is like the idea is to provide that hook in production and help us to like iterate further and yeah I think I'm done with the talk happy to have to take questions the intent not to provide the outlier to the model it provides the bit data the data set that has an outlier to the next retraining match so we can retrain our model to be aware of the of those outliers or it might be not an outlier so it's originally it's like a normally detection stuff but as I mentioned there might be like there is a new concept yeah so just it's not an outlier is this is something that we should work with we should not we could not usually when people talk about outliers we usually filter out loud outliers yeah just not not to be not to deal with them we don't need to we don't want to deal with outliers but here I would say today it's it's an outlier tomorrow it's a new it's a new cluster of your data that that you you have to be aware of the single number know with we don't have so we can from the statists from the statistical staff that I have like short yeah we can derive that just a difference between histograms and have just that one number for this one it's probably a combination of different metrics and and monitoring alerts so there we don't have a sir and one single number might not my name may not be explainable that's why we would like to okay of course we would like to have here for example and when we say okay it's a health it's we ideally at the on top of every model we have we have like red and green health state status but then we want to dig deeper into okay the root cause and so on and so on yeah and this one is the example of Gans and if I would would start sending out lives there did it will be all all red yeah every every metric we want to apply for this type for any every kind of model has its own like trash hold the trash colt might be learned automatically from the training data or it might be set up like manually if you if you have but if you have some insights of you have some like guess about the the training the the production data you have you you can expect for example yeah but you know it's there are you if we talk about statistical properties yeah you have twenty purposes mean max average and so on it's it's in you and if you have like it features it's impossible to manually curate all the all those metrics that's why we want to bike automate that stuff [Applause]