6.14 Machine Learning development process | Full cycle of a machine learning project -[ML|Andrew Ng]
 So far, we've talked a lot about how to train a model and also talked a bit about how to get data for your machine learning application. But when I'm building a machine learning system, I find that training a model is just part of the puzzle. In this video, I'd like to share with you what I think of as the full cycle of a machine learning project. That is, when you're building a valuable machine learning system, what are the steps to think about and plan for? Let's take a look. Let me use speech recognition as an example to illustrate the full cycle of a machine learning project. The first step of a machine learning project is to scope the project. In other words, decide what is the project and what you want to work on. So for example, I once decided to work on speech recognition for voice search, that is to do web search using speaking to your mobile phone rather than typing into your mobile phone. So that's project scoping. After deciding what to work on, you have to collect data. So decide what data you need to train your machine learning system and go and do the work to get the audio and get the transcripts or the labels for your data set. So that's data collection. After you have your initial data collection, you can then start to train the model. And so here you would train a speech recognition system and carry out error analysis and iteratively improve your model. And it's not at all uncommon after you've started training the model for an error analysis or for a bias-variance analysis to tell you that you might want to go back to collect more data, maybe collect more data of everything or just collect more data of a specific type where your error analysis tells you you want to improve the performance of your learning algorithm. For example, once when working on speech, I realized that my model was doing politically poorly when there was car noise in the background. So if it sounded like someone was speaking in a car, my speech system performed poorly, decided to get more data, actually using data augmentation to get more speech data that sounds like it was a car in order to improve the performance of my learning algorithm. So you go around this loop a few times, train the model, carry error analysis, go back to collect more data, maybe do this for a while until eventually you think the model is good enough to then deploy in a production environment. And what that means is you make it available for users to use. And when you deploy a system, you want to also make sure that you continue to monitor the performance of the system and to maintain the system in case the performance gets worse, to bring its performance back up. Instead of just hosting your machine learning model on a server, I'll say a little bit more about why you need to maintain these machine learning systems on the next slide. But after this deployment, sometimes you realize that it's not working as well as you hoped and you go back to train the model to improve it again or even go back and get more data. In fact, if users and if you have permission to use data from your production deployment, sometimes that data from your working speech system can give you access to even more data with which to keep on improving the performance of your system. Now I think you have a sense of what scoping a project means and we've talked a bunch about collecting data and training models in discourse. But let me share with you a little bit more detail about what deploying in production might look like. After you've trained a high performing machine learning model, say a speech recognition model, a common way to deploy the model would be to take your machine learning model and implement it in a server, which I'm going to call an inference server, whose job it is to call your machine learning model, your trained model, in order to make predictions. Then if your team has implemented a mobile app, say a search application, then when the user talks to the mobile app, the mobile app can then make an API call to pass to your inference server the audio clip that was recorded and the inference service job is to apply the machine learning model to it and then return to it the prediction of your model, which in this case would be the text transcript of what was said. So this would be a common way of implementing an application that calls via an API an inference server that has your model repeatedly make predictions based on the input x. So this would be a common pattern where depending on the application that's implemented, you have an API call to give you learning algorithm the input x and your machine learning model would then output the prediction, say y hat. To implement this, some software engineering may be needed to write all the code that does all of these things. And depending on whether your application needs to serve just a few handful of users or millions of users, the amounts of software engineering needed can be quite different. So I've built software that serve just a handful of users on my laptop and I've also built software that serves hundreds of millions of users requiring significant data center resources. So depending on the scale of application needed software engineering may be needed to make sure that your inference server is able to make reliable and efficient predictions, hopefully at not too high a computational cost. Software engineering may be needed to manage scaling to a large number of users. You often want to log the data you're getting, both the inputs x as well as the predictions y hat, assuming that user privacy and consent allows you to store this data. And this data, if you can access to it, is also very useful for system monitoring. For example, I once built a speech recognition system on a certain data set that I had, but when there were new celebrities that suddenly became well known or elections caused new politicians to become elected, then people would search for these new names that were not in the training set and that my system did poorly on. And it was because we're monitoring the system, it allowed us to figure out when the data was shifting and the algorithm was becoming less accurate. And this allowed us to retrain the model and then to carry out a model update to replace the old model with a new one. So the deployment process can require some amount of software engineering. For some applications, if you're just running it on a laptop or on a one or two service, maybe not that much software engineering is needed. And depending on the team you're working on, it's possible that you build the machine learning model, but there could be a different team responsible for deploying it. But there is a growing field in machine learning called ML Ops, this stands for machine learning operations. And this refers to the practice of how to systematically build and deploy and maintain machine learning systems to do all of these things to make sure that your machine learning model is reliable, scales well, has good logs, is monitored, and that you have the opportunity to make updates to the model. As appropriate to keep it running well. For example, if you're deploying your system to millions of people, you may want to make sure you have a highly optimized implementation so that the compute costs of serving millions of people is not too expensive. So in this and the last class, we spent a lot of time talking about how to train a machine learning model. And that is absolutely the critical piece to making sure you have a high performance system. And if you ever have to deploy a system to millions of people, these are some additional steps that you probably have to address. Think about an address at that point as well. Before moving on from the topic of the machine learning development process, there's one more set of ideas that I want to share with you that relates to the ethics of building machine learning systems. This is a crucial topic for many applications. So let's take a look at this in the next video.
[{"start": 0.0, "end": 7.640000000000001, "text": " So far, we've talked a lot about how to train a model and also talked a bit about how to"}, {"start": 7.640000000000001, "end": 11.32, "text": " get data for your machine learning application."}, {"start": 11.32, "end": 16.64, "text": " But when I'm building a machine learning system, I find that training a model is just part"}, {"start": 16.64, "end": 18.04, "text": " of the puzzle."}, {"start": 18.04, "end": 22.8, "text": " In this video, I'd like to share with you what I think of as the full cycle of a machine"}, {"start": 22.8, "end": 23.8, "text": " learning project."}, {"start": 23.8, "end": 29.12, "text": " That is, when you're building a valuable machine learning system, what are the steps to think"}, {"start": 29.12, "end": 30.36, "text": " about and plan for?"}, {"start": 30.36, "end": 31.96, "text": " Let's take a look."}, {"start": 31.96, "end": 36.4, "text": " Let me use speech recognition as an example to illustrate the full cycle of a machine"}, {"start": 36.4, "end": 38.6, "text": " learning project."}, {"start": 38.6, "end": 41.52, "text": " The first step of a machine learning project is to scope the project."}, {"start": 41.52, "end": 46.2, "text": " In other words, decide what is the project and what you want to work on."}, {"start": 46.2, "end": 51.28, "text": " So for example, I once decided to work on speech recognition for voice search, that"}, {"start": 51.28, "end": 56.16, "text": " is to do web search using speaking to your mobile phone rather than typing into your"}, {"start": 56.16, "end": 57.44, "text": " mobile phone."}, {"start": 57.44, "end": 59.839999999999996, "text": " So that's project scoping."}, {"start": 59.839999999999996, "end": 62.839999999999996, "text": " After deciding what to work on, you have to collect data."}, {"start": 62.839999999999996, "end": 67.6, "text": " So decide what data you need to train your machine learning system and go and do the"}, {"start": 67.6, "end": 72.2, "text": " work to get the audio and get the transcripts or the labels for your data set."}, {"start": 72.2, "end": 75.16, "text": " So that's data collection."}, {"start": 75.16, "end": 80.56, "text": " After you have your initial data collection, you can then start to train the model."}, {"start": 80.56, "end": 86.6, "text": " And so here you would train a speech recognition system and carry out error analysis and iteratively"}, {"start": 86.6, "end": 89.24, "text": " improve your model."}, {"start": 89.24, "end": 96.72, "text": " And it's not at all uncommon after you've started training the model for an error analysis"}, {"start": 96.72, "end": 101.08, "text": " or for a bias-variance analysis to tell you that you might want to go back to collect"}, {"start": 101.08, "end": 106.67999999999999, "text": " more data, maybe collect more data of everything or just collect more data of a specific type"}, {"start": 106.67999999999999, "end": 111.08, "text": " where your error analysis tells you you want to improve the performance of your learning"}, {"start": 111.08, "end": 112.36, "text": " algorithm."}, {"start": 112.36, "end": 117.24, "text": " For example, once when working on speech, I realized that my model was doing politically"}, {"start": 117.24, "end": 120.56, "text": " poorly when there was car noise in the background."}, {"start": 120.56, "end": 125.44, "text": " So if it sounded like someone was speaking in a car, my speech system performed poorly,"}, {"start": 125.44, "end": 131.6, "text": " decided to get more data, actually using data augmentation to get more speech data that"}, {"start": 131.6, "end": 137.48, "text": " sounds like it was a car in order to improve the performance of my learning algorithm."}, {"start": 137.48, "end": 141.84, "text": " So you go around this loop a few times, train the model, carry error analysis, go back to"}, {"start": 141.84, "end": 146.76, "text": " collect more data, maybe do this for a while until eventually you think the model is good"}, {"start": 146.76, "end": 150.0, "text": " enough to then deploy in a production environment."}, {"start": 150.0, "end": 154.56, "text": " And what that means is you make it available for users to use."}, {"start": 154.56, "end": 159.2, "text": " And when you deploy a system, you want to also make sure that you continue to monitor"}, {"start": 159.2, "end": 164.44, "text": " the performance of the system and to maintain the system in case the performance gets worse,"}, {"start": 164.44, "end": 166.52, "text": " to bring its performance back up."}, {"start": 166.52, "end": 171.72, "text": " Instead of just hosting your machine learning model on a server, I'll say a little bit more"}, {"start": 171.72, "end": 176.2, "text": " about why you need to maintain these machine learning systems on the next slide."}, {"start": 176.2, "end": 181.6, "text": " But after this deployment, sometimes you realize that it's not working as well as you hoped"}, {"start": 181.6, "end": 187.88, "text": " and you go back to train the model to improve it again or even go back and get more data."}, {"start": 187.88, "end": 195.12, "text": " In fact, if users and if you have permission to use data from your production deployment,"}, {"start": 195.12, "end": 201.12, "text": " sometimes that data from your working speech system can give you access to even more data"}, {"start": 201.12, "end": 204.68, "text": " with which to keep on improving the performance of your system."}, {"start": 204.68, "end": 208.76, "text": " Now I think you have a sense of what scoping a project means and we've talked a bunch about"}, {"start": 208.76, "end": 212.52, "text": " collecting data and training models in discourse."}, {"start": 212.52, "end": 217.28, "text": " But let me share with you a little bit more detail about what deploying in production"}, {"start": 217.28, "end": 219.70000000000002, "text": " might look like."}, {"start": 219.70000000000002, "end": 226.0, "text": " After you've trained a high performing machine learning model, say a speech recognition model,"}, {"start": 226.0, "end": 233.72, "text": " a common way to deploy the model would be to take your machine learning model and implement"}, {"start": 233.72, "end": 240.28, "text": " it in a server, which I'm going to call an inference server, whose job it is to call"}, {"start": 240.28, "end": 245.72, "text": " your machine learning model, your trained model, in order to make predictions."}, {"start": 245.72, "end": 252.28, "text": " Then if your team has implemented a mobile app, say a search application, then when the"}, {"start": 252.28, "end": 258.64, "text": " user talks to the mobile app, the mobile app can then make an API call to pass to your"}, {"start": 258.64, "end": 265.12, "text": " inference server the audio clip that was recorded and the inference service job is to apply"}, {"start": 265.12, "end": 271.4, "text": " the machine learning model to it and then return to it the prediction of your model,"}, {"start": 271.4, "end": 277.12, "text": " which in this case would be the text transcript of what was said."}, {"start": 277.12, "end": 284.0, "text": " So this would be a common way of implementing an application that calls via an API an inference"}, {"start": 284.0, "end": 289.92, "text": " server that has your model repeatedly make predictions based on the input x."}, {"start": 289.92, "end": 295.0, "text": " So this would be a common pattern where depending on the application that's implemented, you"}, {"start": 295.0, "end": 300.84000000000003, "text": " have an API call to give you learning algorithm the input x and your machine learning model"}, {"start": 300.84000000000003, "end": 305.26, "text": " would then output the prediction, say y hat."}, {"start": 305.26, "end": 311.44, "text": " To implement this, some software engineering may be needed to write all the code that does"}, {"start": 311.44, "end": 313.44, "text": " all of these things."}, {"start": 313.44, "end": 318.68, "text": " And depending on whether your application needs to serve just a few handful of users"}, {"start": 318.68, "end": 324.12, "text": " or millions of users, the amounts of software engineering needed can be quite different."}, {"start": 324.12, "end": 329.56, "text": " So I've built software that serve just a handful of users on my laptop and I've also built"}, {"start": 329.56, "end": 335.36, "text": " software that serves hundreds of millions of users requiring significant data center"}, {"start": 335.36, "end": 337.36, "text": " resources."}, {"start": 337.36, "end": 341.2, "text": " So depending on the scale of application needed software engineering may be needed to make"}, {"start": 341.2, "end": 347.72, "text": " sure that your inference server is able to make reliable and efficient predictions, hopefully"}, {"start": 347.72, "end": 350.72, "text": " at not too high a computational cost."}, {"start": 350.72, "end": 355.0, "text": " Software engineering may be needed to manage scaling to a large number of users."}, {"start": 355.0, "end": 359.88, "text": " You often want to log the data you're getting, both the inputs x as well as the predictions"}, {"start": 359.88, "end": 366.24, "text": " y hat, assuming that user privacy and consent allows you to store this data."}, {"start": 366.24, "end": 372.44, "text": " And this data, if you can access to it, is also very useful for system monitoring."}, {"start": 372.44, "end": 378.2, "text": " For example, I once built a speech recognition system on a certain data set that I had, but"}, {"start": 378.2, "end": 384.2, "text": " when there were new celebrities that suddenly became well known or elections caused new"}, {"start": 384.2, "end": 389.68, "text": " politicians to become elected, then people would search for these new names that were"}, {"start": 389.68, "end": 393.32, "text": " not in the training set and that my system did poorly on."}, {"start": 393.32, "end": 397.92, "text": " And it was because we're monitoring the system, it allowed us to figure out when the data"}, {"start": 397.92, "end": 401.41999999999996, "text": " was shifting and the algorithm was becoming less accurate."}, {"start": 401.41999999999996, "end": 409.14, "text": " And this allowed us to retrain the model and then to carry out a model update to replace"}, {"start": 409.14, "end": 412.48, "text": " the old model with a new one."}, {"start": 412.48, "end": 418.12, "text": " So the deployment process can require some amount of software engineering."}, {"start": 418.12, "end": 422.84000000000003, "text": " For some applications, if you're just running it on a laptop or on a one or two service,"}, {"start": 422.84000000000003, "end": 426.92, "text": " maybe not that much software engineering is needed."}, {"start": 426.92, "end": 431.84000000000003, "text": " And depending on the team you're working on, it's possible that you build the machine learning"}, {"start": 431.84000000000003, "end": 438.36, "text": " model, but there could be a different team responsible for deploying it."}, {"start": 438.36, "end": 444.24, "text": " But there is a growing field in machine learning called ML Ops, this stands for machine learning"}, {"start": 444.24, "end": 445.84000000000003, "text": " operations."}, {"start": 445.84000000000003, "end": 454.56, "text": " And this refers to the practice of how to systematically build and deploy and maintain"}, {"start": 454.56, "end": 459.2, "text": " machine learning systems to do all of these things to make sure that your machine learning"}, {"start": 459.2, "end": 466.28000000000003, "text": " model is reliable, scales well, has good logs, is monitored, and that you have the opportunity"}, {"start": 466.28000000000003, "end": 468.2, "text": " to make updates to the model."}, {"start": 468.2, "end": 471.0, "text": " As appropriate to keep it running well."}, {"start": 471.0, "end": 475.47999999999996, "text": " For example, if you're deploying your system to millions of people, you may want to make"}, {"start": 475.47999999999996, "end": 480.84, "text": " sure you have a highly optimized implementation so that the compute costs of serving millions"}, {"start": 480.84, "end": 484.15999999999997, "text": " of people is not too expensive."}, {"start": 484.15999999999997, "end": 488.76, "text": " So in this and the last class, we spent a lot of time talking about how to train a machine"}, {"start": 488.76, "end": 489.76, "text": " learning model."}, {"start": 489.76, "end": 495.08, "text": " And that is absolutely the critical piece to making sure you have a high performance"}, {"start": 495.08, "end": 496.08, "text": " system."}, {"start": 496.08, "end": 501.71999999999997, "text": " And if you ever have to deploy a system to millions of people, these are some additional"}, {"start": 501.71999999999997, "end": 504.88, "text": " steps that you probably have to address."}, {"start": 504.88, "end": 507.52, "text": " Think about an address at that point as well."}, {"start": 507.52, "end": 512.68, "text": " Before moving on from the topic of the machine learning development process, there's one"}, {"start": 512.68, "end": 517.46, "text": " more set of ideas that I want to share with you that relates to the ethics of building"}, {"start": 517.46, "end": 519.28, "text": " machine learning systems."}, {"start": 519.28, "end": 521.96, "text": " This is a crucial topic for many applications."}, {"start": 521.96, "end": 526.96, "text": " So let's take a look at this in the next video."}]