Σχόλια 0

Το κείμενο του εγγράφου

TRAINING RECURRENT NEURAL NETWORKSbyIlya SutskeverA thesis submitted in conformity with the requirementsfor the degree of Doctor of PhilosophyGraduate Department of Computer ScienceUniversity of TorontoCopyrightc2013 by Ilya SutskeverAbstractTraining Recurrent Neural NetworksIlya SutskeverDoctor of PhilosophyGraduate Department of Computer ScienceUniversity of Toronto2013Recurrent Neural Networks (RNNs) are powerful sequence models that were believed to be difﬁcult totrain,and as a result they were rarely used in machine learning applications.This thesis presents methodsthat overcome the difﬁculty of training RNNs,and applications of RNNs to challenging problems.We ﬁrst describe a newprobabilistic sequence model that combines Restricted Boltzmann Machinesand RNNs.The new model is more powerful than similar models while being less difﬁcult to train.Next,we present a new variant of the Hessian-free (HF) optimizer and show that it can train RNNson tasks that have extreme long-range temporal dependencies,which were previously considered to beimpossibly hard.We then apply HF to character-level language modelling and get excellent results.We also apply HF to optimal control and obtain RNN control laws that can successfully operateunder conditions of delayed feedback and unknown disturbances.Finally,we describe a randomparameter initialization scheme that allows gradient descent with mo-mentumto train RNNs on problems with long-termdependencies.This directly contradicts widespreadbeliefs about the inability of ﬁrst-order methods to do so,and suggests that previous attempts at trainingRNNs failed partly due to ﬂaws in the randominitialization.iiAcknowledgementsBeing a PhD student in the machine learning group of the University of Toronto was lots of fun,andjoining it was one of the best decisions that I have ever made.I want to thank my adviser,Geoff Hinton.Geoff taught me how to really do research and our meetings were the highlight of my week.He is anexcellent mentor who gave me the freedom and the encouragement to pursue my own ideas and theopportunity to attend many conferences.More importantly,he gave me his unfailing help and supportwhenever it was needed.I amgrateful for having been his student.I am fortunate to have been a part of such an incredibly fantastic ML group.I truly think so.Theatmosphere,faculty,postdocs and students were outstanding in all dimensions,without exaggeration.I want to thank my committee,Radford Neal and Toni Pitassi,in particular for agreeing to read mythesis so quickly.I want to thank Rich for enjoyable conversations and for letting me attend the Z-groupmeetings.I want to thank the current learning students and postdocs for making the learning lab such a fun en-vironment:Abdel-Rahman Mohamed,Alex Graves,Alex Krizhevsky,Charlie Tang,Chris Maddison,Danny Tarlow,Emily Denton,George Dahl,James Martens,Jasper Snoek,Maks Volkovs,NavdeepJaitly,Nitish Srivastava,and Vlad Mnih.I want to thank my ofﬁcemates,Kevin Swersky,LaurentCharlin,and Tijmen Tieleman for making me look forward to arriving to the ofﬁce.I also want tothank the former students and postdocs whose time in the group overlapped with mine:Amit Gruber,Andriy Mnih,Hugo Larochelle,Iain Murray,Jim Huang,Inmar Givoni,Nikola Karamanov,RuslanSalakhutdinov,Ryan P.Adams,and Vinod Nair.It was lots of fun working with Chris Maddison in thesummer of 2011.I amdeeply indebted to my collaborators:Andriy Mnih,Charlie Tang,Danny Tarlow,George Dahl,GrahamTaylor,James Cook,Josh Tenenbaum,Kevin Swersky,Nitish Srivastava,RuslanSalakhutdinov,Ryan P.Adams,Tim Lillicrap,Tijmen Tieleman,Tom´aˇs Mikolov,and Vinod Nair;andespecially to Alex Krizhevsky and James Martens.I amgrateful to Danny Tarlowfor discovering T&M;to Relu Patrascu for stimulating conversations and for keeping our computers working smoothly;andto Luna Keshwah for her excellent administrative support.I want to thank students in other groups formaking school even more enjoyable:Abe Heifets,Aida Nematzadeh,Amin Tootoonchian,FernandoFlores-Mangas,Izhar Wallach,Lena Simine-Nicolin,Libby Barak,Micha Livne,Misko Dzamba,Mo-hammad Norouzi,Orion Buske,Siavash Kazemian,Siavosh Benabbas,Tasos Zouzias,Varada Kolhatka,Yulia Eskin,Yuval Filmus,and anyone else I might have forgot.A very special thanks goes to AnnatKoren for making the writing of the thesis more enjoyable,and for proofreading it.But most of all,I want to express the deepest gratitude to my family,and especially to my parents,who have done two immigrations for me and my brother’s sake.Thank you.And to my brother,forbeing a good sport.iiiContents0.1 Relationship to Published Work.............................vii1 Introduction 12 Background 32.1 Supervised Learning...................................32.2 Optimization.......................................42.3 Computing Derivatives..................................72.4 Feedforward Neural Networks..............................82.5 Recurrent Neural Networks................................92.5.1 The difﬁculty of training RNNs.........................102.5.2 Recurrent Neural Networks as Generative models................112.6 Overﬁtting.........................................122.6.1 Regularization..................................132.7 Restricted Boltzmann Machines.............................142.7.1 Adding more hidden layers to an RBM.....................172.8 Recurrent Neural Network Algorithms..........................182.8.1 Real-Time Recurrent Learning..........................182.8.2 Skip Connections.................................182.8.3 Long Short-TermMemory............................182.8.4 Echo-State Networks...............................192.8.5 Mapping Long Sequences to Short Sequences..................212.8.6 Truncated Backpropagation Through Time...................233 The Recurrent Temporal Restricted Boltzmann Machine 243.1 Motivation.........................................243.2 The Temporal Restricted Boltzmann Machine......................253.2.1 Approximate Filtering..............................273.2.2 Learning.....................................273.3 Experiments with a single layer model..........................283.4 Multilayer TRBMs....................................293.4.1 Results for multilevel models..........................313.5 The Recurrent Temporal Restricted Boltzmann Machine................313.6 Simpliﬁed TRBM.....................................313.7 Model Deﬁnition.....................................323.8 Inference in RTRBMs...................................333.9 Learning in RTRBMs...................................343.10 Details of Backpropagation Through Time........................35iv3.11 Experiments........................................353.11.1 Videos of bouncing balls.............................363.11.2 Motion capture data...............................363.11.3 Details of the learning procedures........................373.12 Conclusions........................................374 Training RNNs with Hessian-Free Optimization 384.1 Motivation.........................................384.2 Hessian-Free Optimization................................384.2.1 The Levenberg-Marquardt Heuristic.......................404.2.2 Multiplication by the Generalized Gauss-Newton Matrix............404.2.3 Structural Damping................................424.3 Experiments........................................454.3.1 Pathological synthetic problems.........................464.3.2 Results and discussion..............................474.3.3 The effect of structural damping.........................474.3.4 Natural problems.................................474.4 Details of the Pathological Synthetic Problems......................484.4.1 The addition,multiplication,and XOR problem.................494.4.2 The temporal order problem...........................494.4.3 The 3-bit temporal order problem........................494.4.4 The randompermutation problem........................504.4.5 Noiseless memorization.............................504.5 Details of the Natural Problems..............................504.5.1 The bouncing balls problem...........................504.5.2 The MIDI dataset.................................514.5.3 The speech dataset................................514.6 Pseudo-code for the Damped Gauss-Newton Vector Product..............525 Language Modelling with RNNs 535.1 Introduction........................................535.2 The Multiplicative RNN.................................545.2.1 The Tensor RNN.................................545.2.2 The Multiplicative RNN.............................555.3 The Objective Function..................................565.4 Experiments........................................575.4.1 Datasets......................................575.4.2 Training details..................................575.4.3 Results......................................595.4.4 Debagging....................................595.5 Qualitative experiments..................................595.5.1 Samples fromthe models.............................595.5.2 Structured sentence completion.........................605.6 Discussion.........................................61v6 Learning Control Laws with Recurrent Neural Networks 626.1 Introduction........................................626.2 Augmented Hessian-Free Optimization.........................636.3 Experiments:Tasks....................................656.4 Network Details......................................666.5 Formal ProblemStatement................................676.6 Details of the Plant....................................676.7 Experiments:Description of Results...........................686.7.1 The center-out task................................686.7.2 The postural task.................................706.7.3 The DDN task..................................706.8 Discussion and Future Directions.............................717 MomentumMethods for Well-Initialized RNNs 737.1 Motivation.........................................737.1.1 Recent results for deep neural networks.....................737.1.2 Recent results for recurrent neural networks...................737.2 Momentumand Nesterov’s Accelerated Gradient....................747.3 Deep Autoencoders....................................777.3.1 Randominitializations..............................797.3.2 Deeper autoencoders...............................797.4 Recurrent Neural Networks................................807.4.1 The initialization.................................807.4.2 The problems...................................817.5 Discussion.........................................828 Conclusions 848.1 Summary of Contributions................................848.2 Future Directions.....................................85Bibliography 86vi0.1 Relationship to Published WorkThe chapters in this thesis describe work that has been published in the following conferences andjournals:Chapter 3  Nonlinear Multilayered Sequence ModelsIlya Sutskever.Master’s Thesis,2007 (Sutskever,2007) Learning Multilevel Distributed Representations for High-Dimensional SequencesIlya Sutskever and Geoffrey Hinton.In the Eleventh International Conference on ArtiﬁcialIntelligence and Statistics (AISTATS),2007 (Sutskever and Hinton,2007) The Recurrent Temporal Restricted Boltzmann MachineIlya Sutskever,Geoffrey Hinton and Graham Taylor.In Advances in Neural InformationProcessing Systems 21 (NIPS*21),2008 (Sutskever et al.,2008)Chapter 4  Training Recurrent Neural Networks with Hessian Free optimizationJames Martens and Ilya Sutskever.In the 28th Annual International Conference on Ma-chine Learning (ICML),2011 (Martens and Sutskever,2011)Chapter 5  Generating Text with Recurrent Neural NetworksIlya Sutskever,James Martens,and Geoffrey Hinton.In the 28th Annual InternationalConference on Machine Learning (ICML),2011 (Sutskever et al.,2011)Chapter 6  joint work with Timothy Lillicrap and James MartensChapter 7  joint work with James Martens,George Dahl,and Geoffrey HintonThe publications belowdescribe work that is loosely related to this thesis but not described in the thesis: ImageNet Classiﬁcation with Deep Convolutional Neural NetworksAlex Krizhevsky,Ilya Sutskever,and Geoffrey Hinton.In Advances in Neural Information Pro-cessing Systems 26,(NIPS*26),2012.(Krizhevsky et al.,2012) Cardinality Restricted Boltzmann MachinesKevin Swersky,Danny Tarlow,Ilya Sutskever,Richard Zemel,Ruslan Salakhutdinov,and RyanP.Adams.In Advances in Neural Information Processing Systems 26,(NIPS*26),2012 (Swerskyet al.,2012) Improving neural networks by preventing co-adaptation of feature detectorsGeoff Hinton,Nitish Srivastava,Alex Krizhevksy,Ilya Sutskever,and Ruslan Salakhutdinov.Arxiv,2012.(Hinton et al.,2012) Estimating the Hessian by Backpropagating CurvatureJames Martens,Ilya Sutskever,and Kevin Swersky.In the 29th Annual International Conferenceon Machine Learning (ICML),2012 (Martens et al.,2012) Subword language modeling with neural networksTom´aˇs Mikolov,Ilya Sutskever,Anoop Deoras,Hai-Son Le,Stefan Kombrink,JanˇCernock´y.Unpublished,2012 (Mikolov et al.,2012) Data Normalization in the Learning of RBMsYichuan Tang and Ilya Sutskever.Technical Report,UTML-TR 2011-02.(Tang and Sutskever,2011)vii Parallelizable Sampling for MRFsJames Martens and Ilya Sutskever.In the Thirteenth International Conference on Artiﬁcial In-telligence and Statistics (AISTATS),2010 (Martens and Sutskever,2010) On the convergence properties of Contrastive DivergenceIlya Sutskever and Tijmen Tieleman.In the Thirteenth International Conference on ArtiﬁcialIntelligence and Statistics (AISTATS),2010 (Sutskever and Tieleman,2010) Modelling Relational Data using Bayesian Clustered Tensor FactorizationIlya Sutskever,Ruslan Salakhutdinov,and Joshua Tenenbaum.In Advances in Neural Informa-tion Processing Systems 22 (NIPS*22),2009 (Sutskever et al.,2009) A simpler uniﬁed analysis of budget perceptronsIlya Sutskever.In the 26th Annual International Conference on Machine Learning (ICML),2009 (Sutskever,2009) Using matrices to model symbolic relationshipsIlya Sutskever and Geoffrey Hinton.In Advances in Neural Information Processing Systems 21(NIPS*21),2008 (poster spotlight) (Sutskever and Hinton,2009b) Mimicking Go Experts with Convolutional Neural NetworksIlya Sutskever and Vinod Nair.In the 18th International Conference on Artiﬁcial Neural Net-works (ICANN),2008 (Sutskever and Nair,2008) Deep Narrow Sigmoid Belief Networks are Universal ApproximatorsIlya Sutskever and Geoffrey Hinton,Neural Computation.November 2008,Vol 20,No 11:2629-2636 (Sutskever and Hinton,2008) Visualizing Similarity Data with a Mixture of MapsJames Cook,Ilya Sutskever,Andriy Mnih,and Geoffrey Hinton.In the Eleventh InternationalConference on Artiﬁcial Intelligence and Statistics (AISTATS),2007 (Cook et al.,2007) Temporal Kernel Recurrent Neural NetworksIlya Sutskever and Geoffrey Hinton,Neural Networks,Vol.23,Issue 2,March 2010,Pages239-243.(Sutskever and Hinton,2009a)viiiChapter 1IntroductionRecurrent Neural Networks (RNNs) are artiﬁcial neural network models that are well-suited for patternclassiﬁcation tasks whose inputs and outputs are sequences.The importance of developing methods formapping sequences to sequences is exempliﬁed by tasks such as speech recognition,speech synthesis,named-entity recognition,language modelling,and machine translation.An RNN represents a sequence with a high-dimensional vector (called the hidden state) of a ﬁxeddimensionality that incorporates new observations using an intricate nonlinear function.RNNs arehighly expressive and can implement arbitrary memory-bounded computation,and as a result,they canlikely be conﬁgured to achieve nontrivial performance on difﬁcult sequence tasks.However,RNNshave turned out to be difﬁcult to train,especially on problems with complicated long-range temporalstructure – precisely the setting where RNNs ought to be most useful.Since their potential has not beenrealized,methods that address the difﬁculty of training RNNs are of great importance.We became interested in RNNs when we sought to extend the Restricted Boltzmann Machine (RBM;Smolensky,1986),a widely-used density model,to sequences.Doing so was worthwhile because RBMsare not well-suited to sequence data,and at the time RBM-like sequence models did not exist.We in-troduced the Temporal Restricted Boltzmann Machine (TRBM;Sutskever,2007;Sutskever and Hinton,2007) which could model highly complex sequences,but its parameter update required the use of crudeapproximations,which was unsatisfying.To address this issue,we modiﬁed the TRBMand obtained anRNN-RBMhybrid of similar representational power whose parameter update can be computed nearlyexactly.This work is described in Chapter 3 and by Sutskever et al.(2008).Martens (2010)’s recent work on the Hessian-Free (HF) approach to second-order optimization at-tracted considerable attention,because it solved the then-impossible problem of training deep autoen-coders from random initializations (Hinton and Salakhutdinov,2006;Hinton et al.,2006).Because ofits success with deep autoencoders,we hoped that it could also solve the difﬁcult problem of trainingRNNs on tasks with long-term dependencies.While HF was fairly successful at these tasks,we sub-stantially improved its performance and robustness using a new idea that we call structural damping.Itwas exciting,because these problems were considered hopelessly difﬁcult for RNNs unless they wereaugmented with special memory units.This work is described in Chapter 4.Having seen that HF can successfully train general RNNs,we applied it to character-level languagemodelling,the task of predicting the next character in natural text (such as in English books;Sutskeveret al.,2011).Our RNNs outperform every homogeneous language model,and are the only non-toylanguage models that can exploit long character contexts.For example,they can balance parenthesesand quotes over tens of characters.All other language models (including that of Mahoney,2005) arefundamentally incapable of doing so because they can only rely on the exact context matches from thetraining set.Our RNNs were trained with 8 GPUs for 5 days and are among the largest RNNs to date.1CHAPTER 1.INTRODUCTION 2This work is presented in Chapter 5.We then used HF to train RNNs to control a simulated limb under conditions of delayed feedbackand unpredictable disturbances (such as a temperature change that introduces friction to the joints) withthe goal of solving reaching tasks.RNNs are well-suited for control tasks,and the resulting controllerwas highly effective.It is described in Chapter 6.The ﬁnal chapter shows that a number of strongly-held beliefs about RNNs are incorrect,includingmany of the beliefs that motivated the research described in the previous chapters.We showthat gradientdescent with momentum can train RNNs to solve problems with long-term dependencies,provided theRNNs are initialized properly and an appropriate momentumschedule is used.This is surprising becauseﬁrst-order methods were believed to be fundamentally incapable of training RNNs on such problems(Bengio et al.,1994).These results are presented in Chapter 7.Chapter 2BackgroundThis chapter provides the necessary background on machine learning and neural networks that will makethis thesis relatively self-contained.2.1 Supervised LearningLearning is useful whenever we want a computer to perform a function or procedure so intricate thatit cannot be programmed by conventional means.For example,it is simply not clear how to directlywrite a computer program that recognizes speech,even in the absence of time and budget constraints.However,it is in principle straightforward (if expensive) to collect a large number of example speechsignals with their annotated content and to use a supervised learning algorithmto approximate the input-output relationship implied by the training examples.We now deﬁne the supervised learning problem.Let X be an input space,Y be an output space,and D be the data distribution over X  Y that describes the data that we tend to observe.For everydraw (x;y) fromD,the variable x is a typical input and y is the corresponding (possibly noisy) desiredoutput.The goal of supervised learning is to use a training set consisting of n of i.i.d.samples,S =f(xi;yi)gni=1 Dn,in order to ﬁnd a function f:X!Y whose test errorTestD(f)  E(x;y)D[L(f(x);y)] (2.1)is as low as possible.Here L(z;y) is a loss function that measures the loss that we suffer whenever wepredict y as z.Once we ﬁnd a function whose test error is small enough for our needs,the learningproblemis solved.Although it would be ideal to ﬁnd the global minimizer of the test errorf= arg minf is a functionTestD(f) (2.2)doing so is fundamentally impossible.We can approximate the test error with the training errorTrainS(f)  E(x;y)S[L(f(x);y)]  TestD(f) (2.3)(where we deﬁne S as the uniform distribution over training cases counting duplicate cases multipletimes) and ﬁnd a function f with a low training error,but it is trivial to minimize the training errorby memorizing the training cases.Making sure that good performance on the training set translatesinto good performance on the test set is known as the generalization problem,which turns out to be3CHAPTER 2.BACKGROUND 4conceptually easy to solve by restricting the allowable functions f to a relatively small class of functionsF:f= arg minf2FTrainS(f) (2.4)Restricting f to F essentially solves the generalization problem,because it can be shown (as we do insec.2.6) that when log jFj is small relative to the size of the training set (so in particular,jFj is ﬁnite,although similar results can be shown for inﬁnite F’s that are small in a certain sense (Vapnik,2000)),the training error is close to the test error for all functions f 2 F simultaneously.This lets us focuson the algorithmic problemof minimizing the training error while being reasonably certain that the testerror will be approximately minimized as well.The cost of restricting f to F is that the best attainabletest error may be inadequately high for our needs.Since the necessary size of the training set grows with F,we want F to be as small as possible.Atthe same time,we want F to be as large as possible to improve the performance of its best function.Inpractice,it is sensible to choose the largest possible F that can be supported by the size of the trainingset and the available computation.Unfortunately,there is no general recipe for choosing a good F for a given machine learning prob-lem.The theoretically best F consists of just one function that achieves the best test error among allpossible functions,but our ignorance of this function is the reason we are interested in learning in theﬁrst place.The more we know about the problemand about its high-performing functions,the more wecan restrict F while being reasonably sure that it contains at least one good function.In practice,it isbest to experiment with function classes that are similar to ones that are successful for related problems1.2.2 OptimizationOnce we have chosen an appropriate F and collected a sufﬁciently large training set,we are faced withthe problem of ﬁnding a function f 2 F that has a low training error.Finding the global minimizer ofthe training error for most interesting choices of F is NP-hard,but in practice there are many choicesof smoothly-parameterized Fs that are relatively easy to optimize with gradient methods.Let the function f2 F be a differentiable parameterization of F where  2 Rjjand jj is thenumber of parameters.Let us also assume that the loss L is a differentiable function of its arguments.Then the functionTrainS()  TrainS(f) = E(x;y)S[L(f(x);y)] (2.5)is differentiable.If f(x) is easy to compute,then it immediately follows that the training error TrainS()and its derivative rTrainS() can be computed at the cost of jSj evaluations of f(x) and rf(x).Inthis setting,we can use Gradient Descent (GD),which is a greedy method for minimizing arbitrary dif-ferentiable functions.Given a function F(),GDoperates as follows:1:for iterations do2:t+1trF(t) "3:t t +14:end forThe learning rate"is a tunable problem-dependent parameter that has a considerable effect on the speedof the optimization.1It is important to evaluate a given F with its performance on a set examples called the validation set which is distinct fromthe test set.Otherwise,our choice of F will be informed by the spurious regularities of the test set,which can cause seriousproblems when the test set is small.CHAPTER 2.BACKGROUND 5GD has been extensively analyzed in a number of settings.If the objective function F is a positivedeﬁnite quadratic,then GD will converge to its global minimumat a rate ofF(t) F() = O((1 1=R)t) (2.6)where is the global minimum,R is the condition number of the quadratic (given by the ratio of thelargest to the smallest eigenvalues R = max=min),provided that"= 1=max.When F is a generalconvex function,the rate of convergence can be bounded byF(t) F() k1k2"t(2.7)provided that 1="is greater than the Lipshitz coefﬁcient of rF,2which in the quadratic case is max(Nocedal and Wright,1999).This rate of convergence is valid across the entire parameter space and notjust in the neighborhood of the global minimum,and at ﬁrst sight appears to be weaker than eq.2.6 sinceit is not exponential.However,it is easy to show that when F has a ﬁnite condition number,eq.2.6 is adirect consequnce of eq.2.73.Stochastic Gradient Descent (SGD) is an important generalization of GD that is well-suited formachine learning applications.Unlike standard GD,which computes rTrainS() on the entire trainingset S,SGD uses the unbiased approximation rTrains(),where s is a randomly chosen subset of thetraining set S.The “minibatch” s can consist of as little as one training case,but using more trainingcases is more cost-effective.SGD tends to work better than GD on large datasets where each iterationof GDis very expensive,and for very large datasets it is not uncommon for SGDto converge in the timethat it takes batch GD to complete a single parameter update.On the other hand,batch GD is triviallyparallelizeable,so it is becoming more attractive due to the availability of large computing clusters.Momentummethods (Hinton,1978;Nesterov,1983) use gradient information to update the param-eters in a direction that is more effective than steepest descent by accumulating speed in directions thatconsistently reduce the cost function.Formally,a momentum method maintains a velocity vector vtwhich is updated as follows:vt+1= vt"rF(t) (2.8)t+1= t+vt+1(2.9)The momentum decay coefﬁcient  2 [0;1) controls the rate at which old gradients are discarded.Itsphysical interpretation is the “friction” of the surface of the objective function,and its magnitude has anindirect effect on the magnitude of the velocity.2The Lipshitz coefﬁcient of an arbitrary function H:Rm!Rkis deﬁned as the smallest positive real number Lsuch thatkH(x) H(y)k  Lkx yk for all x;y 2 Rm;if no such real number exists,the Lipshitz constant is deﬁned to be inﬁnite.If L  1,the function is continuous.3We can prove an even stronger statement using proof similar to that of O’Donoghue and Candes (2012):Theorem 2.2.1.If F is convex,rF is L-Lipshitz (so krF() rF(0)k  Lk 0k for all ;0),and F is -stronglyconvex (so,in particular,k k2=2  F() F() for all ,where is the minimum of F),then F(t) F() <(1 =6L)t.Note that when F is quadratic,the above condition implies that its condition number is bounded by L= (recall that"= 1=L).Proof.The deﬁnition of strong convexity gives k1 k2< 2=(F(1)  F()).Applying it into eq.2.7,we getF(t) F() < 2L=(t)(F(1) F()).Thus after t = 4L= iterations,F(t) F() < (F(1) F())=2.Sincethis bound can be applied at any point,we get that F(t) F() is halved every 4L= iterations.Algebraic manipulationsimply a convergence rate of (1 =6L)t.CHAPTER 2.BACKGROUND 6Figure 2.1:A momentum method accumulates velocity in directions of persistent reduction,whichspeeds up the optimization.A variant of momentum known as Nesterov’s accelerated gradient (Nesterov,1983,described indetail in Chap.7) has been analyzed with certain schedules of the learning rate and of the momentumdecay coefﬁcient ,and was shown by Nesterov (1983) to exhibit the following convergence rate forconvex functions F whose gradients are noiseless:F(t) F()  4k1k2"(t +2)2(2.10)where,as in eq.2.7,1="is larger than the Lipshitz constant of rF.This convergence rate is also globaland does not assume that the parameters were initialized in the neighborhood of the global minimum.4Momentum methods are faster than GD because they accelerate the optimization along directionsof low but persistent reduction,similarly to the way second-order methods accelerate the optimizationalong low-curvature directions (but second-order methods also decelerate the optimization along high-curvature directions,which is not done by momentum methods;Nocedal and Wright,1999) (ﬁg.2.1).In fact,it has been shown that when Nesterov’s accelerated gradient is used with the optimal momentumon a quadratic,its convergence rate is identical to the worst-case convergence rate of the linear conju-gate gradient (CG) as a function of the condition number (O’Donoghue and Candes,2012;Shewchuk,1994;Nocedal and Wright,1999).This may be surprising,since CG is the optimal iterative methodfor quadratics (in the sense that it outperforms any method that uses linear combinations of previously-computed gradients;although CG can be obtained from eqs.2.8-2.9 using a certain formula for (Shewchuk,1994)).Thus momentum can be seen as a second-order method that accelerates the op-timization in directions of low-curvature.They can also decelerate the optimization along the high-curvature directions by cancelling the high-frequency oscillations that cause GD to diverge.Convex objective functions F() are insensitive to the initial parameter setting,since the optimiza-tion will always recover the optimal solution,merely taking longer time for worse initializations.But,given that most objective functions F() that we want to optimize are non-convex,the initializationhas a profound impact on the optimization and on the quality of the solution.Chapter 7 shows thatappropriate initializations play an even greater role than previously believed for both deep and recurrentneural networks.Unfortunately,it is difﬁcult to design good random initializations for new models,soit is important to experiment with many different initializations.In particular,the scale of the initial-ization tends to have a large inﬂuence for neural networks (see Chap.7 and Jaeger and Haas (2004);Jaeger (2012b)).For deep neural networks (sec.2.4),the greedy unsupervised pre-training of Hintonet al.(2006),Hinton and Salakhutdinov (2006),and Bengio et al.(2007) is an effective technique forinitializing the parameters,which greedily trains parameters of each layer to model the distribution of4An argument similar to the one in footnote 3 can show that the convergence rate of a quadratic with condition numberR is (1 p1=R)t,provided that the momentum is reset to zero everypR iterations.See O’Donoghue and Candes (2012)for more details.Note that it is also the worst-case convergence rate of the linear conjugate gradient (Shewchuk,1994) as afunction of the condition number.CHAPTER 2.BACKGROUND 7activities in the layer below.2.3 Computing DerivativesIn this section,we explain how to efﬁciently compute the derivatives of any function F() that canbe evaluated with a differentiable computational graph (Baur and Strassen,1983;Nocedal and Wright,1999).In this section,the term “input” refers to the parameters rather than to an input pattern,becausewe are interested in computing derivatives w.r.t.the parameters.Consider a graph over N nodes,1;:::;N.Let I be the set of the input nodes,and let the last nodeN be the output node (the formalism allows for N 2 I,but this makes for a trivial graph).Each nodei has a set of ancestors Ai(with numbers less than i) that determine its inputs,and a differentiablefunction fiwhose value and Jacobian are easy to compute.Then the following algorithm evaluates acomputational graph:1:distribute the input  across the input nodes zifor i 2 I2:for i from1 to N if i 62 I do3:xiconcatj2Aizj4:zifi(xi)5:end for6:output F() = zNwhere every node zican be vector-valued (this includes the output node i = N,so F can be vector-valued).Thus the computational graph formalism captures nearly all models that occur in machinelearning.If we assume that our training error has the form L(F()) = L(zN) where L is the loss func-tion and F() is the vector of the model’s predictions on all the training cases,the derivative ofL(zN) w.r.t. is given by F0()>L0(zN).We now show how the backpropagation algorithm com-putes the Jacobian-vector product F0()>w for an arbitrary vector w of the dimensionality of zN:1:dzNw2:dzi0 for i < N3:for i fromN downto 1 if i 62 I do4:dxif0i(xi)> dzi5:for all j 2 Aido6:dzjdzj+unconcatjdxi7:end for8:end for9:concatenate dzifor i 2 I onto d10:output d,which is equal to F0()>wwhere unconcat is the inverse of concat:if xi= concatj2Aizj,then unconcatjxi= zj.The correct-ness of the above algorithm can be proven by structural induction over the graph,which would showthat each node dziis equal to@zN@zi>w as we descend from the node dzN,where the induction step isproven with the chain rule.By setting w to L0(zN),the algorithmcomputes the sought-after derivative.Adifferent formof differentiation known as forward differentiation computes the derivative of eachziw.r.t.a linear combination of the parameters.Given a vector v (whose dimensionality matches’s),we let Rzibe the directional derivative @zi=@  v (the notation is from Pearlmutter (1994)).Then the following algorithm computes the directional derivative of each node in the graph as fol-lows:CHAPTER 2.BACKGROUND 81:distribute the input v across the input nodes Rzifor i 2 I2:for i from1 to N if i 62 I do3:Rxiconcatj2AiRzj4:Rzif0i(xi)  Rxi5:end for6:output RzN,which is equal to F0()  vThe correctness of this algorithmcan likewise be proven by structural induction over the graph,provingthat Rzi= @zi=@  v for each i,starting fromi 2 I and reaching node zN.Unlike backward differen-tiation,forward differentiation does not need to store the state variables zi,since they can be computedtogether with Rziand be discarded once used.Thus automatic differentiation can compute the Jacobian-vector products of any function expressibleas a computational graph at the cost of roughly two function evaluations.The Theano compiler (Bergstraet al.,2010) computes derivatives in precisely this manner automatically and efﬁciently.2.4 Feedforward Neural NetworksThe Feedforward Neural Network (FNN) is the most basic and widely used artiﬁcial neural network.Itconsists of a number of layers of artiﬁcial neurons (termed units) that are arranged into a layered con-ﬁguration (ﬁg.2.2).Of particular interest are deep neural networks,which are believed to be capable ofrepresenting the highly complex functions that achieve high performance on difﬁcult perceptual prob-lems such as vision and speech (Bengio,2009).FNNs have achieved success in a number of domains(e.g.,Salakhutdinov and Hinton,2009;Glorot et al.,2011;Krizhevsky and Hinton,2011;Krizhevsky,2010),most notably in large vocabulary continuous speech recognition (Mohamed et al.,2012),wherethey were directly responsible for considerable improvements over previous highly-tuned,state-of-the-art systems.Formally,a feedforward neural network with`hidden layers is parameterized by`+ 1 weightmatrices (W0;:::;W`) and`+ 1 vectors of biases (b1;:::;b`+1).The concatenation of the weightmatrices and the biases forms the parameter vector  that fully speciﬁes the function computed bythe network.Given an input x,the feedforward neural network computes an output z as follows:1:set z0x2:for i from1 to`+1 do3:xiWi1zi1+bi4:zie(xi)5:end for6:Output z z`Here e() is some nonlinear function such as the element-wise sigmoid sigmoid(xj) = 1=(1+exp(xj)).When e() is a sigmoid function,it can be used to implement Boolean logic,which allows deep andwide feedforward neural networks to implement arbitrary Boolean circuits and hence arbitrary compu-tation subject to some time and space constraints.But while we cannot hope to always train feedforwardneural networks so deep from labelled cases alone (provably so,under certain cryptographic assump-tions (Kearns and Vazirani,1994)5),wide and slightly deep networks (3-5 layers) are often easy to trainin practice with SGD while being moderately expressive.5Intuitively,given a public key,it is easy to generate a large number of (encryption,message) pairs.If circuits werelearnable,we could learn a circuit that could map an encryption to its secret message with high accuracy (since such a circuitexists).CHAPTER 2.BACKGROUND 9Figure 2.2:The feedforward neural network.FNNs are trained by minimizing the training error w.r.t.the parameters using a gradient method,such as SGD or momentum.Despite their representational power,deep FNNs have been historically considered very hard totrain,and until recently have not enjoyed widespread use.They became the subject of intense attentionthanks to the work of Hinton and Salakhutdinov (2006) and Hinton et al.(2006),who introduced the ideaof greedy layerwise pre-training,and successfully applied deep FNNs to a number of challenging tasks.Greedy layerwise pre-training has since branched into a family of methods (Hinton et al.,2006;Hintonand Salakhutdinov,2006;Bengio et al.,2007),all of which train the layers of a deep FNN in order,one at time,using an auxiliary objective,and then “ﬁne-tune” the network with standard optimizationmethods such as stochastic gradient descent.More recently,Martens (2010) has attracted considerableattention by showing that a type of truncated-Newton method called Hessian-free optimization (HF) iscapable of training deep FNNs from certain random initializations without the use of pre-training,andcan achieve lower errors for the various auto-encoding tasks considered in Hinton and Salakhutdinov(2006).But recent results described in Chapter 7 show that even very deep neural networks can betrained using an aggressive momentumschedule fromwell-chosen randominitializations.It is possible to implement the FNN with the computational graph formalism and to use backwardautomatic differentiation to obtain the gradient (which is done if the FNN is implemented in Theano(Bergstra et al.,2010)),but it is also straightforward to programthe gradient directly:1:dz`dL(z`;y)=dz`2:for i from`+1 downto 1 do3:dxie0(xi)  dzi4:dzi1W>i1dxi5:dbidxi6:dWi1dxiz>i17:end for8:Output [dW0;:::;dW`;db1;:::;db`+1]2.5 Recurrent Neural NetworksWe are now ready to deﬁne the Recurrent Neural Network (RNN),the central object of study of thisthesis.The standard RNN is a nonlinear dynamical system that maps sequences to sequences.It is pa-rameterized with three weight matrices and three bias vectors [Whv;Whh;Woh;bh;bo;h0] whose con-CHAPTER 2.BACKGROUND 10Figure 2.3:ARecurrent Neural Network is a very deep feedforward neural network that has a layer foreach timestep.Its weights are shared across time.catenation  completely describes the RNN (ﬁg.2.3).Given an input sequence (v1;:::;vT) (which wedenote by vT1),the RNN computes a sequence of hidden states hT1and a sequence of outputs zT1by thefollowing algorithm:1:for t from1 to T do2:utWhvvt+Whhht1+bh3:hte(ut)4:otWohht+bo5:ztg(ot)6:end forwhere e() and g() are the hidden and output nonlinearities of the RNN,and h0is a vector of parametersthat store the very ﬁrst hidden state.The loss of the RNN is usually a sumof per-timestep losses:L(z;y) =TXt=1L(zt;yt) (2.11)The derivatives of the RNNs are easily computed with the backpropagation through time algorithm(BPTT;Werbos,1990;Rumelhart et al.,1986):1:for t fromT downto 1 do2:dotg0(ot)  dL(zt;yt)=dzt3:dbodbo+dot4:dWohdWoh+doth>t5:dhtdht+W>ohdot6:dzte0(zt)  dht7:dWhvdWhv+dztv>t8:dbhdbh+dzt9:dWhhdWhh+dzth>t110:dht1W>hhdzt11:end for12:Return d = [dWhv;dWhh;dWoh;dbh;dbo;dh0].2.5.1 The difﬁculty of training RNNsAlthough the gradients of the RNNare easy to compute,RNNs are fundamentally difﬁcult to train,espe-cially on problems with long-range temporal dependencies (Bengio et al.,1994;Martens and Sutskever,2011;Hochreiter and Schmidhuber,1997),due to their nonlinear iterative nature.A small change toan iterative process can compound and result in very large effects many iterations later;this is knownCHAPTER 2.BACKGROUND 11colloquially as “the butterﬂy-effect”.The implication is that in an RNN,the derivative of the loss func-tion at one time can be exponentially large with respect to the hidden activations at a much earlier time.Thus the loss function is very sensitive to small changes,so it becomes effectively discontinuous.RNNs also suffer from the vanishing gradient problem,ﬁrst described by Hochreiter (1991) andBengio et al.(1994).Consider the term@L(zT;yT)@Whh,which is easy to analyze by inspecting line 10 ofthe BPTT algorithm:@L(zT;yT)@Whh=TXt=1dzth>t1(2.12)wheredzt=

TY=t+1W>hhe0(zt)!W>ohg0(ot)@L(zT;yT)@pT(2.13)If all the eigenvalues of Whhare considerably smaller than 1,then the contributions dzth>t1to dWhhwill rapidly diminish because dzttends to zero exponentially as T t increases.The latter phenomenonis known as the vanishing gradient problem,and it is guaranteed to occur in any RNNthat can store onebit of information indeﬁnitely while being robust to at least some level of noise (Bengio et al.,1994),a condition that ought to be satisﬁed by most RNNs that perform interesting computation.A vanishingdztis undesirable,because it turns BPTT into truncated-BPTT,which is likely incapable of trainingRNNs to exploit long-termtemporal structure (see sec.2.8.6).The vanishing and the exploding gradient problems make it difﬁcult to optimize RNNs on sequenceswith long-range temporal dependencies,and are possible causes for the abandonment of RNNs by ma-chine learning researchers.2.5.2 Recurrent Neural Networks as Generative modelsGenerative models are parameterized families of probability distributions that extrapolate a ﬁnite train-ing set to a distribution over the entire space.They have many uses:good generative models of spec-trograms can be used to synthesize speech;generative models of natural language can improve speechrecognition by deciding between words that the acoustic model cannot accurately distinguish;and im-prove machine translation by evaluating the plausibility of a large number of candidate translations inorder to select the best one.An RNNdeﬁnes a generative model over sequences if the loss function satisﬁes L(zt;yt) = log p(yt;zt)for some parameterized family of distributions p(;z) and if yt= vt+1.This deﬁnes the following dis-tribution over sequences vT1:P(vtjvt11)  P(vt;zt) (2.14)P(vT1) =TYt=1P(vtjvt11) TYt=1P(vt;zt1) (2.15)where z0is an additional parameter vector that speciﬁes the distribution over the ﬁrst timestep of thesequence,v1.This equation deﬁnes a valid distribution because ztis a function of vt1and is independentof vTt+1.Samples fromP(vT1) can be obtained by sampling the conditional distribution vt P(vtjvt11)sequentially,by iterating from t = 1 to T.The loss function is precisely equivalent to the averagenegative log probability of the sequences in the training set:TrainS() = EvS[log P(v)] (2.16)CHAPTER 2.BACKGROUND 12where in this equation,the dependence of P on the parameters  is explicit.The log probability is a good objective function to optimize if we wish to ﬁt a distribution to data.Assuming the data distribution D is precisely equal to P for some and that the mapping !Pis one-to-one,it is meaningful to discuss the rate at which our parameter estimates converge to asthe size of the training set increases.In this setting,if the log probability is uniformly bounded across,the maximumlikelihood estimator (i.e.,the parameter setting maximizing eq.2.16) is known to havethe fastest possible rate of convergence among all possible ways of mapping data to parameters (in aminimax sense over the parameters) when the size of the training set is sufﬁciently large (Wasserman,2004),which justiﬁes its use.In practice,the true data distribution D cannot usually be represented byany setting of the parameters in the model P,but the average log probability objective is still used.2.6 OverﬁttingThe termoverﬁtting refers to the gap between the training error TrainS(f) and the test error TestD(f).We mentioned earlier that by restricting the functions of consideration f to a class of functions F wecontrol overﬁtting and address the generalization problem.Here we explain how limiting F accom-plishes this.Theorem 2.6.1.If F is ﬁnite and the loss is bounded L(z;y) 2 [0;1],then overﬁtting is uniformlybounded with high probability over draws S from the training set (Kearns and Vazirani,1994;Valiant,1984):PrSDjSj"TestD(f) TrainS(f) slog jFj +log 1=jSjfor all f 2 F#> 1  (2.17)The result suggests that when the training set is larger than log jFj,then every training error will beclose to every test error.The log jFj termin the bound formally justiﬁes the intuition that each trainingcase carries a constant number of bits about the best function in F.Proof.We begin with the proof’s intuition.The central limit theorem ensures that the training errorTrainS(f) is centred at TestD(f) and has Gaussian tails of size 1=pjSj (here we rely on L(z;y) 2[0;1]).This means that,for a single function,the probability that its training error deviates fromits testerror by more than log jFj=pjSj is exponentially small in log jFj.Hence the training error is fairlyunlikely to deviate by more than log jFj=pjSj for jFj functions simultaneously.This intuition can be quantiﬁed by means of a one-sided Chernoff or Hoffeding bound for a singleﬁxed f (Lugosi,2004;Kearns and Vazirani,1994;Valiant,1984):PrSDjSj[TestD(f) TrainS(f) > t]  exp(jSjt2) (2.18)Applying the union bound,we can immediately control the maximal possible overﬁtting:Pr [TestD(f) TrainS(f) > t for some f 2 F] = Pr [[f2FfTestD(f) TrainS(f) > tg]Xf2FPr [TestD(f) TrainS(f) > t] jFj exp(jSjt2)CHAPTER 2.BACKGROUND 13If we set the probability of failure Pr [TestD(f) TrainS(f) > t for some f 2 F] to ,we can obtainan upper bound for t:  jFj exp(jSjt2)log() log jFj  jSjt2log1+log jFj  jSjt2t slog 1= +log jFjjSjThe above states that with probability at least 1,there is no function f 2 F whose overﬁtting exceedsslog 1= +log jFjjSj.This is one of the simplest learning theoretic bounds (Kearns and Vazirani,1994),and althoughformally it is only applicable to ﬁnite F,we observe that it trivially applies to any implementation ofany parametric model that uses the common 32 or 64-bit ﬂoating point representation for its parameters.These implementations work with ﬁnite subsets of F that have at most 264jjdifferent elements (whichcan be RNNs,FNNs,or other models),so the theoremapplies and guarantees that such implementationswill not overﬁt if the number of labelled cases exceeds the number of its parameters by some constantfactor.Although this bound is pessimistic,it provides a formal justiﬁcation for a heuristic practice called“parameter counting”,where number of parameters is compared to the number of labels in the trainingset in order to predict the severity of overﬁtting.It should be emphasized that this theorem does not suggest that learning will necessarily succeed,since it could fail if the training error of each f 2 F is unacceptably high.It is therefore important forF to be well-chosen so that at least one of its functions achieves low training (and hence test) error.It should also be emphasized that this result does not mean that overﬁtting must occur when jSj jj.In these cases,generalization may occur for other reasons,such as the inability of the optimizationmethod to fully exploit the neural network’s capacity,or the relative simplicity of the dataset.2.6.1 RegularizationThere are several other techniques for preventing overﬁtting.A common technique is regularization,which replaces the training error TrainS() with TrainS() + R(),where R() is a function thatpenalizes “overly complex” models (as determined by some property of ).A common choice for R()is kk2=2.While the method of regularization seems to be different from working with subsets of F,it turnsout to be closely related to the use of the smaller function class F= ff:R() < g and is equivalentwhen TrainS() and R() are convex functions of .Theorem2.6.2.Assume that TrainS() and R() are smooth.Then for every local minimumofTrainS() s.t.R()   (2.19)there exists a 0such that is a local minimum ofTrainS() +0R() (2.20)CHAPTER 2.BACKGROUND 14Figure 2.4:A Restricted Boltzmann Machine.If TrainS() and R() are convex functions of ,then every local minimumis also global minimum,and as a result,the method of regularization and restriction are equivalent up to the choice of .Theirequivalence breaks down in the presence of multiple local minima.Proof.Let  be given,and let be a local minimumof eq.2.19.Then either R() <  or R() = .If R() < ,then the choice 0= 0 makes a local minimumof eq.2.20.When R() = ,consider the Lagrange function for the problemof minimizingTrainS() s.t.R() =  (2.21)which is given byL(;) = TrainS() +  (R() ) (2.22)A basic property of Lagrange functions states that if is a local minimumof eq.2.21,then there existssuch thatrL(;) = 0 (2.23)Eq.2.23 implies that rTrainS() + rR() = 0,so is a local minimum of the regularizedobjective TrainS() +R() as well.The converse (that for every local minimumof TrainS() +R() there exists a 0such that is a local minimumof TrainS() subject to R() < 0) can be proved with a similar method.2.7 Restricted Boltzmann MachinesThe Restricted Boltzmann Machine,or RBM,is a parameterized family of probability distributions overbinary vectors.It deﬁnes a joint distribution over v 2 f0;1gNvand h 2 f0;1gNhvia the followingequation (ﬁg.2.4):P(v;h)  P(v;h) exph>Wv +v>bv+h>bhZ()(2.24)where the partition function Z() is given byZ() =Xv2f0;1gNvXh2f0;1gNhexph>Wv +v>bv+h>bh(2.25)Here  = [W;bv;bh] is the parameter vector.Thus each setting of  has a corresponding RBMdistribu-tion P.CHAPTER 2.BACKGROUND 15The partition function Z() is an sum of exponentially many terms and cannot be efﬁciently ap-proximated to a constant multiplicative factor unless P = NP (Long and Servedio,2010).This makesthe RBM difﬁcult to handle,because we cannot evaluate the RBM’s objective function and measurethe progress of learning.Nevertheless,it enjoys considerable popularity despite its intractability fortwo reason:ﬁrst,the RBMcan learn excellent generative models,and its samples often “look like” thetraining (and test) data (Hinton,2002);and second,the RBM plays an important role in the trainingof Deep Belief Networks (Hinton et al.,2006;Hinton and Salakhutdinov,2006),by acting as a goodinitialization for the FNN.The ease of posterior inference is another attractive feature since the distri-butions P(hjv) and P(vjh) are product distributions (or factorial distributions) and have the followingsimple form(recall that sigmoid(x) = 1=(1 +exp(x))):P(hi= 1jv) = sigmoid((Wv +bh)i) (2.26)P(vj= 1jh) = sigmoid((W>h +bv)j) (2.27)To derive these equations,let t = Wv +bhand c =1Z()P(v)exp(v>bv):P(hjv) = P(h;v)=P(v) (2.28)= exph>(Wv +bh) +v>bv1Z()P(v)= exph>t c (2.29)= exp

NhXi=1hi ti! c =NhYi=1exp(hiti)  c (2.30)Thus P(hjv) is a product distribution.By treating eq.2.30 as a function of hi2 f0;1g and normalizingit so that it sums to 1 over its domain f0;1g,we getP(hijv) =exp(ti hi)  cexp(ti 0)  c +exp(ti 1)  c=1exp(ti (0 hi)) +exp(ti (1 hi))=11 +exp(ti ([[hi= 0]] [[hi= 1]]))= sigmoid(ti (2hi1))= sigmoid((Wv +bh)i (2hi1)) (2.31)where [[X]] is 1 if X is true and 0 otherwise.A similar derivation applies to the other conditionaldistribution.As a generative model,the RBM can be trained by maximizing the average log probability of atraining set S:TrainS() = EvS[log P(v)] (2.32)We will maximize the RBM’s average log probability with a gradient method,so we need to computethe derivative w.r.t.the RBM’s parameters.Letting G(v;h) = h>Wv +b>vv +b>hh and noticing thatCHAPTER 2.BACKGROUND 16P(v;h) = exp(G(v;h))=Z(),we can compute the derivatives of TrainS() w.r.t.W as follows:rWTrains() = EvS[rWlog P(v)] = EvS"rWlogXhP(v;h)#= EvS"rWlogXhexp(G(v;h)) rWlog Z()#= EvSrWPhexp(G(v;h))Ph0exp(G(v;h0))rWlogXv;hexp(G(v;h))= EvS"Xhexp(G(v;h))rWG(v;h)Ph0exp(G(v;h0))#Pv;hrWexp(G(v;h))Pv0;h0exp(G(v0;h0))= EvS"XhP(hjv)rWG(v;h)#Xv;hexp(G(v;h))rWG(v;h)Pv0;h0exp(G(v0;h0))= EvSEhP(jv)[rWG(v;h)]Xv;hP(v;h)rWG(v;h)= EvS;hP(jv)[rWG(v;h)] Ev;hP[rWG(v;h)]We ﬁnish by noticing that rWG(v;h) = hv>.An identical derivation yields the derivatives w.r.t.thebiases,where we use rbhG(v;h) = h and rbvG(v;h) = v.These derivatives consist of expectations that can be approximated using unbiased samples fromS(v)P(hjv) and P(v;h).Unsurprisingly,it is difﬁcult to do,because the objective can be estimated byan integral of unbiased derivative estimates.Indeed (assuming P 6=#P),there is no efﬁcient methodfor drawing approximately-unbiased samples from P(v;h) that is valid for every setting of the RBM’sparameters (Long and Servedio,2010).Nonetheless,it is possible to train RBMs reasonably well with Contrastive Divergence (CD).CDis an approximate parameter update (Hinton,2002) that works well in practice.CD computes a pa-rameter update by replacing the model distribution P(hjv)P(v),which is difﬁcult to sample,with thedistribution P(hjv)Rk(v) which is easy to sample.Rk(v) is sampled by running a Markov chain that isinitialized to the empirical data distribution S and is followed by k-steps of some transition operator Tthat converges to the distribution P(v):1:randomly pick v0fromthe training set S2:for i from1 to k do3:vi T(jvi1)4:end for5:return vkThe above algorithmcomputes a sample fromRk.The value of k is arbitrary,since k steps of a transitionoperator T(jv) can be combined to one step of the transition operator Tk(jv).However,it is customaryto use the term“CDk” to a CD update that is based on k steps of the above algorithmwith some simpleT.As k!1,the Markov chain T converges to P,and hence Rk!P.Consequently,the qual-ity of the parameter updates computed by CD increases,although the beneﬁt of increasing k quicklydiminishes.The partition function of RBMs was believed to be difﬁcult to estimate in practical settings untilSalakhutdinov and Murray (2008) applied Annealed Importance Sampling (Neal,2001) to obtain anunbiased estimate of it.Their results showed that CD1is inferior to CD3,which in turn is inferior toCHAPTER 2.BACKGROUND 17CD25for ﬁtting RBMs to the MNIST dataset.Thus the best generative models can be obtained onlywith fairly expensive parameter updates that are derived fromCD.Note that it is possible that the resultsof Salakhutdinov and Murray (2008) have substantial variance and that the true value of the partitionfunction is much larger than reported,but there is currently no evidence that it is the case.The RBMcan be slightly modiﬁed to allow the vector v to take real values;one way of achievingthis is by modifying the RBM’s deﬁnition as follows:P(v;h) =exp(kvk2=22+v>bv+h>bh+h>Wv)Z()(2.33)This equation does not change the form of the gradients and the conditional distribution P(hjv).Theonly change it introduces is in the conditional distribution P(vjh),which is now equal to a multivariateGaussian with parameters N((bv+W>h)2;I2).See Welling et al.(2005) and Taylor et al.(2007)for more details and generalizations.2.7.1 Adding more hidden layers to an RBMIn this section we describe how to improve an ordinary RBMby introducing additional hidden layers,and creating a “better” representation of the data,as described by Hinton et al.(2006).This is useful formaking the model more powerful and for allowing features of features.Let P(v;h) denote the joint distribution deﬁned by the RBM.The idea is to get another RBM,Q(h;u),which has h as its visible and u as its hidden variables,to learn to model the aggregatedposterior distribution,~Q(h),of the ﬁrst RBM:~Q(h) XvP(hjv)S(v):(2.34)When a single RBM is not an adequate model for v,the aggregated posterior~Q(h) typically hasmany regularities that can be modelled with another model.Thus provided Q(h) approximates~Q(h)better than P(h) does,it can be shown that the augmented model MPQ(v;h;u) = P(vjh)Q(h;u) is abetter model of the original data than the distribution P(v;h) deﬁned by the ﬁrst RBM alone (Hintonet al.,2006).It follows from the deﬁnition that MPQ(v;h;u) uses the undirected connections learnedby Qbetween h and u,but it uses directed connections fromh to v.It thus inherits P(vjh) fromthe ﬁrstRBMbut discards P(h) from its generative model.Data can be generated from the augmented modelby sampling from Q(h;u) by running a Markov chain,discarding the value of u,and then samplingfrom P(vjh) (in a single step) to obtain v.Provided Nu Nv,the RBMQ can be initialized by usingthe parameters from P to ensure that the two RBMs deﬁne the same distribution over h.Starting fromthis initialization,optimization then ensures that Q(h) models~Q(h) better than P(h) does.The second RBM,Q(h;u),learns by ﬁtting the distribution~Q(h),which is not equivalent to max-imizing log MPQ(v).Nevertheless,it can be proved (Hinton et al.,2006) that this learning proceduremaximizes a variational lower bound on log MPQ(v).Even though MPQ(v;h;u) does not involve theconditional P(hjv),we can nonetheless approximate the posterior distribution MPQ(hjv) by P(hjv).Applying the standard variational bound (Neal and Hinton,1998),we getL  EP(hjv);vS[log Q(h)P(vjh)] +HvS(P(hjv)):(2.35)where H(P(hjv)) is the entropy of P(hjv).Maximizing this lower bound with respect to the parametersof Q whilst holding the parameters of P and the approximating posterior P(hjv) ﬁxed is preciselyequivalent to ﬁtting Q(h) to~Q(h).Note that the details of Q are unimportant;Q could be any modeland not an RBM.The main advantage of using another RBM is that it is possible to initialize Q(h)CHAPTER 2.BACKGROUND 18to be equal to P(h),so the variational bound starts as an equality and any improvement in the boundguarantees that MPQ(v) is a better model of the data than P(v).This procedure can be repeated recursively as many times as desired,creating very deep hierarchicalrepresentations.For example,a third RBM,R(u;x) can be used to model the aggregated approximateposterior over u obtained by~R(u) =XvXhQ(ujh)P(hjv)S(v):(2.36)Provided R(u) is initialized to be the same as Q(u),the distribution MPQR(h) will be a better modelof~Q(h) than Q(h),but this does not mean that MPQR(v) is necessarily a better model of S(v) thanMPQ(v).It does mean,however,that the variational lower bound using P(hjv) and Q(ujh) to approx-imate the posterior distribution MPQR(ujv) will be equal to the variational lower bound to MPQ(v) ofeq.2.35,and learning R will further improve this variational bound.2.8 Recurrent Neural Network Algorithms2.8.1 Real-Time Recurrent LearningReal-Time Recurrent Learning (RTRL;Williams and Zipser,1989) is an elegant forward-pass onlyalgorithmthat computes the derivatives of the RNNw.r.t.its parameters at each timestep.Unlike BPTT,which requires an entire forward and a backward pass to compute a single parameter update,RTRLmaintains the exact derivative of the loss so far at each timestep of the forward pass,without a backwardpass and without the need to store the past hidden states.This property allows it to update the parametersafter each timestep,which makes the learning “online” (as opposed to the “batch” learning of BPTT thatrequires an entire forward and a backward pass before the parameters can be updated.Sadly the computational cost of RTRL is prohibitive,as it uses jj concurrent applications of for-ward differentiation,each of which obtains the derivative of the cumulative loss w.r.t.a single parameterat every timestep.It requires jj=2 times more computation and jj=T more memory than BPTT.Al-though it is possible to make RTRL time-efﬁcient with the aid of parallelization,the amount of resourcesrequired to do so is prohibitive.2.8.2 Skip ConnectionsThe vanishing gradients problem is one of the main difﬁculties in the training of RNNs.To mitigate it,we could reduce the number of nonlinearities separating the relevant past information from the currenthidden unit by introducing direct connections between the past and the current hidden state.Doing soreduces the number of nonlinearities in the shortest path which makes the learning problemless “deep”and therefore easier.One of the earlier uses of skip connections was in the Nonlinear AutoRegressive with eXogenousinputs method (NARX;Lin et al.,1996),where they improved the RNN’s ability to infer ﬁnite statemachines.They were also successfully used by the Time-Delay Neural network (TDNN;Waibel et al.,1989),although the TDNN was not recurrent and could process temporal information only with the aidof the skip connections.2.8.3 Long Short-TermMemoryLong Short-Term Memory (LSTM;Hochreiter and Schmidhuber,1997) is an RNN architecture thatelegantly addresses the vanishing gradients problem using “memory units”.These linear units have aCHAPTER 2.BACKGROUND 19self-connection of strength 1 and a pair of auxiliary “gating units” that control the ﬂow of informationto and from the unit.When the gating units are shut,the gradients can ﬂow through the memory unitwithout alteration for an indeﬁnite amount of time,thus overcoming the vanishing gradients problem.While the gates never isolate the memory unit in practice,this reasoning shows that the LSTMaddressesthe vanishing gradients problemin at least some situations,and indeed,the LSTMeasily solves a numberof synthetic problems with pathological long-range temporal dependencies that were previously believedto be unsolvable by standard RNNs.6LSTMs were also successfully applied to speech and handwrittentext recognition (Graves and Schmidhuber,2009,2005),robotic control (Mayer et al.,2006),and tosolving Partially-Observable Markov Decision Processes (Wierstra and Schmidhuber,2007;Dung et al.,2008).We now deﬁne the LSTM.Let N be the number of memory units of the LSTM.At each timestept,the LSTM maintains a set of vectors,described in table 2.1,whose evolution is governed by thefollowing equations:ht= tanh(Whhht1+Whvvt+Whm~mt1) (2.37)igt= sigmoid(Wighht+Wigvvt+Wigm~mt1) (2.38)it= tanh(Wihht+Wivvt+Wim~mt1) (2.39)ot= sigmoid(Wohht+Wovvt+Wom~mt1) (2.40)ft= sigmoid(bf+Wfhht+Wfvvt+Wfm~mt1) (2.41)mt= mt1ft+itigtthe input gate allows the memory unit to be updated (2.42)~mt= mtotthe output gate determines if information can leave the unit (2.43)zt= g(Wyhht+Wym~mt) (2.44)The product  denotes element-wise multiplication.Eqs.2.37-2.41 are standard RNN equations,buteqns.2.42-2.43 are the main LSTM-speciﬁc equations deﬁning the memory units that describe how theinput and output gates guard the contents of the memory unit.They also describe how the forget gatecan make the memory unit forget its contents.The gating units are implemented by multiplication,so it is natural to restrict their domain to [0;1]N,which corresponds to the sigmoid nonlinearity.The other units do not have this restriction,so the tanhnonlinearity is more appropriate.We have included an explicit bias bffor the forget gates because it is important for them to beapproximately 1 at the early stages of learning,which is accomplished by initializing bfto a large value(such as 5).If it is not done,it will be harder to learn long range dependencies because the smallervalues of the forget gates will create a vanishing gradients problem.Since the forward pass of the LSTMis relatively intricate,the equations for the correct derivativesof the LSTMare highly complex,making them tedious to implement.Fortunately,LSTMs can now beeasily implemented with Theano,which can compute arbitrary derivatives efﬁciently (Bergstra et al.,2010).2.8.4 Echo-State NetworksThe Echo-State Network (ESN;Jaeger and Haas,2004) is a standard RNN that is trained with the ESNtraining method,which learns neither the input-to-hidden nor the hidden-to-hidden connections,but setsthem to draws from a well-chosen distribution,and only uses the training data to learn the hidden-to-output connections.6We discovered (in Chap.7) that standard RNNs are capable of learning to solve these problems provided they use anappropriate randominitializaiton.CHAPTER 2.BACKGROUND 20variable namedescriptionigt[0;1]N-valued vector of input gatesit[1;1]N-valued vector of inputs to the memory unitsot[0;1]N-valued vector of output gatesft[0;1]N-valued vector of the forget gatesvtRv-valued input vectorht[1;1]h-valued conventional hidden statemtRN-valued state of the memory units~mtRN-valued memory state available to the rest of the LSTMztthe output vectorTable 2.1:A list and a description of the variables used by the LSTM.It may at ﬁrst seem surprising that an RNN with random connections can be effective,but randomparameters have been successful in several domains.For example,randomprojections have been used inmachine learning,hashing,and dimensionality reduction (Datar et al.,2004;Johnson and Lindenstrauss,1984),because they have the desirable property of approximately preserving distances.And,morerecently,randomweights have been shown to be effective for convolutional neural networks on problemswith very limited training data (Jarrett et al.,2009;Saxe et al.,2010).Thus it should not be surprisingthat randomconnections are effective at least in some situations.Unlike randomprojections or convolutional neural networks with randomweights,RNNs are highlysensitive to the scale of the randomrecurrent weight matrix,which is a consequence of the exponentialrelationship between the scale and the evolution of the hidden states (most easily seen when the hiddenunits are linear).Too small recurrent connections cause the hidden state to have almost no memory ofits past inputs,while too large recurrent connections cause the hidden state sequence to be chaotic anddifﬁcult to decode.But when the recurrent connections are sparse and are scaled so that their spectralradius is slightly less than 1,the hidden state sequence remembers its inputs for a limited but nontrivialnumber of timesteps while applying many random transformations to it,which are often useful forpattern recognition.Some of the most impressive applications of ESNs are to problems with pathological long rangedependencies (Jaeger,2012b).It turns out that the problems of Chapter 4 can easily be solved with anESN that has several thousand hidden units,provided the ESN is initialized with a semi-randominitial-ization that combines the correctly-scaled randominitialization with a set of manually ﬁxed connectionsthat implement oscillators with various periods that drive the hidden state.7Despite its impressive performance on the synthetic problems from Martens and Sutskever (2011),the ESN has a number of limitations.Its capacity is limited because its recurrent connections are notlearned,so it cannot solve data-intensive problems where high-performing models must have millions ofparameters.In addition,while ESNs achieve impressive performance on toy problems (Jaeger,2012b),7ESNs can trivially solve other problems with pathological long range dependencies using explicit integration units,whosed dynamics are given byht= ht1+(1 ) tanh(Whhht1+Wvhvt) (2.45)However,explicit integration trivializes most of the synthetic problems from Martens and Sutskever (2011) (see Jaeger(2012b)),since if Whhis set to zero and  is set to nearly 1,then hT (1  )PTt=1tanh(Wvhvt),and simple choicesof the scales of Wvhmake it trivial for hTto represent the solution.However,integration is not useful for the memorizationproblems of Chapter 4,and when integration is absent (or ineffective),the ESN must be many times larger than the smallestequivalent standard RNN that can learn to solve these problems (Jaeger,2012a).CHAPTER 2.BACKGROUND 21Figure 2.5:A diagram of the alignment computed by CTC.A neural network makes a predictioneach timestep of the long signal.CTC aligns the network’s predictions to the target label (“hello” inthe ﬁgure),and reinforces this alignment with gradient descent.The ﬁgure also shows the network’sprediction of the blank symbol.The matrix in the ﬁgure represents the S matrix from the text,whichrepresents a distribution over the possible alignments of the input image to the label.the size of high-performing ESNs grows very quickly with the information that the hidden state needs tocarry.For example,the 20-bit memorization problem(Chap.7) requires an ESNwith at least 2000 units(while being solvable by RNNs that have 100 units whose recurrent connections are allowed to adapt;Chapter 4).Similarly,the ESN that achieves nontrivial performance on the TIMIT speech recognitionbenchmark used 20,000 hidden units (Triefenbach et al.,2010),and it is likely that ESNs achievingnontrivial performance on language modelling (Sutskever et al.,2011;Mikolov et al.,2010,2011) willrequire even larger hidden states due to the information-intensive nature of the problem.This explana-tion is consistent with the performance characteristics of random convolutional networks,which excelonly when the number of labelled cases is very small,so systems that adapt all the parameters of theneural network lose because of overﬁtting.But while ESNs do not solve the problem of RNN training,their impressive performance suggeststhat an ESN-based initialization could be successful.This is conﬁrmed by the results of Chapter 7.2.8.5 Mapping Long Sequences to Short SequencesOur RNN formulation assumes that the length of the input sequence is equal to the length of the outputsequence.It is a fairly severe limitation,because most sequence pattern recognition tasks violate thisassumption.For example,in speech recognition,we may want to map long sequence of frames (whereeach frame is a spectrogram segment that can span between 50-200 ms) to the much shorter phonemesequence or the even shorter character sequence of the correct transcription.Furthermore,the length ofthe target sequence need not directly depend on the length of the input sequence.The problem of mapping long sequences to short sequences has been addressed by Bengio (1991);CHAPTER 2.BACKGROUND 22Bottou et al.(1997);LeCun et al.(1998),using dynamic programming techniques,which was suc-cessfully applied to handwritten text recognition.In this section,we focus on Connectionist SequenceClassiﬁcation (CTC;Graves et al.,2006),which is a more recent embodiment of the same idea.It hasbeen used with LSTMs to obtain the best results for Arabic handwritten text recognition (Graves andSchmidhuber,2009) and the best performance on the slightly easier “online text recognition” problem(where the text is written on a touch-pad) (Graves et al.,2008).CTC computes a gradient by aligning the network’s predictions (a long sequence) with the targetsequence (a short sequence),and uses the alignent to provide a target for each timestep of the RNN(ﬁg.2.5).This idea is formalized probabilistically as follows.Let there be K distinct output labels,f1;:::;Kg for each timestep,and suppose that the RNN (or the LSTM) outputs a sequence of T pre-dictions.The prediction of each timestep t is a distribution over the K+1 labels (p1t;:::;pKt;pBt) whichincludes the K output labels and a special blank symbol Bwhich represents the absence of a prediction.CTC deﬁnes a distribution over sequences (l1;:::;lM) (where each symbol li2 f1;:::;Kg and whoselength is M  T):P(ljp) =X1i1<:::<lMTMYj=1pljijYm62fi1;:::;iMgpBm(2.46)In other words,CTC deﬁnes a distribution over label sequences P(ljp) which is obtained by indepen-dently sampling a symbol at each timestep t and dropping all the blank symbols B.We nowshowthat log P(ljp) can be efﬁciently computed with dynamic programming,so its deriva-tives can be obtained with automatic differentiation.Recalling that the length of p is T and of l is M,the idea is to construct a matrix S of size (M +1) (T +1) whose indicies start with 0,so that everymonotonic path fromthe bottom-left entry up to the top-right entry corresponds to an alignment of p tol (ﬁg.2.5).The entries of the matrix for m> 0 and t > 0 are given by the expressionSm;t=X1i1<:::<lmtmYj=1pljijYj62fi1;:::;img;jtpBj(2.47)It is a useful matrix because its top-right entry satisﬁes SM;T= P(ljp) and because it is efﬁcientlycomputable with dynamic programming:S0;0= 1 (2.48)Sm;0= 0 m> 0 (2.49)S0;t= pBt S0;t1t > 0 (2.50)Sm;t= pBt Sm;t1+plmt Sm1;t1(2.51)The S matrix encodes a distribution over alignments,and its gradient reinforces those alignments thathave a relatively high probability.Thus CTC is a latent variable model (with the alignment being thelatent variable) based on the EMalgorithm.Unfortunately,it is not obvious how CTC could be implemented with neural network-like hardwaredue to the need to store a large alignment matrix in memory.Hence it is worth devising more neurally-plausible approaches to alignment,based on the CTC or otherwise.At prediction time we need to solve the decoding problem,which is the problem of computing theMAP predictionarg maxlP(ljp) (2.52)Unfortunately the problemis intractable because it is necessary to use dynamic programming to evaluateP(ljp) for a single l,so classical search techniques such as beam-search are used for approximatedecoding (Graves et al.,2006).CHAPTER 2.BACKGROUND 232.8.6 Truncated Backpropagation Through TimeTruncated backpropagation (Williams and Peng,1990) is arguably the most practical method for trainingRNNs.The earliest use of truncated BPTT was by Elman (1990),and since then truncated-BPTT hassuccessfully trained RNNs on word-level language modelling (Mikolov et al.,2010,2011,2009) thatachieved considerable improvements over much larger N-grammodels.One of the main problems of BPTT is the high cost of a single parameter update,which makesit impossible to use a large number of iterations.For instance,the gradient of an RNN on sequencesof length 1000 costs the equivalent of a forward and a backward pass in a neural network that has1000 layers.The cost can be reduced with a naive method that splits the 1000-long sequence into 50sequences (say) each of length 20 and treats each sequence of length 20 as a separate training case.This is a sensible approach that can work well in practice,but it is blind to temporal dependenciesthat span more than 20 timesteps.Truncated BPTT is a closely related method that has the same per-iteration cost,but it is more adept at utilizing temporal dependencies of longer range than the naivemethod.It processes the sequence one timestep at a time,and every k1timesteps,it runs BPTT for k2timesteps,so a parameter update can be cheap if k2is small.Consequently,its hidden states have beenexposed to many timesteps and so may contain useful information about the far past,which would beopportunistically exploited.This cannot be done with the naive method.Truncated BPTT is given below:1:for t from1 to T do2:Run the RNN for one step,computing htand zt3:if t divides k1then4:Run BPTT (as described in sec.2.5),fromt down to t k25:end if6:end forChapter 3The Recurrent Temporal RestrictedBoltzmann MachineIn the ﬁrst part of this chapter,we describe a new family of non-linear sequence models that are sub-stantially more powerful than hidden Markov models (HMM) or linear dynamical systems (LDS).Ourmodels have simple approximate inference and learning procedures that work well in practice.Mul-tilevel representations of sequential data can be learned one hidden layer at a time,and adding extrahidden layers improves the resulting generative models.The models can be trained with very high-dimensional,very non-linear data such as raw pixel sequences.Their performance is demonstratedusing synthetic video sequences of two balls bouncing in a box.In the second half of the chapter,weshow how to modify the model to make it easier to train by introducing a deterministic hidden state that