📄 Page
1
(This page has no text content)
📄 Page
2
1. Preface a. Who Should Read This Book b. Why I Wrote This Book c. Navigating This Book d. A Note on the Google AI Platform e. Things You Need for This Book f. Conventions Used in This Book g. Using Code Examples h. O’Reilly Online Learning i. How to Contact Us j. Acknowledgments 2. 1. Data Science and Deep Learning a. What Is Data Science? b. Classification and Regression i. Regression ii. Goodness of Fit iii. Classification with Logistic Regression iv. Multivariant Regression and Classification c. Data Discovery and Preparation i. Bad Data ii. Training, Test, and Validation Data
📄 Page
3
iii. Good Data iv. Preparing Data v. Questioning Your Data d. The Basics of Deep Learning i. The Perceptron Game e. Understanding How Networks Learn i. Backpropagation ii. Optimization and Gradient Descent iii. Vanishing or Exploding Gradients iv. SGD and Batching Samples v. Batch Normalization and Regularization vi. Activation Functions vii. Loss Functions f. Building a Deep Learner i. Optimizing a Deep Learning Network ii. Overfitting and Underfitting iii. Network Capacity g. Conclusion i. Game Answers 3. 2. AI on the Google Cloud Platform a. AI Services on GCP
📄 Page
4
i. The AI Hub ii. AI Platform iii. AI Building Blocks b. Google Colab Notebooks i. Building a Regression Model with Colab c. AutoML Tables d. The Cloud Shell e. Managing Cloud Data f. Conclusion 4. 3. Image Analysis and Recognition on the Cloud a. Deep Learning with Images i. Enter Convolution Neural Networks b. Image Classification i. Set Up and Load Data ii. Inspecting Image Data iii. Channels and CNN iv. Building the Model v. Training the AI Fashionista to Discern Fashions vi. Improving Fashionista AI 2.0 c. Transfer Learning Images i. Identifying Cats or Dogs
📄 Page
5
ii. Transfer Learning a Keras Application Model iii. Training Transfer Learning iv. Retraining a Better Base Model d. Object Detection and the Object Detection Hub API i. YOLO for Object Detection e. Generating Images with GANs f. Conclusion 5. 4. Understanding Language on the Cloud a. Natural Language Processing, with Embeddings i. Understanding One-Hot Encoding ii. Vocabulary and Bag-of-Words iii. Word Embeddings iv. Understanding and Visualizing Embeddings b. Recurrent Networks for NLP i. Recurrent Networks for Memory ii. Classifying Movie Reviews iii. RNN Variations c. Neural Translation and the Translation API i. Sequence-to-Sequence Learning
📄 Page
6
ii. Translation API iii. AutoML Translation d. Natural Language API e. BERT: Bidirectional Encoder Representations from Transformers i. Semantic Analysis with BERT ii. Document Matching with BERT iii. BERT for General Text Analysis f. Conclusion 6. 5. Chatbots and Conversational AI a. Building Chatbots with Python b. Developing Goal-Oriented Chatbots with Dialogflow c. Building Text Transformers i. Loading and Preparing Data ii. Understanding Attention iii. Masking and the Transformer iv. Encoding and Decoding the Sequence d. Training Conversational Chatbots i. Compiling and Training the Model ii. Evaluation and Prediction e. Using Transformer for Conversational Chatbots
📄 Page
7
f. Conclusion 7. 6. Video Analysis on the Cloud a. Downloading Video with Python b. Video AI and Video Indexing c. Building a Webcam Face Detector i. Understanding Face Embeddings d. Recognizing Actions with TF Hub e. Exploring the Video Intelligence API f. Conclusion 8. 7. Generators in the Cloud a. Unsupervised Learning with Autoencoders i. Mapping the Latent Space with VAE b. Generative Adversarial Network c. Exploring the World of Generators i. A Path for Exploring GANs ii. Translating Images with Pix2Pix and CycleGAN d. Attention and the Self-Attention GAN i. Understanding Self-Attention ii. Self-Attention for Image Colorization— DeOldify e. Conclusion 9. 8. Building AI Assistants in the Cloud
📄 Page
8
a. Needing Smarter Agents b. Introducing Reinforcement Learning i. Multiarm Bandits and a Single State ii. Adding Quality and Q Learning iii. Exploration Versus Exploitation iv. Understanding Temporal Difference Learning c. Building an Example Agent with Expected SARSA i. Using SARSA to Drive a Taxi ii. Learning State Hierarchies with Hierarchical Reinforcement Learning d. Bringing Deep to Reinforcement Learning i. Deep Q Learning ii. Optimizing Policy with Policy Gradient Methods e. Conclusion 10. 9. Putting AI Assistants to Work a. Designing an Eat/No Eat AI b. Selecting and Preparing Data for the AI c. Training the Nutritionist Model d. Optimizing Deep Reinforcement Learning e. Building the Eat/No Eat Agent f. Testing the AI Agent
📄 Page
9
g. Commercializing the AI Agent i. Identifying App/AI Issues ii. Involving Users and Progressing Development h. Future Considerations i. Conclusion 11. 10. Commercializing AI a. The Ethics of Commercializing AI b. Packaging Up the Eat/No Eat App c. Reviewing Options for Deployment i. Deploying to GitHub ii. Deploying with Google Cloud Deploy d. Exploring the Future of Practical AI e. Conclusion 12. Index
📄 Page
10
Practical AI on the Google Cloud Platform Utilizing Google’s State-of-the-Art AI Cloud Services Micheal Lanham
📄 Page
11
Practical AI on the Google Cloud Platform by Micheal Lanham Copyright © 2021 Micheal Lanham. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Jonathan Hassell Development Editor: Melissa Potter Production Editor: Kate Galloway Copyeditor: Piper Editorial, LLC Proofreader: Arthur Johnson Indexer: Judith McConville Interior Designer: David Futato Cover Designer: Karen Montgomery
📄 Page
12
Illustrator: Kate Dullea November 2020: First Edition Revision History for the First Edition 2020-10-20: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781492075813 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Practical AI on the Google Cloud Platform, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author, and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-492-07581-3
📄 Page
14
Preface This book was developed for an audience that I regularly see at my local Deep Learning Meetup group, a group of young, very eager, and very intelligent people wanting to understand and use the latest AI. Except, their dreams are often crushed or soured when they realize that the mathematics or programming they took in school is not the math they need to use for AI. For those who learn the correct math and programming, they then face the roadblock of building real, working AI—often with limited resources. While many companies see the value in investing in AI, the amount they are currently willing to invest is very small. In fact, developing cutting-edge AI can be quite expensive computationally, and that equals money. Google likely encountered the same audience I had seen at my Meetup groups—very young and keen newbies eager to learn but missing certain resources—when it decided to build its first AI cloud platform. However, what likely solidified that decision was seeing the same mentality expressed in corporations and businesses worldwide. Companies were essentially in the same boat as those trying to learn this new AI tech. Providing an entire AI platform with state-of-the-art models and other training tools in the cloud was a no-brainer. And so it was born, Google AI on the Google Cloud Platform (GCP).
📄 Page
15
Of course, what the next wave of AI/machine learning will look like remains to be seen. Will it be a set of automation tools that make our lives easier, or will it be something else? While I agree that automation tools like robot cleaners, self-driving cars, and so on will be a part of it, they won’t be the only part. What I see is the potential for a whole new wave of AI assistant or AI automation assistant apps. These could be smart assistants that provide the following services: Self help From assisting with maintaining physical training to just managing your weight, this will likely be a major part of what we use AI for in the future. Personal automation Google has already shown how personal assistants will be able to book your next hair appointment, but this could be taken a step further—perhaps automating a series of tasks to create a vacation, or an adventure vacation. Financial management Imagine having Warren Buffett as your personal financial advisor, except instead of him, you get an AI assistant that can and will manage all your money for you. That includes setting up and making investments and so on. An AI that would work 24/7 managing your money and making extra money for you won’t be a hard app to sell. Care assistants As the world ages, the number of personal-care assistants needed to help with aging will also increase. For the most
📄 Page
16
part this will be physical care, but it will likely include more mundane tasks like remembering medication or making appointments. However, this could progress to having real medical diagnosticians that would be better able to track your whole medical history throughout your life. Teachers Perhaps an AI teacher would allow you to better manage and track your learning goals. This AI agent could progress with you and manage your education and even accreditations throughout your lifetime. Imagine hiring an AI bot that not only trained you, but also accredited your training to others. Entertainment People in the AI community have been writing or trying to write self-aware chatbots for decades. Examples of this have been the focus of several movies, including the Oscar winner Her. Her features a Siri-like AI that is (or becomes) self-aware and falls in love with a human. The AI in Her was developed more as a general assistant and was not intended as a love bot—at least it is not portrayed that way in the movie. But perhaps the intention could be to build love or companion AI in a variety of forms. You could have imaginary AI friends for the lonely child, or replicas of old or deceased celebrities for those aging, and so on. The possibilities in this area are endless. Protection Imagine if you had an AI that could protect you in multiple ways, from guarding your finances to just looking behind your back when you walk home late at night. These could be separate AI or perhaps combined.
📄 Page
17
Everything else The list of these types of AI agents could go on and on, and it remains to be seen what will become practical in this brand-new space. While the goal of this book is to teach you how to use the Google AI platform for a variety of reasons, it is my hope that you will think about how these services could be used to power these types of AI assistants. Of course, you may not be ready to pull all of the resources together to build an AI assistant. Therefore, I have also made this book accessible for you by showing the base case for using the service or system, and how best to use it. That way you will be able to use the system immediately and then perhaps later move on to building a full, working AI assistant. For those of you looking to just build business AI, I have also shown plenty of examples with that in mind. Who Should Read This Book You will enjoy this book if you’re eager to learn and enjoy working with or seeing plenty of coding examples. I have tried to make this book accessible by minimizing the discussion of mathematics. However, you may find yourself needing some math refreshers or tutorials to grasp certain core concepts. Training models can and will take time, so patience is a must. As well, you need to understand that you will most certainly fail at what seem to be the most rudimentary of tasks. The
📄 Page
18
important thing to remember is that AI is just hard; it takes dedication and commitment to understand it. Why I Wrote This Book I wanted to write this book because Google had developed all of this cool AI that no one seemed to be using. Then I realized I wanted to write this book to help those looking for their place in AI. That sounds really cheesy until you understand my involvement in AI. I first learned of AI as a young man in the 1980s. It wasn’t until the later 1990s that I took a serious look back at advanced neural networks, only to be disappointed again by their lack of progress. Instead, I relied on some traditional data science and later ventured into various genetic learning strategies. Over many years I returned to deep learning and AI only to be disappointed time and again, until recently. It was through a recent project only a few short years ago that I took a look back at deep learning and realized how far it had come. However, unlike many, I had a broad base of understanding of the concepts and mathematics. Being exposed to deep learning over many, many years previously and keeping up with research gave me a significant advantage that allowed me to pick up the technology quicker than most. Then, when I sought the help of others, it occurred to me that most people were eager to learn but were unable to do so because of their frustrations with what was being taught. From those frustrations I spun out a group of introductory workshops aimed at providing
📄 Page
19
a tutorial on deep learning. Through hosting those sessions and the very positive response I received, I decided I wanted a bigger voice, and therefore writing a book made sense. So a big reason for writing this book is to help others bypass the same frustrations I have succumbed to over the years. I hope that alleviating those frustrations will give newcomers more energy to tackle tougher problems more successfully in the future. Navigating This Book This book is best read from start to finish, but of course you are likely a technical professional who needs to find their way and get answers as quickly as possible. With that in mind, use the following summary to help you decide the best place to start or perhaps just to refresh your knowledge if you return to the book later as a reference: Chapter 1, Data Science and Deep Learning This chapter is the best place to start if you are newish to data science, machine learning, or deep learning. If you have only a basic understanding of any of those topics, you will not want to miss this chapter. You should bypass this chapter only if you consider yourself a master of deep learning. Chapter 2, AI on the Google Cloud Platform This is a gentle introduction to the available AI services on Google and how those services are structured. From there
📄 Page
20
we will look at how to use the Google Colab service to build our first working deep learning network. Chapter 3, Image Analysis and Recognition on the Cloud In this chapter we take a look at how deep learning networks perform image recognition, and the tools they use to do this. We will look at building a similar image classification network, and then we will move on to using the Google Vision AI service. Chapter 4, Understanding Language on the Cloud Natural language processing, or NLP, is one area where deep learning systems are making unbelievable progress. In this chapter we first learn how a deep learning system can process language, and then we build a simple language processor. Chapter 5, Chatbots and Conversational AI Google provides a natural language chatbot service called Dialogflow that does a variety of language processing tasks. In this chapter we’ll use Dialogflow as a chat agent for a variety of tasks. Chapter 6, Video Analysis on the Cloud Video analysis is really an extension of image analysis, and in this chapter we see that Google has developed a service for doing just that. Later, we will review a variety of examples that use this service. Chapter 7, Generators in the Cloud AI can be used for a number of tasks, but one showing extreme promise is generation of content. AI content generation is where deep learning models generate unique