Imported from https://github.com/hardmaru/write-rnn-tensorflow