• Tidak ada hasil yang ditemukan

Deep Learning: A Practitioner's Approach

N/A
N/A
Игорь Ежов

Academic year: 2023

Membagikan " Deep Learning: A Practitioner's Approach"

Copied!
532
0
0

Teks penuh

Deep Learning, cover image, and associated trade imagery are trademarks of O'Reilly Media, Inc. You use the information and instructions in this section at your own risk.

Preface

What’s in This Book?

The book has many appendix chapters for topics that were relevant but did not fit directly into the main chapters.

Who Is “The Practitioner”?

Who Should Read This Book?

The Enterprise Machine Learning Practitioner

The Java engineer

The Enterprise Executive

The Academic

Conventions Used in This Book

Using Code Examples

Administrative Notes

O’Reilly Safari

How to Contact Us

Acknowledgments

Josh

I would like to note the support we received from our CEO at Skymind, Chris Nicholson. I would like to thank the people who contributed to the plugin chapters: Alex Black (Backprop, DataVec), Vyacheslav "Raver" Kokorin (GPU), Susan Eraly (GPU), and Ruben Fiszel (Reinforcement Learning).

Adam

The following are a few other people I would like to acknowledge who had an impact on my career leading up to this book: my parents (Lewis and Connie), Dr. Last, and especially not least, I would like to thank my wife Leslie and my sons Ethan, Griffin, and Dane for their patience while I worked late, often, and sometimes on vacation.

A Review of Machine Learning

The Learning Machines

Use the examples in the book to try out variations on practical deep networks. We hope you find the material practical and accessible. Let's start the book with a brief introduction to what machine learning is about and some of the core concepts you'll need to better understand the rest of the book.

How Can Machines Learn?

We will discuss our definition of deep learning in more detail in the next section.

Machine Learning Versus Data Mining

Let's take a quick look at another of the roots of deep learning: how neural networks are inspired by biology.

Biological Inspiration

First, the most basic unit of a neural network is an artificial neuron (or node for short). Artificial neurons are modeled after biological neurons in the brain and are stimulated by inputs just like biological neurons.

Biological Inspiration Across Computer Science

Biological neural networks are significantly more complex (several orders of magnitude) than artificial neural network versions. Second, just as neurons in the brain can be trained to forward only signals that are useful in achieving larger brain goals, we can train the neurons of a neural network to forward only useful signals.

What Is Deep Learning?

Ant colonies are able to perform intermediate tasks, defense, nest building, and foraging, while maintaining a near-optimal number of workers at each task based on relative need without the direct coordination of an individual ant.

Going Down the Rabbit Hole

Framing the Questions

The Math Behind Machine Learning: Linear Algebra

Scalars

Vectors

Matrices

Tensors

Hyperplanes

Relevant Mathematical Operations

Dot product

Element-wise product

Outer product

Converting Data Into Vectors

At some point we want our input data to be in the form of an array, but we can convert the data to intermediate representations (eg the "svmlight" file format shown in the code example that follows). The rest of the indexed numbers in the row are inserted into the corresponding slot in the matrix at runtime as "functions" to prepare for various linear algebra operations during the machine learning process.

Solving Systems of Equations

What Is a Feature?

An example of matrix decomposition in solving systems of linear equations is using upper-lower (LU) decomposition to solve the matrix A. Beyond matrix decomposition, let's take a look at general methods for solving sets of lin ‐.

Figure 1-4. Visualizing the equation Ax = b
Figure 1-4. Visualizing the equation Ax = b

Iterative methods

Iterative methods and linear algebra

The Math Behind Machine Learning: Statistics

Probability

Probability Versus Odds, Explained

Further Defining Probability: Bayesian Versus Frequentist

Bayesians, on the other hand, deal with "belief". in mathematical terms, "distributions") about the variable and update their beliefs about the variable as new information comes in.

Conditional Probabilities

Bayes’s Theorem

Posterior Probability

Distributions

The distribution of the training data in machine learning is important for understanding how to vectorize the data for modeling.

Figure 1-5. Examples of normal distributions
Figure 1-5. Examples of normal distributions

Central Limit Theorem

Long-tailed distributions deal with the real probability of events occurring that are five times the standard deviation. We need to be mindful of getting a good representation of the events in our training data to prevent overfitting the training data.

Samples Versus Population

Resampling Methods

Selection Bias

Likelihood

How Does Machine Learning Work?

Regression

Setting up the model

A simple example of a problem that linear regression solves would be to predict how much we will spend on gas per month based on the length of our commute. Visually, we can think of linear regression as finding a line that comes as close to as many points as possible in a scatter plot of data, as demonstrated in Figure 1-6.

Figure 1-6. Linear regression plotted
Figure 1-6. Linear regression plotted

Relating the linear regression model

Fitting is defining a function f(x) that produces y-values ​​close to the measured or actual y-values.

Classification

We will discuss this further when we talk about multi-output neural networks versus single-output neural networks (binary classification). We will also discuss classification more in this chapter when we talk about logistic regression and then delve into the overall architecture of neural networks.

Clustering

In addition to two labels, we can have classification models with N labels for which we give each of the output labels a score, and then the label with the highest score is the output label. Recommendation is the process of suggesting items to users of a system based on similar other users or other items they have previously looked at.

Underfitting and Overfitting

Solving underfitting is the priority, but a lot of effort in machine learning goes into not overfitting the line to the data. The training set of data we are trying to draw a line through is just a sample of a larger unknown set, and the line we draw will need to fit the larger set equally well if it is to have any predictive power.

Optimization

If the line fits the data too well, we have the opposite problem, called "overfitting". You minimize the sum of the difference between the line at point x and the target point y to which it corresponds.

Convex Optimization

Now let's take a closer look at one subclass of optimization called convex optimization. tion. three-dimensional space) will produce something that looks more like a leaf that sticks out at each corner and sags convexly in the middle—a rather bowl-shaped feature. The slopes of these convex curves give our algorithm a hint as to which direction to take the next parameter step, as we will see in the gradient descent algorithm optimization.

Gradient Descent

In convex optimization, we look for a point where the derivative is equal to 0 for the function. This point is also known as the stationary point of the function or the minimum point.

What Is Gradient?

The cost function tells us how far we are from the global minimum of the loss function, and we use the derivative of the loss function as the update function to change the parameter. Taking the derivative of the loss function tells each parameter in x how much we need to adjust the parameter to get closer to the 0 point on the loss curves.

Stochastic Gradient Descent

The lowest point in the lowest valley is known as the global minimum, while the lows of all other valleys are known as local minima. In Chapter 8, we take an in-depth look at normalization methods in the context of vectorization and illustrate some ways to better address this problem.

Mini-batch training and SGD

Applying mini-batch to stochastic gradient descent has also been shown to lead to smoother convergence because the gradient com‐ . As the mini-log size increases, the computed gradient is closer to the "true" gradient of the entire training set.

Quasi-Newton Optimization Methods

If our dataset size is too small (eg, 1 training record), we're not using the hardware as effectively as we could, especially for situations like GPUs.

The Jacobian and the Hessian

Generative Versus Discriminative Models

Discriminative models focus on closely modeling the boundary between classes and can provide a more nuanced representation of this boundary than a generative model. Generative models are typically set up as probabilistic graphical models that capture the subtle relationships in the data.

Logistic Regression

The Logistic Function

Understanding Logistic Regression Output

If y is a function of x, and that function is sigmoidal or logistic, the more x increases, the closer we get to 1/1, because e is to the power of an infinitely large negative number. Because (1 + e–θx) is in the denominator, the larger it gets, the closer the quotient itself gets to zero.

Evaluating Models

If we are trying to estimate the probability that an e-mail is spam and f(x) happens to be equal to 0.6, we can rewrite it by saying that y has a 60 percent chance of being 1, or e- the email has a 60 percent chance of being spam, given the input.

The Confusion Matrix

If we define machine learning as a method of deriving unknown outputs from known inputs, the parameter vector x in a logistic regression model determines the strength and certainty of our deductions.

Figure 1-11. The confusion matrix
Figure 1-11. The confusion matrix

Sensitivity versus specificity

Accuracy

Precision

Recall

Context and interpreting scores

The goal is to accurately predict death in this scenario; this is where the model has the most value in the context of being clinically relevant in the real world. We delve deeper into the different facets of class imbalance and error distributions in the context of classification and regression.

Building an Understanding of Machine Learning

The goal of the challenge was to “predict hospital mortality with the highest accuracy. This was set up so that the contestants were focused not only on predicting that the patient would live most of the time and get a good F1 score, but to focus on predicting.

Foundations of Neural Networks and Deep Learning

Neural Networks

There has been a lot of hubris and a lot of talk spread across the internet and in the literature about the connection of neural networks to the human mind. We provide a brief overview of the biological neuron and then look at the early predecessor of modern neural networks: the perceptron.

Figure 2-1. Multilayer neural network topology
Figure 2-1. Multilayer neural network topology

The Biological Neuron

Building on our understanding of the perceptron, we will then look at how it evolved into the more generalized artificial neuron that underpins today's modern multi-layer perceptrons. Most synapses send signals from the axon of one neuron to the dendrite of another neuron.

Dendrites

Axons

Information flow across the biological neuron

From biological to artificial

The Perceptron

Both the TLU and the perceptron inspired the biological neuron, as we will explore.

History of the perceptron

Definition of the perceptron

While we don't have a complete model for how the brain works, we can see how the perceptron was modeled after the biological neuron. In this case, we can see how the perceptron receives input through connections with weights on them, in a similar way to how synapses transmit information to other biological neurons.

Figure 2-3. Single-layer perceptron
Figure 2-3. Single-layer perceptron

The perceptron learning algorithm

The input values ​​do not affect the bias term, but the bias term is learned via per‐. As a basic linear classifier, we consider the single-layer perceptron to be the simplest form of the family of feed-forward neural networks.

Limitations of the early perceptron

Multilayer Feed-Forward Networks

Evolution of the artificial neuron

The artificial neuron (see Figure 2-6) takes inputs that, based on the weights on the connections, can be ignored (by a 0.0 weight on an input connection) or passed to the activation function. For the input layer, we just take the attribute at that particular index, and the activation function is linear (it passes the attribute value).

Figure 2-6. Details of an artificial neuron in a multilayer perceptron neural network We express the net input to a neuron as the weights on connections multiplied by activation incoming on connection, as shown in Figure 2-6
Figure 2-6. Details of an artificial neuron in a multilayer perceptron neural network We express the net input to a neuron as the weights on connections multiplied by activation incoming on connection, as shown in Figure 2-6

Comparing the biological neuron and the artificial neuron

Activation functions and their use will be an ongoing theme in almost every chapter for the rest of this book.

Feed-forward neural network architecture

This is controlled by the type of activation function we use in the neurons in the output layer. We will discuss the difference between these two types of activation functions later in the chapter.

Figure 2-7. Fully connected multilayer feed-forward neural network topology
Figure 2-7. Fully connected multilayer feed-forward neural network topology

Training Neural Networks

Weights can be understood mathematically by treating them as a vector of parameters in the previous section on linear algebra, which describes the process of machine learning as optimizing a vector of parameters (e.g., “weights” here) to minimize error.

Backpropagation Learning

Algorithm intuition

In the next section, we'll look at the mathematical notation you'll see in most literature. Learning algorithms for multilayer neural networks are neither guaranteed to converge to a global optimum, nor are they absolute.

A closer look at backpropagation

This is a direct effect of how learning a general function from training examples is considered an intractable problem in the worst case. The loss function (described later in this chapter) is not explicitly called in the pseudocode in Example 2-2.

Figure 2-8. Multilayer perceptron network zoomed-in with component labels
Figure 2-8. Multilayer perceptron network zoomed-in with component labels

Understanding backpropagation pseudocode Example 2-2 has the following inputs

This rule also contains an expression for the derivative of the activation function to obtain the gradient of the activation function. We saw in the previous section that g'(z) gave us the derivative of the activation function.

Figure 2-9. Updating connections into the output layer
Figure 2-9. Updating connections into the output layer

Backpropagation and Fractional Error Responsibility

This produces the partial error value for the node in the previous layer, which is used when we update the input links in that layer. We progressively perform this algorithm layer by layer until we have updated every layer in the network.

Backpropagation and Mini-Batch Stochastic Gradient Descent

This equation takes a look at each node i in the current layer and takes the current error value Δi and multiplies it by the weight of the incoming connection times the derivative of the activation function. The learning rate is a parameter we define (as opposed to being a measurement of network performance).

Activation Functions

The length of these learning steps, or the amount of weights changed with each iteration, is known as the learning rate. We use activation functions for hidden neurons in a neural network to introduce nonlinearity into the network's modeling capabilities.

Linear

The family of sigmoid functions contains several variations, one of which is known as the Sigmoid function.

Sigmoid

A sigmoid function is a machine that converts independent variables of nearly infinite range into simple probabilities between 0 and 1, and most of the output will be very close to 0 or 1.

Tanh

Hard Tanh

Softmax

If we want to get multiple classifications per output (eg "person + car"), we don't want softmax as the output layer. In the case where we have a large set of labels (eg thousands of labels), we would use a version of the softmax activation function called hierarchical softmax activa‐.

Rectified Linear

Compared to the sigmoid and tanh activation functions, the ReLU activation function does not suffer from gradient vanishing problems. Research has shown deep networks using ReLU activation functions to train well without using pre-training techniques.

Leaky ReLU

Because the gradient of a ReLU is either zero or a constant, it is possible to rule in the vanishing exploding gradient problem.

Softplus

Loss Functions

Loss Function Notation

We will use the notation h Xi =Yi to denote the neural network that transforms the input Xi to give the output Yi. So our notation h X =Y must be conditioned by a set of weights and biases; Thus, we will change our notation to say hw,b X =Y.

Loss Functions for Regression

We will modify this notation a bit later to emphasize its dependence on weights and biases. When we refer to the jth output function, we will use it as a signature that binds our notation to a matrix where the rows are different data points and col‐.

Mean squared error loss

Given the data available, the loss function notation indicates that its value depends only on W and b, the weights and the biases of the neural network. In the universe of a given neural network with a fixed number of layers, configurations, etc. to be trained on a given set of data, the value of the loss function depends solely on the state of the network, as defined by the weights and prejudices.

Other loss functions for regression

Regression loss function discussion

Although MSLE and MAPE are approaches to deal with large ranges, common practice with neural networks is to normalize input to a suitable range and use the MSE or MAE to optimize for either the mean or the median.

Loss Functions for Classification

Hinge loss

Logistic loss

For the sake of mathematical convenience, when dealing with the product of probabilities, it is customary to transform them into the log of proba‐. Note that we want to minimize our loss function, which we do by maximizing the likelihood, which in turn we do by minimizing the negative log likelihood.

Loss Functions for Reconstruction

This is mathematically equivalent to what is called the cross-entropy between two probability distributions—in this case, what we predict and what we observe under the same criteria.

Hyperparameters

Learning Rate

Too much learning rate exceeds the low point, causing the algorithm to bounce back and forth on either side of the minimum without ever coming to a stop. If you can't wait another week for results, choose a moderate learning rate (e.g. 0.1) and experiment with several others in the same ballpark to get the best speed and accuracy.

Regularization

A large learning rate coefficient (eg, 1) will make your parameters fast, and small ones (eg, will make it slow. Large jumps will save time initially, but can be disastrous if they cause us to exceed our minimum.

Momentum

Conversely, small learning rates should eventually lead you to an error minimum (it may be a local minimum rather than a global one), but they can take too long and add to the burden of an already computationally intensive process.

Sparsity

Fundamentals of Deep Networks

Defining Deep Learning

1 Referring to the character of Lewis Carroll's Red Queen from the book Through the Looking Glass; she has to keep running to stay in the same place. As the demands of the industry are changing and reaching more and more, the capabilities of neural networks must grow forward.

Defining deep networks

More connections means our network has more parameters to optimize, and that required the explosion in computing power that has occurred over the last 20 years.

Deep Reinforcement Learning

Deep reinforcement learning is a variant of reinforcement learning where a neural network is used as the universal function approximator. Deep reinforcement learning has grown in popularity during the production of this book, and hopefully we will see it included in a future edition.

Evolutionary progress and resurgence

This eventually led to the creation of the MNIST handwriting benchmark (we cover this more later in the chapter) and a progressive number of records for accuracy achieved by deep learning. Term Memory [LSTM] Memory Cell and Memory Cell with Forget Gate) during the late 1990s.

Figure 3-1. Trough of Disillusionment (source: https://en.wikipedia.org/wiki/
Figure 3-1. Trough of Disillusionment (source: https://en.wikipedia.org/wiki/

HAL 9000

This application will be more of the latent intelligence variety (eg recommendations or voice recognition) coupled with pragmatic engineering to make it useful in everyday aspects of our lives. We probably won't realize all the big commercial applications until they are right in front of our faces.

Advances in network architecture

Based on these achievements, we can easily design deep learning that will influence many applications in the next decade.

From feature engineering to automated feature learning

With CNNs, we train the network to understand the edge of the nose and then the general shape of the nose from the low-level "nose edge" features. Early layers in the network can pick up these nose edge features and then pass them on to later layers in the network as larger feature maps.

Generative modeling

The CNN extracts the artist's style into the network's parameters, which can later be applied to arbitrary images to be rendered in the same style. Another interesting application of recurrent neural networks is the work of Lipton and Elkan in which the network models proper names such as "Coors Light" and other aspects of beer jargon.

Figure 3-2. Stylized images by Gatys et al., 2015
Figure 3-2. Stylized images by Gatys et al., 2015

The Tao of deep learning

Chapter 5, we take a look at an example of Recurrent Neural Networks in which we generate new lines of Shakespeare by modeling all of Shakespeare's other works. Crafted beer reviews can be prompt-driven (eg, "give me a 3-star review of a German lager") and are impressive.

Organization of This Chapter

Common Architectural Principles of Deep Networks

Parameters

In deep networks, we still have a parameter vector that represents the connection in the network model we are trying to optimize. One network's layers are composed of RBMs (subnetworks in their own right, which we'll review later in the chapter) that are used to extract features for the other network.

Layers

The biggest change in deep networks regarding parameters is how the layers in the different architectures are connected. In terms of working with the core linear algebra of deep networks, DL4J relies on the ND4J library to represent these linear algebra primitives.

Activation functions for general architecture

In this case, we would use a sigmoid output layer with a single neuron to give us a real value in the range 0.0 to 1.0 (excluding these values) for the single class. Instead, we would use the sigmoid output layer with n number of neurons, which gives us a probability distribution (0.0 to 1.0) for each class independently.

Reconstruction cross-entropy

An example of this would be to use the multiclass cross entropy as a loss function in a layer with a soft‐.

Optimization Algorithms

The Jacobian has one partial derivative per parameter (to calculate the partial derivatives, all other variables are currently treated as constants). Second-order algorithms compute the derivative of the Jacobian (ie, the derivative of a matrix of derivatives) by approximating the Hessian.

First-order methods

There are other variations of optimization algorithms (such as "meta heuristics") that we will not cover in this book. You can adjust the SGD by adjusting the learning rate (e.g., with methods such as Adagrad, discussed shortly) or by using second-order information (i.e., the Hessian), as we'll see later. after.

Second-order methods

BFGS in Practice

Here we define a hyperparameter as any configuration setting that is free to be selected by the user that can affect performance.

Layer size

However, the link weights, as we saw in Chapter 1, are the parameters we need to train. A large number of parameters can lead to long training times and models that struggle to converge.

Magnitude hyperparameters

Momentum is a factor between 0.0 and 1.0 that is applied to the rate of change of weights over time. You multiply half the sum of the squared weights by a coefficient called weight-cost.

Mini-batching

We can also relate dropout to the concept of averaging the output of multiple models. L2 improves generalization, smooths the model output as the input changes, and helps the network ignore weights it doesn't use.

Summary

Building Blocks of Deep Networks

Over time, better optimization methods, activation functions, and weight initialization methods have reduced the importance of pre-training based deep networks. This gives us the first layer of weights for our main neural network (eg, multi-layer multi-layer perceptron).

RBMs

Geoff Hinton

Network layout

The nodes of the visible and hidden layers are connected by links with associated weights. In an RBM, every single node of the input (visible) layer is connected by weights to every single node of the hidden layer, but no two nodes are of the same layer.

Figure 3-3. RBM network
Figure 3-3. RBM network

Training

On” means that they forward the signal on the network; "off" means no. Normally "on" means that the data passing through the node is valuable; it contains information that will help the network make a decision.

Reconstruction

If we use an RBM to learn the MNIST dataset, we can sample from the trainers. If we know the mean and variance, or sigma, of the normal data, we can reconstruct that curve.

Figure 3-4. Reconstruction in RBMs
Figure 3-4. Reconstruction in RBMs

Other uses of RBMs

Autoencoders

Similarities to multilayer perceptrons

Defining features of autoencoders

Training autoencoders

Common variants of autoencoders

Applications of autoencoders

In addition to the output layer, there are a few other differences that we outline in the next section. Autoencoders are commonly used in systems where we know what the normal data will look like, but it is difficult to describe what is abnormal.

Variational Autoencoders

The VAE model assumes that data x is generated in two steps: (a) a value zi∼p z is generated from a prior distribution, and (b) the data instance is generated according to some conditional distribution xi∼p x z. For example, if P z x is Gaussian, the forward activation of the encoder yields the Gaussian distribution parameters μ and σ2.

Major Architectures of Deep Networks

Unsupervised Pretrained Networks

Deep Belief Networks

Feature Extraction with RBM Layers

These features move forward through these layers of RBMs in one direction, creating more elaborate features on the top layer. These feature layers are then used as initial weights in a traditional feedforward neural network driven by backpropagation.

Fine-tuning a DBN with a feed-forward multilayer neural network

As this raw data is modeled in the generative modeling process with each layer of the RBM, the system is able to extract increasingly higher-level features from the raw input data produced by our baseline input vectorization process. These initialization values ​​help the training algorithm guide the parameters of the traditional neural network to better regions of parameter search space.

Current state of DBNs

Generative Adversarial Networks

Training generative models, unsupervised learning, and GANs

The goal here is to make the images realistic enough to fool the discriminator network to the point where it cannot tell the difference between real and syn‐. The goal here is to update the parameters of the generating network to the point where the discriminant network is sufficiently "fooled" by the generating network because the output is so realistic compared to the real training data images.

Deconvolutional Networks

Building generative models and Deep Convolutional Generative Adversarial Networks

This network takes random numbers (from a uniform distribution) and generates an image from the network model as output. As the input random numbers change, we see that the DCGAN generates different types of images.

Conditional GANs

Comparing GANs and variational autoencoders

Sometimes with generated images we also get a different type of noise in the generated output image. The downside of images created with VAE is that the images are sometimes slightly blurry due to the way they are created.

Convolutional Neural Networks (CNNs)

The images generated by GANs tend to capture the style of the input data, but sometimes they don't compose the scene in a consistent way (eg, the image is of a dog, but the dog doesn't look quite right). The biological inspiration for CNNs is the visual cortex in animals.9 Cells in the visual cortex are sensitive to small subregions of input.

Intuition

Columns next to each other are thus materialized in the exported materialized view of the database. Cells are well suited to exploiting the strong spatio-local correlation found in the types of images our brains process, acting as local filters in the input space.

What Is the CIFAR-10 Dataset?

In many cases, we will want to have multiple hidden layers in our multilayer neural network, which will also multiply those weights. The structure of image data allows us to change the architecture of a neural network in a way that we can take advantage of this structure.

CNN Architecture Overview

The input layer accepts three-dimensional input generally in terms of spatial size (width × height) of the image and has a depth representing the color channels (generally three for RGB color channels). These layers find a series of features in the images and gradually construct higher order features.

Neuron spatial arrangements

We express the rectified linear unit (ReLU) activation function as a layer in the diagram here to be consistent with other literature. These layers are fully connected to all the neurons in the previous layer, as their name implies.

Evolution of the connections between layers

Input Layers

Convolutional Layers

Convolution

At each step, the kernel is multiplied by the input data values ​​within its bounds, creating a single entry in the output feature map. Convolutional layers perform transformations on the input data volume that are a function of the activations in the input volume and the parameters (weights and biases of the neurons).

Filters

The figure illustrates how the kernel is shifted over the input data to produce the con‐. In practice, if the feature we are looking for is detected in the input, the output is large.

Activation maps

To calculate the activation map, we push the filter over the depth slice of the input volume. We calculate the dot product between the inputs to the filter and the input volume.

Figure 4-13. Convolutions and activation maps
Figure 4-13. Convolutions and activation maps

Controlling Local Connectivity with the Receptive Field

We control the local connectivity of this process with the hyperparameter called the receptive field, which determines how much of the width and height of the input volume our filter maps against.

Parameter sharing

We cannot take advantage of parameter sharing if the input images we train on have a specific centered structure.

Learned filters and renders

ReLU activation functions as layers

Convolutional layer hyperparameters

The last hyperparameter is zero-padding, which can be used to control the spatial size of the output volumes. We would want to do this in cases where we want to preserve the spatial size of the input volume in the output volume.

Batch normalization and layers

Stride configures how far our filter slider will move based on the use of the filter function. Each time we apply the filter function to an input column, we create a new depth column in the output volume.

Pooling Layers

Fully Connected Layers

AlexNet is an example of this; it has two fully bonded layers followed by a softmax layer at the end.

Other Applications of CNNs

CNNs of Note

We have seen how convolutional layers, pooled layers and regular fully connected layers work together to do image classification.

Recurrent Neural Networks

Modeling the Time Dimension

Lost in time

Temporal feedback and loops in connections

Sequences and time-series data

An important facet of Recurrent Neural Networks is how we can work with input and output in unique ways.

Understanding model input and output

Now that we've seen the variations of input and output data, let's take a look at how this input data is represented.

3D Volumetric Input

Minibatch size is the number of input records (collections of time series points for a single source entity) that we want to model per batch. In the terminology of the previous section, we would consider any time step count above 1 to be "many-to-" in terms of input and output architecture.

Uneven time-series and masking

The number of columns matches up to the traditional feature column count found in a normal input vector.

Why Not Markov Models?

Recurrent Neural Networks, Hidden Layers, and Number of States

General Recurrent Neural Network Architecture

Recurrent Neural Networks architecture and time-steps

Vanishing Gradient Problem

LSTM Networks

Properties of LSTM networks

The computational complexity of the forward and backward pass operations scales linearly with the number of time steps in the input sequence. In the following sections, we provide an overview of the LSTM architecture and components.

LSTM network architecture

With recurrent neural networks, we introduce the idea of ​​a type of connection that connects the output of a hidden layer neuron to the input of the same hidden layer neuron. With this recurrent connection, we can take the input from the previous time step into the neuron as part of the incoming information.

Figure 4-21. Visually feed-forward multilayer network
Figure 4-21. Visually feed-forward multilayer network

LSTM units

The output port exposes (or not) the contents of the memory cell to the output of the LSTM unit. The output of the LSTM block is recurrently connected to the block input and all ports for the LSTM block.

Figure 4-24. LSTM block diagram
Figure 4-24. LSTM block diagram

Gated Recurrent Units (GRU)

These events can span up to 1,000 discrete time steps compared to older recurrent architectures, which can model events over about 10 time steps.

LSTM layers

BPTT and truncated BPTT

Recurrent Neural Networks and Backpropagation

In the figure, we can see that the shortened BPTT transition size is four time steps. The overall complexity of the standard BPTT and the truncated BPTT are similar and require the same number of time steps during training.

Figure 4-27. Truncated BPTT
Figure 4-27. Truncated BPTT

Domain-Specific Applications and Blended Networks

Image Labeling with Mixed CNN/Recurrent Neural Network38 This type of network is a combination of CNN and BRNN.

Recursive Neural Networks

Network Architecture

Think of the goal as the top of the tree, while the stakes are the bottom.

Varieties of Recursive Neural Networks

Applications of Recursive Neural Networks

Summary and Discussion

Will Deep Learning Make Other Algorithms Obsolete?

Different Problems Have Different Best Methods

However, random forests and ensemble methods tend to be winners when deep learning doesn't win. The size of the input dataset can be another factor in how well deep learning is suited to a given problem.

When Do I Need Deep Learning?

Empirical results over the past few years have shown that deep learning provides the best predictive power when the data set is large enough. Neural networks have greater representational capacity than linear models and are more capable of exploiting data.

When to use deep learning

It is common in machine learning to try several models and find the one that works best for a particular problem. If the data is clearly linear, as seen in visualizations, you would try to fit the data with a non-linear model (eg a multilayer perceptron).

When to stick with traditional machine learning

Building Deep Networks

Matching Deep Networks to the Right Problem

The applications in this chapter illustrate the concepts of deep networks that we have been building since Chapter 1. Even though a project like DL4J will evolve over time, we want to provide readers with a snapshot of the code that will always work with this version of the book.

Columnar Data and Multilayer Perceptrons

Historically, machine learning modeling has been relatively brittle when features are not in the correct "spots" in which the model expects them to be. A major strength of CNNs is their ability to take raw image data in which the objects in the scene are arbitrarily posed and skillfully recognize the features.

Evolution of CNN Applications

Columnar data, thanks to painstaking efforts, is displayed with all features aligned to a specific column. Objects in images rarely appear where we want or expect them, presenting non-trivial challenges in the feature extraction phase for classical machine learning techniques.

Time-series Sequences and Recurrent Neural Networks

However, in both time series and images, we are looking for specific artifacts that may occur in the data. These objects can be scaled in size and usually do not appear in the same place every time in the data, presenting us with a challenge.

Playing the Devil’s Advocate for Model Choice

Recurrent neural networks have evolved from multilayer perceptrons to better model the time domain of time series data. When we deal with variable-length time series with unknown but likely long dependencies, this is the case for which recurrent neural networks are particularly justified.

Using Hybrid Networks

If we were in the pure world of software engineering, we would consider this situation to be technical debt. If we're starting from a place where we don't know the right features, with the current state of the art in deep learning, it's easier to semiautomate hyperpara‐.

The DL4J Suite of Tools

The DL4J project also features robust vectorization capabilities with the introduction of DataVec as a first-class citizen in the suite. Let's take a quick look at each of these facets of the DL4J suite before we dive into setting up the tools on your laptop.

Vectorization and DataVec

Runtimes and ND4J

ND4J and the need for speed

JavaCPP

Benchmarking ND4J and DL4J

Basic Concepts of the DL4J API

Loading and Saving Models

Writing a trained model to disk

Reading a saved model from disk

Getting Input for the Model

Loading data during training

Setting Up Model Architecture

Building layer-oriented architectures

In the preceding code snippet, we can see hyperparameters such as a learning rate, an updater, and a moment value set for a given MultiLayerConfiguration object. We'll look at strategies for setting hyperparameters for different network architectures later in the book.

Training and Evaluation

We will commonly see this pattern for managing epoch loops in examples later in the chapter.

Making a prediction

Training, validation, and test data

Modeling CSV Data with Multilayer Perceptron Networks

Gambar

Figure 1-1. The relationship between AI and deep learning
Figure 1-2. Stylized images by Gatys et al., 2015 2
Figure 1-5. Examples of normal distributions
Figure 1-7. Underfitting and overfitting in machine learning
+7

Referensi

Dokumen terkait

In this study Deep Learning was used for the diagnosis of corn plant disease using the Convolutional Neural Network CNN method, with a total dataset of 3.854 images of diseases in

In this paper, the Apache Spark system has been utilized as an extensive data framework and applied a Deep Transfer Learning DTL method using Convolutional Neural Network CNN three

Keywords: electromagnetic interference noise; noise removal; convolutional neural network; image‐to‐image regression; deep learning; photoacoustic tomography; photoacoustic

Hyperspectral Image Super-Resolution via Deep Spatiospectral Attention Convolutional Neural Networks Jin-Fan Hu , Ting-Zhu Huang , Member, IEEE, Liang-Jian Deng , Member, IEEE,

An Early Recognition Approach for Okra Plant Diseases and Pests Classification Based on Deep Convolutional Neural Networks Rashidul Hasan Hridoy, Maisha Afroz, Faria Ferdowsy Abstract

CONCLUSION This study detected topics on social media Twitter using the Convolutional Neural Network CNN and Recurrent Neural Network RNN methods with the expansion of TF-IDF N-gram

Full form DL Deep Learning DCNN Deep Convolutional Neural Network BCE Binary Cross Entropy DNN Deep Neural Network CCE Categorical Cross Entropy PReLU Parametric Rectification SGD

Uses the Unet architecture which introduces a symmetric architecture and uses convolution techniques based on convolutional neural networks Convolutional Neural Network, CNN to handle