Book Image

Automated Machine Learning with AutoKeras

By : Luis Sobrecueva
Book Image

Automated Machine Learning with AutoKeras

By: Luis Sobrecueva

Overview of this book

AutoKeras is an AutoML open-source software library that provides easy access to deep learning models. If you are looking to build deep learning model architectures and perform parameter tuning automatically using AutoKeras, then this book is for you. This book teaches you how to develop and use state-of-the-art AI algorithms in your projects. It begins with a high-level introduction to automated machine learning, explaining all the concepts required to get started with this machine learning approach. You will then learn how to use AutoKeras for image and text classification and regression. As you make progress, you'll discover how to use AutoKeras to perform sentiment analysis on documents. This book will also show you how to implement a custom model for topic classification with AutoKeras. Toward the end, you will explore advanced concepts of AutoKeras such as working with multi-modal data and multi-task, customizing the model with AutoModel, and visualizing experiment results using AutoKeras Extensions. By the end of this machine learning book, you will be able to confidently use AutoKeras to design your own custom machine learning models in your company.
Table of Contents (15 chapters)
1
Section 1: AutoML Fundamentals
5
Section 2: AutoKeras in Practice
11
Section 3: Advanced AutoKeras

Creating the sentiment predictor

Now, we will use the AutoKeras TextClassifier to find the best classification model. Just for this example, we will set max_trials (the maximum number of different Keras models to try) to 2; we do not need to set the epochs parameter; instead, we must define an EarlyStopping callback of 2 epochs so that the training process stops if the validation loss does not improve in two consecutive epochs:

clf = ak.TextClassifier(max_trials=2)
cbs = [tf.keras.callbacks.EarlyStopping(patience=2)]

Let's run the training process and search for the optimal classifier for the training dataset:

clf.fit(x_train, y_train, callbacks=cbs)

Here is the output:

Figure 7.3 – Notebook output of text classifier training

Figure 7.3 – Notebook output of text classifier training

The previous output shows that the accuracy of the training dataset is increasing.

As we can see, we are getting a loss of 0.28 in the validation set. This isn't bad just for a few minutes of training...