Book Image

Enhancing Deep Learning with Bayesian Inference

By : Matt Benatan, Jochem Gietema, Marian Schneider
Book Image

Enhancing Deep Learning with Bayesian Inference

By: Matt Benatan, Jochem Gietema, Marian Schneider

Overview of this book

Deep learning has an increasingly significant impact on our lives, from suggesting content to playing a key role in mission- and safety-critical applications. As the influence of these algorithms grows, so does the concern for the safety and robustness of the systems which rely on them. Simply put, typical deep learning methods do not know when they don’t know. The field of Bayesian Deep Learning contains a range of methods for approximate Bayesian inference with deep networks. These methods help to improve the robustness of deep learning systems as they tell us how confident they are in their predictions, allowing us to take more in how we incorporate model predictions within our applications. Through this book, you will be introduced to the rapidly growing field of uncertainty-aware deep learning, developing an understanding of the importance of uncertainty estimation in robust machine learning systems. You will learn about a variety of popular Bayesian Deep Learning methods, and how to implement these through practical Python examples covering a range of application scenarios. By the end of the book, you will have a good understanding of Bayesian Deep Learning and its advantages, and you will be able to develop Bayesian Deep Learning models for safer, more robust deep learning systems.
Table of Contents (11 chapters)

5.7 Implementing PBP

Because PBP is quite complex, we’ll implement it as a class. Doing so will keep our example code tidy and allow us to easily compartmentalize our various blocks of code. It will also make it easier to experiment with, for example, if you want to explore changing the number of units or layers in your network.

Step 1: Importing libraries

We begin by importing various libraries. In this example, we will use scikit-learn’s California Housing dataset to predict house prices:

 
from typing import List, Union, Iterable  
import math  
from sklearn import datasets  
from sklearn.model_selection import train_test_split  
import tensorflow as tf  
import numpy as np  
from tensorflow.python.framework import tensor_shape  
import tensorflow_probability as tfp

To make sure we produce the same output every time, we initialize our seeds:

 
RANDOM_SEED...