| 85 | self.pred = tf.matmul(l_out_x, Ws_out) + bs_out |
| 86 | |
| 87 | def compute_cost(self): |
| 88 | losses = tf.contrib.legacy_seq2seq.sequence_loss_by_example( |
| 89 | [tf.reshape(self.pred, [-1], name='reshape_pred')], |
| 90 | [tf.reshape(self.ys, [-1], name='reshape_target')], |
| 91 | [tf.ones([self.batch_size * self.n_steps], dtype=tf.float32)], |
| 92 | average_across_timesteps=True, |
| 93 | softmax_loss_function=self.ms_error, |
| 94 | name='losses' |
| 95 | ) |
| 96 | with tf.name_scope('average_cost'): |
| 97 | self.cost = tf.div( |
| 98 | tf.reduce_sum(losses, name='losses_sum'), |
| 99 | self.batch_size, |
| 100 | name='average_cost') |
| 101 | tf.summary.scalar('cost', self.cost) |
| 102 | |
| 103 | @staticmethod |
| 104 | def ms_error(labels, logits): |