Large Scale Data Analysis Using Deep Learning
Deep Feedforward Networks - 2
U Kang
In This Lecture
๏ฎ
Back propagation
๏ฑ
Motivation
๏ฑ
Main idea
๏ฑ
Procedure
Computational Graphs
๏ฎ
Formalizes computation
๏ฎ
Each node indicates a variable
๏ฎ
Each edge indicates an operation
Chain Rule of Calculus
๏ฎ
Let x be a real number, and f and g be functions from R to R. Suppose y = g(x), and z = f(g(x)) = f(y). Then the chain rule states that
๐๐๐๐๐๐๐๐=
๐๐๐ฆ๐ฆ๐๐๐๐ ๐๐๐ฆ๐ฆ๐๐๐๐๏ฎ
Suppose ๐ฅ๐ฅ โ ๐ ๐
๐๐, ๐ฆ๐ฆ โ ๐ ๐
๐๐, ๐๐: ๐ ๐
๐๐โ ๐ ๐
๐๐, ๐๐ : ๐ ๐
๐๐โ ๐ ๐ . If ๐๐ = ๐๐(๐๐) and ๐ง๐ง = ๐๐(๐๐) , then
๐๐๐๐๐๐๐๐๐๐
= โ
๐๐ ๐๐๐ฆ๐ฆ๐๐๐๐๐๐
๐๐๐ฆ๐ฆ๐๐
๐๐๐๐๐๐
. In
vector notation: ๐ป๐ป
๐๐๐ง๐ง = (
๐๐๐๐๐๐๐๐)
๐๐๐ป๐ป
๐๐๐ง๐ง , where
๐๐๐๐๐๐๐๐is the n x m Jacobian matrix of g
๏ฑ E.g., suppose ๐ง๐ง = ๐๐๐๐๐๐, and ๐ฒ๐ฒ = ๐ป๐ป๐๐๐๐ ๐๐ . Then ๐ป๐ป๐๐๐ง๐ง = (๐๐๐๐๐๐๐๐)๐๐๐ป๐ป๐๐๐ง๐ง = ๐ป๐ป๐๐๐๐
Repeated Subexpressions
๏ฎ Computing the same subexpression many times would be wasteful
Backpropagation - Overview
๏ฎ
Backpropagation is an algorithm to compute partial derivatives efficiently in neural networks
๏ฎ
The main idea is dynamic programming
๏ฑ Many computations share common computations
๏ฑ Store the common computations in memory, and read them from memory when needed, without re-computing them from scratch
Backpropagation - Overview
๏ฎ Assume a computational graph to compute a single scalar ๐ข๐ข(๐๐)
๏ฑ E.g., this can be the loss
๏ฎ Our goal is to compute a partial derivatives ๐๐๐ข๐ข๐๐๐ข๐ข(๐๐)(๐๐) for all ๐๐ โ {1,2, โฆ , ๐๐๐๐} where ๐ข๐ข(1) to ๐ข๐ข(๐๐๐๐) are the parameters of model
๏ฎ We assume that nodes are ordered such that we compute their outputs one after the other, starting at ๐ข๐ข(๐๐๐๐+1) and going up to ๐ข๐ข(๐๐)
๏ฎ Each node ๐ข๐ข(๐๐) is associated with an operation ๐๐(๐๐) and is
computed by ๐ข๐ข(๐๐) = ๐๐(๐ด๐ด(๐๐)) where ๐ด๐ด(๐๐) is the set of all parents of ๐ข๐ข(๐๐)
Forward Propagation
๏ฎ This procedure performs the computations mapping ๐๐๐๐ inputs ๐ข๐ข(1) to ๐ข๐ข(๐๐๐๐) to output ๐ข๐ข(๐๐)
Back-Propagation
๏ฎ This procedure computes the partial derivatives of ๐ข๐ข(๐๐) with respect to the variables ๐ข๐ข(1), โฆ , ๐ข๐ข(๐๐๐๐)
Back-Propagation Example
๏ฎ
Back-propagation procedure (re-use blue-colored computation)
๏ฑ Compute ๐๐๐ฆ๐ฆ๐๐๐๐ and ๐๐๐๐๐๐๐๐
๏ฑ ๐๐๐๐
๐๐๐ค๐ค โ ๐๐๐ค๐ค๐๐๐ฆ๐ฆ ๐๐๐ฆ๐ฆ๐๐๐๐ + ๐๐๐ค๐ค๐๐๐๐ ๐๐๐๐๐๐๐๐
๏ฑ ๐๐๐๐
๐๐๐ฃ๐ฃ โ ๐๐๐ค๐ค๐๐๐ฃ๐ฃ ๐๐๐ค๐ค๐๐๐๐
v w
y x
z
Cost of Back-Propagation
๏ฎ The amount of computation scales linearly with the number of edges in the computational graph
๏ฑ Computation for each edge: computing a partial derivative, one multiplication, and one addition
w
y x
z
Compute ๐๐๐๐
๐๐๐ฆ๐ฆ and ๐๐๐๐
๐๐๐ง๐ง ๐๐๐๐
๐๐๐ค๐ค โ
๐๐๐ฆ๐ฆ
๐๐๐ค๐ค
๐๐๐ง๐ง
๐๐๐ฆ๐ฆ + ๐๐๐ฅ๐ฅ
๐๐๐ค๐ค
๐๐๐ง๐ง
๐๐๐ง๐ง ๐๐๐ค๐ค ๐๐๐ง๐ง ๐๐๐ฅ๐ฅ
Back-Propagation in Fully Connected
๏ฎ Forward propagation
MLP
Back-Propagation in Fully Connected
๏ฎ Backward computation
MLP
โจ: element-wise product
Minibatch Processing
๏ฎ SGD (recap)
๏ฑ We sample a minibatch of examples ๐ต๐ต = {๐ฅ๐ฅ 1 , โฆ , ๐ฅ๐ฅ ๐๐๐ } drawn uniformly from the training set
๏ฑ The estimate of the gradient is ๐๐ = ๐๐๐1 โ๐๐=1๐๐๐ ๐ป๐ป๐๐๐ฟ๐ฟ(๐ฅ๐ฅ ๐๐ ,๐ฆ๐ฆ ๐๐ ,๐๐)
๏ฑ Then the gradient descent is given by ๐๐ โ ๐๐ โ ๐๐๐๐
๏ฎ SGD using back propagation
๏ฑ For each instance (๐ฅ๐ฅ(๐๐),๐ฆ๐ฆ(๐๐)), where i=1~mโ, we compute the gradient
๐ป๐ป๐๐๐๐(๐๐) using back propagation where ๐๐(๐๐) = ๐ฟ๐ฟ(๐ฅ๐ฅ ๐๐ ,๐ฆ๐ฆ ๐๐ ,๐๐) is the i-th loss
๏ฑ The final gradient is ๐๐ = ๐๐๐1 โ๐๐=1๐๐๐ ๐ป๐ป๐๐๐๐(๐๐)
๏ฑ Update ๐๐ โ ๐๐ โ ๐๐๐๐
Example
๏ฎ A feedforward neural network with one hidden layer
๏ฎ Forward propagation
๏ฑ ๐๐ โ ๐พ๐พ๐๐
๏ฑ ๐๐ โ ๐๐(๐๐) (elementwise)
๏ฑ ๏ฟฝ๐๐ โ ๐๐๐๐๐๐
๏ฑ ๐ฑ๐ฑ โ ๐ฟ๐ฟ ๏ฟฝ๐๐,๐๐ + ๐๐๐๐ ๐พ๐พ,๐๐ = (๏ฟฝ๐๐ โ ๐๐)๐๐+๐๐( ๐พ๐พ ๐น๐น2 + ๐๐ 22)
๐๐ ๐๐
Example
๏ฎ Back propagation
๏ฑ ๐๐ โ ๐ป๐ป๏ฟฝ๐ฆ๐ฆ๐๐ = 2 ๏ฟฝ๐ฆ๐ฆ โ ๐ฆ๐ฆ
๏ฑ ๐ป๐ป๐๐๐๐ โ ๐ป๐ป๐๐[ ๏ฟฝ๐ฆ๐ฆ โ ๐ฆ๐ฆ 2 + ๐๐ ๐พ๐พ ๐น๐น2 + ๐๐ 22 ] = ๐๐๐๐ + 2๐๐๐๐
๏ฑ ๐๐ โ ๐ป๐ป๐๐๐๐ = ๐ป๐ป๐๐[ ๏ฟฝ๐ฆ๐ฆ โ ๐ฆ๐ฆ 2 + ๐๐ ๐พ๐พ ๐น๐น2 + ๐๐ 22 ] = ๐๐๐๐
๏ฑ ๐๐ โ ๐ป๐ป๐๐๐๐ = ๐๐ โจ ๐๐๐(๐๐) (elementwise)
๏ฑ ๐ป๐ป๐พ๐พ๐๐ โ ๐ป๐ป๐พ๐พ[ ๏ฟฝ๐ฆ๐ฆ โ ๐ฆ๐ฆ 2 + ๐๐ ๐พ๐พ ๐น๐น2 + ๐๐ 22 ] = ๐๐๐๐๐๐ + 2๐๐๐พ๐พ
๐๐ ๐๐ ๐๐
๐พ๐พ ๐๐
Higher-Order Derivatives
๏ฎ Some software frameworks (e.g., Theano and Tensorflow) support the use of higher-order derivatives
๏ฎ Hessian is useful for optimizing parameters.
๏ฑ For a function ๐๐:๐ ๐ ๐๐ โ ๐ ๐ , the Hessian matrix is n x n matrix
๏ฑ In deep learning, n is the number of parameters which can be millions or billions; thus constructing entire Hessian is intractable
๏ฑ The typical deep learning approach to compute a function of Hessian is to use Krylov methods: a set of iterative techniques for inverting a matrix or computing eigenvectors using only matrix-vector products
๏ฑ Hessian-vector product can be computed efficiently by
What you need to know
๏ฎ
Backpropagation is an algorithm to compute partial derivatives efficiently in neural
networks
๏ฑ
Reuse partial derivatives
๏ฎ
Procedure of backpropagation
๏ฎ