based on the loss, use SGD to update parameter
(self)
| 240 | return xentropy - normalizing |
| 241 | |
| 242 | def train(self): |
| 243 | """based on the loss, use SGD to update parameter""" |
| 244 | learning_rate = tf.train.exponential_decay(self.learning_rate, self.global_step, self.decay_steps, |
| 245 | self.decay_rate, staircase=True) |
| 246 | self.learning_rate_=learning_rate |
| 247 | #noise_std_dev = tf.constant(0.3) / (tf.sqrt(tf.cast(tf.constant(1) + self.global_step, tf.float32))) #gradient_noise_scale=noise_std_dev |
| 248 | train_op = tf_contrib.layers.optimize_loss(self.loss_val, global_step=self.global_step, |
| 249 | learning_rate=learning_rate, optimizer="Adam",clip_gradients=self.clip_gradients) |
| 250 | return train_op |
| 251 | |
| 252 | #:param s_t: vector representation of current input(is a sentence). shape:[batch_size,sequence_length,embed_size] |
| 253 | #:param h: value(hidden state).shape:[hidden_size] |