MCPcopy Create free account
hub / github.com/MorvanZhou/tutorials / compute_cost

Method compute_cost

tensorflowTUT/tf20_RNN2.2/full_code.py:87–101  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected