Imported from https://github.com/tensorflow/tensor2tensor