based on the loss, use SGD to update parameter
(self)
| 189 | return train_op |
| 190 | |
| 191 | def train(self): |
| 192 | """based on the loss, use SGD to update parameter""" |
| 193 | learning_rate = tf.train.exponential_decay(self.learning_rate, self.global_step, self.decay_steps, self.decay_rate, staircase=True) |
| 194 | self.learning_rate_=learning_rate |
| 195 | optimizer = tf.train.AdamOptimizer(learning_rate) |
| 196 | gradients, variables = zip(*optimizer.compute_gradients(self.loss_val)) |
| 197 | gradients, _ = tf.clip_by_global_norm(gradients, 5.0) |
| 198 | update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS) #ADD 2018.06.01 |
| 199 | with tf.control_dependencies(update_ops): #ADD 2018.06.01 |
| 200 | train_op = optimizer.apply_gradients(zip(gradients, variables)) |
| 201 | return train_op |
| 202 | |
| 203 | #test started. toy task: given a sequence of data. compute it's label: sum of its previous element,itself and next element greater than a threshold, it's label is 1,otherwise 0. |
| 204 | #e.g. given inputs:[1,0,1,1,0]; outputs:[0,1,1,1,0]. |
no test coverage detected