AI and Machine Learning for Coders

Book description

If you’re looking to make a career move from programmer to AI specialist, this is the ideal place to start. Based on Laurence Moroney's extremely successful AI courses, this introductory book provides a hands-on, code-first approach to help you build confidence while you learn key topics.

You’ll understand how to implement the most common scenarios in machine learning, such as computer vision, natural language processing (NLP), and sequence modeling for web, mobile, cloud, and embedded runtimes. Most books on machine learning begin with a daunting amount of advanced math. This guide is built on practical lessons that let you work directly with the code.

You’ll learn:

  • How to build models with TensorFlow using skills that employers desire
  • The basics of machine learning by working with code samples
  • How to implement computer vision, including feature detection in images
  • How to use NLP to tokenize and sequence words and sentences
  • Methods for embedding models in Android and iOS
  • How to serve models over the web and in the cloud with TensorFlow Serving

Table of contents

  1. Foreword
  2. Preface
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. Navigating This Book
    4. Technology You Need to Understand
    5. Online Resources
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How to Contact Us
    10. Acknowledgments
  3. I. Building Models
  4. 1. Introduction to TensorFlow
    1. What Is Machine Learning?
    2. Limitations of Traditional Programming
    3. From Programming to Learning
    4. What Is TensorFlow?
    5. Using TensorFlow
      1. Installing TensorFlow in Python
      2. Using TensorFlow in PyCharm
      3. Using TensorFlow in Google Colab
    6. Getting Started with Machine Learning
      1. Seeing What the Network Learned
    7. Summary
  5. 2. Introduction to Computer Vision
    1. Recognizing Clothing Items
      1. The Data: Fashion MNIST
    2. Neurons for Vision
    3. Designing the Neural Network
      1. The Complete Code
    4. Training the Neural Network
    5. Exploring the Model Output
    6. Training for Longer—Discovering Overfitting
    7. Stopping Training
    8. Summary
  6. 3. Going Beyond the Basics: Detecting Features in Images
    1. Convolutions
    2. Pooling
    3. Implementing Convolutional Neural Networks
    4. Exploring the Convolutional Network
    5. Building a CNN to Distinguish Between Horses and Humans
      1. The Horses or Humans Dataset
      2. The Keras ImageDataGenerator
      3. CNN Architecture for Horses or Humans
      4. Adding Validation to the Horses or Humans Dataset
      5. Testing Horse or Human Images
    6. Image Augmentation
    7. Transfer Learning
    8. Multiclass Classification
    9. Dropout Regularization
    10. Summary
  7. 4. Using Public Datasets with TensorFlow Datasets
    1. Getting Started with TFDS
    2. Using TFDS with Keras Models
      1. Loading Specific Versions
    3. Using Mapping Functions for Augmentation
      1. Using TensorFlow Addons
    4. Using Custom Splits
    5. Understanding TFRecord
    6. The ETL Process for Managing Data in TensorFlow
      1. Optimizing the Load Phase
      2. Parallelizing ETL to Improve Training Performance
    7. Summary
  8. 5. Introduction to Natural Language Processing
    1. Encoding Language into Numbers
      1. Getting Started with Tokenization
      2. Turning Sentences into Sequences
    2. Removing Stopwords and Cleaning Text
    3. Working with Real Data Sources
      1. Getting Text from TensorFlow Datasets
      2. Getting Text from CSV Files
      3. Getting Text from JSON Files
    4. Summary
  9. 6. Making Sentiment Programmable Using Embeddings
    1. Establishing Meaning from Words
      1. A Simple Example: Positives and Negatives
      2. Going a Little Deeper: Vectors
    2. Embeddings in TensorFlow
      1. Building a Sarcasm Detector Using Embeddings
      2. Reducing Overfitting in Language Models
      3. Using the Model to Classify a Sentence
    3. Visualizing the Embeddings
    4. Using Pretrained Embeddings from TensorFlow Hub
    5. Summary
  10. 7. Recurrent Neural Networks for Natural Language Processing
    1. The Basis of Recurrence
    2. Extending Recurrence for Language
    3. Creating a Text Classifier with RNNs
      1. Stacking LSTMs
    4. Using Pretrained Embeddings with RNNs
    5. Summary
  11. 8. Using TensorFlow to Create Text
    1. Turning Sequences into Input Sequences
    2. Creating the Model
    3. Generating Text
      1. Predicting the Next Word
      2. Compounding Predictions to Generate Text
    4. Extending the Dataset
    5. Changing the Model Architecture
    6. Improving the Data
    7. Character-Based Encoding
    8. Summary
  12. 9. Understanding Sequence and Time Series Data
    1. Common Attributes of Time Series
      1. Trend
      2. Seasonality
      3. Autocorrelation
      4. Noise
    2. Techniques for Predicting Time Series
      1. Naive Prediction to Create a Baseline
      2. Measuring Prediction Accuracy
      3. Less Naive: Using Moving Average for Prediction
      4. Improving the Moving Average Analysis
    3. Summary
  13. 10. Creating ML Models to Predict Sequences
    1. Creating a Windowed Dataset
      1. Creating a Windowed Version of the Time Series Dataset
    2. Creating and Training a DNN to Fit the Sequence Data
    3. Evaluating the Results of the DNN
    4. Exploring the Overall Prediction
    5. Tuning the Learning Rate
    6. Exploring Hyperparameter Tuning with Keras Tuner
    7. Summary
  14. 11. Using Convolutional and Recurrent Methods for Sequence Models
    1. Convolutions for Sequence Data
      1. Coding Convolutions
      2. Experimenting with the Conv1D Hyperparameters
    2. Using NASA Weather Data
      1. Reading GISS Data in Python
    3. Using RNNs for Sequence Modeling
      1. Exploring a Larger Dataset
    4. Using Other Recurrent Methods
    5. Using Dropout
    6. Using Bidirectional RNNs
    7. Summary
  15. II. Using Models
  16. 12. An Introduction to TensorFlow Lite
    1. What Is TensorFlow Lite?
    2. Walkthrough: Creating and Converting a Model to TensorFlow Lite
      1. Step 1. Save the Model
      2. Step 2. Convert and Save the Model
      3. Step 3. Load the TFLite Model and Allocate Tensors
      4. Step 4. Perform the Prediction
    3. Walkthrough: Transfer Learning an Image Classifier and Converting to TensorFlow Lite
      1. Step 1. Build and Save the Model
      2. Step 2. Convert the Model to TensorFlow Lite
      3. Step 3. Optimize the Model
    4. Summary
  17. 13. Using TensorFlow Lite in Android Apps
    1. What Is Android Studio?
    2. Creating Your First TensorFlow Lite Android App
      1. Step 1. Create a New Android Project
      2. Step 2. Edit Your Layout File
      3. Step 3. Add the TensorFlow Lite Dependencies
      4. Step 4. Add Your TensorFlow Lite Model
      5. Step 5. Write the Activity Code to Use TensorFlow Lite for Inference
    3. Moving Beyond “Hello World”—Processing Images
    4. TensorFlow Lite Sample Apps
    5. Summary
  18. 14. Using TensorFlow Lite in iOS Apps
    1. Creating Your First TensorFlow Lite App with Xcode
      1. Step 1. Create a Basic iOS App
      2. Step 2. Add TensorFlow Lite to Your Project
      3. Step 3. Create the User Interface
      4. Step 4. Add and Initialize the Model Inference Class
      5. Step 5. Perform the Inference
      6. Step 6. Add the Model to Your App
      7. Step 7. Add the UI Logic
    2. Moving Beyond “Hello World”—Processing Images
    3. TensorFlow Lite Sample Apps
    4. Summary
  19. 15. An Introduction to TensorFlow.js
    1. What Is TensorFlow.js?
    2. Installing and Using the Brackets IDE
    3. Building Your First TensorFlow.js Model
    4. Creating an Iris Classifier
    5. Summary
  20. 16. Coding Techniques for Computer Vision in TensorFlow.js
    1. JavaScript Considerations for TensorFlow Developers
    2. Building a CNN in JavaScript
    3. Using Callbacks for Visualization
    4. Training with the MNIST Dataset
    5. Running Inference on Images in TensorFlow.js
    6. Summary
  21. 17. Reusing and Converting Python Models to JavaScript
    1. Converting Python-Based Models to JavaScript
      1. Using the Converted Models
    2. Using Preconverted JavaScript Models
      1. Using the Toxicity Text Classifier
      2. Using MobileNet for Image Classification in the Browser
      3. Using PoseNet
    3. Summary
  22. 18. Transfer Learning in JavaScript
    1. Transfer Learning from MobileNet
      1. Step 1. Download MobileNet and Identify the Layers to Use
      2. Step 2. Create Your Own Model Architecture with the Outputs from MobileNet as Its Input
      3. Step 3. Gather and Format the Data
      4. Step 4. Train the Model
      5. Step 5. Run Inference with the Model
    2. Transfer Learning from TensorFlow Hub
    3. Using Models from
    4. Summary
  23. 19. Deployment with TensorFlow Serving
    1. What Is TensorFlow Serving?
    2. Installing TensorFlow Serving
      1. Installing Using Docker
      2. Installing Directly on Linux
    3. Building and Serving a Model
      1. Exploring Server Configuration
    4. Summary
  24. 20. AI Ethics, Fairness, and Privacy
    1. Fairness in Programming
    2. Fairness in Machine Learning
    3. Tools for Fairness
      1. The What-If Tool
      2. Facets
    4. Federated Learning
      1. Step 1. Identify Available Devices for Training
      2. Step 2. Identify Suitable Available Devices for Training
      3. Step 3. Deploy a Trainable Model to Your Training Set
      4. Step 4. Return the Results of the Training to the Server
      5. Step 5. Deploy the New Master Model to the Clients
      6. Secure Aggregation with Federated Learning
      7. Federated Learning with TensorFlow Federated
    5. Google’s AI Principles
    6. Summary
  25. Index

Product information

  • Title: AI and Machine Learning for Coders
  • Author(s): Laurence Moroney
  • Release date: October 2020
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492078197