SeriesDeep Learning3 / 20

Optimization of Deep Neural Networks

Module 3 of CS 7643 - Deep Learning @ Georgia Tech.

Review of Deep Learning#

Gradient Descent and Neural Networks#

Recall that Backpropagation - otherwise known as reverse-model automatic differentiation (synonymous in the context of machine learning) - is the recursive application of gradient descent to neural network layers via the chain rule of calculus.

Backpropagation enables us to use any differentiable function as a component of a neural network. For Deep Neural Networks (DNNs) - neural networks with at least two hidden layers - this implies we can select from a wide range of functions for each layer.

dnn-viz

DNN Design Considerations#

Since we’ve covered the core components of neural networks, what else is there to consider? Although we have the basic framework in place, there is a huge degree of flexibility to selecting specific implementations of each component.

In this module, we will explore each of these sub-domains to ensure we make informed decisions when designing our own neural networks.

DNNs: Architectural Considerations#

Architecture?#

The Architecture of a neural network specifies its composition in terms of 1) module (hidden layer) function types, and 2) connections between different modules. Certain compositions provide architectural bias to better fit the characteristics of a certain problem type. For example, top-performing architectures for natural language processing (NLP) problems tend to differ from those for computer vision (CV) problems.

High-Level Architectures#

Example neural architectures include…

The first step to neural architectural design is always to understand your data - architectural choices should be guided by the type of data used and its characteristics.

Module Types#

DNNs consist of a sequence of alternating linear and non-linear layers.

Note that a combination of linear layers alone would have the same representational power as a single linear layer. For this reason, non-linear layers are crucial to increasing representational power.

w1Tw2Tw3Tx=w4Txw_1^Tw_2^Tw_3^Tx = w_4^Tx

While gradient flow across linear layers is relatively straightforward, flow across non-linear layers is much more variable. Function characteristics such as gradients at extreme points and computational complexity are important considerations for selecting non-linearities.

gradient-flow

Although no single non-linearity is best for all problem domains, ReLU is the most common starting point due to its low computational complexity and robustness to vanishing gradients.

DNNs: Data Considerations#

Relative to other machine learning subfields, deep learning is interesting in that explicit feature engineering is not required. Instead, raw input data drives the learning of both intermediate features and the target function. This makes the characteristics of the input data even more important. We can alter these characteristics to be more appropriate for DNN training.

Normalization#

Feature Normalization is the process of transforming numerical features to a common scale to guarantee well-behaved statistics (e.g., range, mean, variance). Normalization can have a tangible impact on gradient-based learning - we can use normalization to ensure activations fall within a desired range, which results in gradients falling within a desirable (i.e., non-saturated) region of non-linear function domains.

Common types of normalization techniques include…

In the context of deep learning, we can implement standardization using layers. This is not problematic so long as the standardization technique is differentiable.

Once again, normalization is especially important before non-linearities to prevent extremely low and extremely high activation values. This is one method to combat against saturation, which would could result in vanishing / exploding gradients.

Data Augmentation#

Augmentation is used as a pre-processing step to transform data in a synthetic fashion. This may benefit model training in terms of 1) training data size, and 2) training data robustness.

In the context of images, here are a few examples of data augmentation:

cowmix

The more variability provided to the neural network during training, the more generalizable it will be to out-of-sample instances.

DNNs: Optimization Considerations#

Weight Initialization#

Furthermore, we might be interested in using different weight initialization techniques depending on the problem. Initial parameter values have a massive impact on learning since parameter values directly influence gradients. For example…

Ideally, weights should be initialized such that activations fall within “normal” regions of the non-linearities. A common approach is to initialize weights to small normally distributed random values.

DNNs may still struggle with small initial parameter values - the depth of the network implies many products of activation ×\times upstream gradient, and small activations will therefore limit gradient-based learning. DNNs must therefore balance the competing issues of saturation and small activations.

Perhaps the most ideal approach is Xavier Initialization, which samples weight values from a uniform distribution dependent on hidden layer size (number of nodes). This is an ideal approach since it maintains the variance of the output as similar to the variance of the input.

Uniform(6nj+nj+1,+6nj+nj+1)\text{Uniform}(-\frac{\sqrt{6}}{\sqrt{n_j + n_{j+1}}}, + \frac{\sqrt{6}}{\sqrt{n_j + n_{j+1}}})

xavier-init

Choice of Optimizer#

Recall that our optimization problem is to identify the set of weights that minimizes our loss function. In the context of deep learning, an Optimizer is a specific optimization algorithm which aims to find our ideal set of weights.

There are many challenges to consider during the optimization process:

Different optimizers incorporate different strategies to combat these problems:

Each of these optimizers behave differently depending on the surface of the loss function. Undesirable behaviors such as overshooting or stagnating may still occur. Vanilla SGD with Momentum can generalize better than adaptive methods, but may require a higher degree of tuning.

Regularization#

In the context of machine learning, Regularization refers to a broad class of methods for reducing overfitting during model training. Recall that overfitting refers to the situation where a model fits noise in the training data as opposed to the underlying trend we wish to represent. Overfitting is typically signaled by a significant gap in performance between training and validation data, where generalization error is much higher than training error.

Many regularization methods apply some additional penalty to the loss function based on the magnitude of the current weights:

L=yWxi2+λWL = |y - Wx_i|^2 + \lambda|W|

L=yWxi2+λW2L = |y - Wx_i|^2 + \lambda |W|^2

L=yWxi2+αW2+βWL = |y - Wx_i|^2 + \alpha|W|^2 + \beta |W|

Penalty-based regularization tends to produce smaller weight values. Since smaller weights result in smaller model variance, this is one technique for mitigating overfitting.

Other regularization methods apply to neural networks specifically. Dropout is a technique which probabilistically removes (“drops”) a certain percentage of nodes in a neural network layer during each iteration of training. This process forces the network to learn more robust features and representations that do not rely on any particular subset of nodes. Dropout is practically implemented by masking activations of deactivated nodes to zero.

dropout

At inference time, we do not perform any dropout. Instead, we may scale the weights at train or inference time by some term involving dropout probability. This helps to ensure activation distributions are similar at train versus inference time.

DNNs: Training Considerations#

Training deep neural networks is more of an art than a science. Many different factors contribute to the final outcome - the goal is to find a combination of components that works particularly well, where there exists a reasonable number of reasonable combinations.

General Methodology#

Properly executed DNN Training should split input data into the following partitions:

Cross-Validation is an alternative procedure which may be used in place of a validation set. Instead of holding out a dedicated validation set, the training set is divided into kk folds, where k1k-1 folds are used for training and the kk-th fold is used to estimate validation performance. Each possible combination of training : validation folds is used to train : evaluate the model, then evaluation metrics are summarized across iterations. This method is computationally expensive, and should only be used in the case of relatively small data.

Metrics + Monitoring#

The key to DNN Training is to monitor many different metrics to understand what is happening during training. So what metrics should we be looking at?

Recall the difference between overfitting and underfitting in machine learning. Overfitting is the case where validation loss diverges from training loss, where training loss continues to improve while validation loss remains constant or increases. Our model may have too much variance as compared to bias.

overfitting

Conversely, Underfitting is the case where training and validation loss are both very close, and perhaps relatively poor. Our model may benefit from additional variance.

A Hyperparameter is any value which influences a model’s representation, but is not directly learned from the data. Hyperparameters should be tuned to the specific dataset in order to match the model’s configuration to characteristics of the problem at hand. Deep learning involves a large number of hyperparameters. These include variables such as hidden layer size, number of hidden layers, learning rate, momentum, and regularization coefficient.

Hyperparameter Tuning is the process of selecting an optimal set of hyperparameters to minimize validation loss. We can perform hyperparameter tuning in a number of different ways:

Note that many hyperparameters are inter-dependent, so they cannot be reliably tuned individually.


(all images obtained from Georgia Tech DL course materials)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts