Home

Awesome

Recurrent Highway Networks

Note: For Tensorflow 1.0, please use this branch.

What?

This repository contains code accompanying the paper Recurrent Highway Networks (RHNs). RHNs are an extension of Long Short Term Memory Networks with forget gates to enable the learning of deep recurrent state transitions. We provide implementations in Tensorflow, Torch7 and Brainstorm libraries, and welcome additional implementations from the community.

Why?

The recurrent state transition in typical recurrent networks is modeled with a single step non-linear function. This can be very inefficient in principle for modeling complicated transitions, requiring very large networks. Increased recurrence depth allows RHNs to model complex transitions more efficiently achieving substantially improved results.

Moreover, using depth d in the recurrent state transition is much more powerful than stacking d recurrent layers. The figures below illustrate that if we consider the functions mapping one hidden state to another T time steps apart, its maximum depth scales as the product of d and T instead of the sum. Of course, in general RHNs can also be stacked to get the best of both worlds.

Stacked RNNDeep Transition RNN
Stacked RNNDeep Transition RNN

RHN Benchmarks reproducible with the provided code

Influence of recurrence depth on performance

The score (perplexity) of word-level language models on the Penn Treebank dataset dramatically improves as recurrence depth increases while keeping the model size fixed. WT refers to tying the input and output weights for regularization. This idea was independently developed by Inan and Khosravi and Press and Wolf. Recently, Inan et al. also posted a more detailed follow-up paper.

Rec. depth#Units/LayerBest ValidationTestBest Validation (WT)Test (WT)
1127592.489.293.290.6
2118079.076.376.975.1
3111075.072.672.770.6
4105073.370.970.868.6
5100072.069.869.767.7
696071.969.369.166.6
792071.768.768.766.4
889071.268.568.266.1
986071.368.568.166.0
1083071.368.368.366.0

Comparison to SOTA language models on Penn Treebank

NetworkSizeBest ValidationTest
LSTM+dropout66 M82.278.4
Variational LSTM66 M77.375.0
Variational LSTM with MC dropout66 M-73.4
Variational LSTM + WT51 M75.873.2
Pointer Sentinel LSTM21 M72.470.9
Ensemble of 38 large LSTMs+dropout66 M per LSTM71.968.7
Ensemble of 10 large Variational LSTMs66 M per LSTM-68.7
Variational RHN (depth=8)32 M71.268.5
Variational RHN + WT (depth=10)23 M67.965.4
Variational RHN + WT with MC dropout (depth=5)*22 M-64.4

*We used 1000 samples for MC dropout as done by Gal for LSTMs, but we've only evaluated the depth 5 model so far.

Wikipedia (enwik8) next character prediction modeling

NetworkNetwork sizeTest BPC
Grid-LSTM16.8 M1.47
MI-LSTM17 M1.44
mLSTM21 M1.42
Layernorm HyperNetworks27 M1.34
Layernorm HM-LSTM35 M1.32
RHN - Rec. depth 523 M1.31
RHN - Rec. depth 1021 M1.30
Large RHN - Rec. depth 1046 M1.27

Wikipedia (text8) next character prediction modeling

NetworkNetwork sizeTest BPC
MI-LSTM17 M1.44
mLSTM10 M1.40
BN LSTM16 M1.36
HM-LSTM35 M1.32
Layernorm HM-LSTM35 M1.29
RHN - Rec. depth 1020 M1.29
Large RHN - Rec. depth 1045 M1.27

CODE

Tensorflow

Tensorflow code for RHNs is built by heavily extending the LSTM language modeling example provided in Tensorflow. It supports Variational RHNs as used in the paper, which use the same dropout mask at each time step and at all layers inside the recurrence. Note that this implementation uses the same dropout mask for both the H and T non-linear transforms in RHNs while the Torch7 implementation uses different dropout masks for different transformations. The Theano implementation can be configured either way.

Requirements

We recommend installing Tensorflow in a virtual environment. In addition to the usual Tensorflow dependencies, the code uses Sacred so you need to do:

$ pip install sacred

Usage

To reproduce SOTA results on Penn Treebank:

$ python rhn_train.py with ptb_sota

To reproduce SOTA results on enwik8/text8 (Wikipedia), first download the dataset from http://mattmahoney.net/dc/enwik8.zip or for text8 http://mattmahoney.net/dc/text8.zip and unzip it into the data directory, then run:

$ python rhn_train.py with enwik8_sota

or

$ python rhn_train.py with text8_sota

Change some hyperparameters and run:

$ python rhn_train.py with ptb_sota depth=20

This is a Sacred experiment, so you check the hyperparameter options using the print_config command, e.g.

$ python rhn_train.py print_config with ptb_sota

Torch7

Torch7 code is based on Yarin Gal's adaptation of Wojciech Zaremba's code implementing variational dropout. The main additions to Gal's code are the Recurrent Highway Network layer, the initial biasing of T-gate activations to facilitate learning and a few adjustments to other network parameters such as rnn_size and dropout probabilities.

Requirements

We recommend installing Torch from the official website. To ensure the code runs some packages need to be installed:

$ luarocks install nngraph 
$ luarocks install cutorch
$ luarocks install nn
$ luarocks install hdf5

Usage

$ th torch_rhn_ptb.lua

To run on the enwik8 dataset, first download and prepare the data (see data/README for details):

$ cd data
$ python create_enwik8.py

Then you can train by running:

$ th toch_rhn_enwik8.lua

Theano

The Theano code's configuration and usage is similar to that of the Tensorflow code. In this implementation two configuration options were added:

The following isn't implemented:

Requirements

Theano and Sacred.

Usage

As with the Tensorflow code, the SOTA results on Penn Treebank and on enwik8 (Wikipedia) can be reproduced:

$ python theano_rhn_train.py with ptb_sota
$ python theano_rhn_train.py with enwik8_sota

Brainstorm

An RHN layer implementation is also provided in Brainstorm. This implementation does not use variational dropout. It can be used in a Brainstorm experiment by simply importing HighwayRNNCoupledGates from brainstorm_rhn.py.

Citation

If you use RHNs in your work, please cite us:

@article{zilly2016recurrent,
  title="{Recurrent Highway Networks}",
  author={Zilly, Julian Georg and Srivastava, Rupesh Kumar and Koutn{\'\i}k, Jan and Schmidhuber, J{\"u}rgen},
  journal={arXiv preprint arXiv:1607.03474},
  year={2016}
}

License

MIT License.