Introduces the concept of feedback with Neural networks from past states and the notion of timestep. RNNs are represented as computational DAGs.
Adds a state variable h (hidden unit), and the operation of the layer depends on its state. State is updated at every time step. can be arbitrary differentiable functions (required for backpropagation).
Backpropagation through time: our goal is to compute MLE of the parameters by solving . To compute the MLE, we need the gradients of the loss wrt parameters. Consider a general parameterized RNN model
- Loss can be written as: and we need to compute , and is just flattened version of .
- Using chain rule, this can be calculated, and takes to compute overall and thus, need to truncated at some time step to maintain computable tracatability.
- Exploding and vanishing gradients: We are multiplying by the jacobian to compute backpropagation at each time step (consider the gradient of and where is gradient of the nonlinearity). If the gradients are high or low, it can result in exploding and vanishing gradients respectively.
LSTM
Much better introduction by Chris Olah.
- Avoids the vanishing/exploding gradient problem.
- LSTM adds a memory cell that is controlled using three gates output gate , Input gate , and forget gate . Each serves a specific purpose:
- Output: determines what gets reads out from the input and hidden state.
- Input: determines what gets reads in.
- Forget: determines when to reset the cell.
- Each gate is composed of a sigmoid NN and a pointwise multiplication. Sigmoid controls when to switch something on and off, and pointwise multiplication uses the sigmoid output for switching operation. A “1” keeps something, and “0” corresponds to removing it.
- Let’s first write the computation equations, and then understand them:
- At the first step, . This means, we use the forget gate output to forget some of the information from the cell state.
- At the second step , we use the output from input gate which scales the information as per its importance, and use the candidate memory to select the new candidate values that could be added to the state.
- Our memory is updated at this point, and LSTM now decides what to output.
- Output gate decides what gets read out from the input and hidden state, and is transformed with the cell state to compute the next hidden state:
GRU
GRU combines forget and input gate into a single “update” gate . And also merges cell and hidden state.
Beam search
Compute top K candidate outputs at each step, and expand each one in V possible ways, to generate VK candidates. Select top K again.
- Stochastic beam search samples top K without replacement, i.e. pick the top one, renormalize, and pick the new top one.