import tensorflow as tf

                average_across_timesteps=False,
                average_across_batch=True)

            self._cost = tf.reduce_sum(loss)
            self._final_state = state

            if not is_training:
                return

            self._lr = tf.Variable(0., trainable=False)
            tvars = tf.trainable_variables()
            grads, _ = tf.clip_by_global_norm(tf.gradients(self._cost, tvars),
                                          config.max_grad_norm)
            optimizer = tf.train.GradientDescentOptimizer(self._lr)
            self._train_op = optimizer.apply_gradients(
                zip(grads, tvars),
                global_step=tf.train.get_or_create_global_step())

            self._new_lr = tf.placeholder(
                tf.float32, shape=[], name='new_learning_rate')
            self._lr_update = tf.assign(self._lr, self._new_lr)

            self.saver = tf.train.Saver(tf.global_variables())

    def _get_lstm_cell(self, config, is_training):
        if config.rnn_mode == BASIC:
