Get startedGet started for free

Custom training

1. Custom training

SPEAKER: In previous lessons, you learned about no-code solutions like AutoML and low-code solutions like pre-trained APIs. Now let's explore a code-based solution, custom training, a do-it-yourself approach to building an ML model. While AutoML UI offers significant convenience and pre-trained APIs eliminate the need for training data, you might require custom training if your unique needs extend beyond AutoML's automated capabilities. This is when complete control and flexibility over the model architecture, frameworks, and training logic become essential. Before any coding begins, you must determine what environment you want your ML training code to use. There are two options, a pre-built container or a custom container. A pre-built container is like a furnished kitchen with cabinets, appliances, and cookware. So if your ML training needs a platform like Python, TensorFlow, and PyTorch, and you're not particular about the underlying infrastructure to run on or, to use our kitchen analogy, which oven or knife you use, a pre-built container is probably your best choice. A custom container, alternatively, is like an empty room. You define the exact appliances and tools that you prefer to cook with. That means you must determine the details like the environment, machine type, and disks when creating the custom container. In terms of the tools to code your ML model, you can use Vertex AI Workbench. You can think of Vertex AI Workbench as Jupyter Notebook deployed in a single development environment that supports the entire data science workflow, from exploring to training, and then deploying a machine learning model. You can also use Colab Enterprise, which was integrated into Vertex AI platform in 2023 so data scientists could code in a familiar environment. After you decide the working environment, the next step is to start writing code. These days, you don't have to code from scratch. Instead, you can leverage ML libraries. An ML library is a collection of pre-written code that can be used to perform machine learning tasks. These libraries can save developers time and effort by providing them with the tools they need to build machine learning models without having to write everything from the beginning. As a data scientist, you might already be familiar with popular ML libraries, like TensorFlow, scikit-learn, and PyTorch. They are open-source and widely used by a large community of users and developers. Let's explore TensorFlow, an end-to-end open platform for machine learning supported by Google. TensorFlow contains multiple abstraction layers. You use TensorFlow APIs to develop and train ML models. The TensorFlow APIs are arranged hierarchically, with the high-level APIs built on the low level APIs. The lowest layer is hardware. TensorFlow can run on different hardware platforms, including CPU, GPU, and TPU. The next layer is the low-level TensorFlow APIs where you can write your own operations in C++ and call the core, basic, and numeric processing functions written in Python. The third layer is the TensorFlow model libraries, which provide the building blocks, such as neural network layers and evaluation metrics to create a custom ML model. The high-level TensorFlow APIs like Keras sit on top of this hierarchy. They hide the ML building details and automatically deploy the training. They can be your most used APIs. Note that Vertex AI fully hosts TensorFlow from low-level to high-level APIs. Regardless of which abstraction level you are writing your TensorFlow code at, Vertex AI gives you a managed service. Now let's look at an example of using tf.keras, a commonly used, high-level TensorFlow library to build a simple regression model. Typically, it takes three fundamental steps. In step 1, you create a model where you piece together the layers of a neural network. In step 2, you compile the model where you specify hyperparameters, such as performance evaluation and model optimization. Finally, you train your model to find the best fit. Assume you already imported necessary packages like TensorFlow and uploaded the data. The first step is to create a model by using tf.keras.sequential. To demonstrate, you can define your model as a three-layer neural network. You'll explore more details about neural networks such as activation functions in the next module. The next step is to compile the model by specifying how you want to train it by using the method compile. For instance, you can decide how to measure the performance by specifying a loss function. You can also optimize the training by pointing to an optimizer. The last step is to train the model by using the method fit. For instance, you can define the input, the training data and the output, the predicted results. You can also decide how many iterations you want to train the model by specifying the numbers of epochs. After you train the model and are satisfied with the performance, you can then deploy the model and make predictions. Apart from TensorFlow, Google is consistently introducing new frameworks. One of the most promising frameworks is JAX. JAX is a high-performance numerical computation library that is highly flexible and easy to use. It offers new possibilities for both research and production environments.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.