def _create_model(self):
depth = len(self.vocab)+1
self._create_rnn()
with tf.name_scope('loss'):
self.logits = tf.contrib.layers.fully_connected(inputs=self.output, num_outputs=depth, activation_fn=None)
self.labels = tf.one_hot(self.seq, depth=depth)
self.loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=self.labels[:, 1:], logits=self.logits[:, :-1]), name='loss')
with tf.name_scope('sample'):
self.sample = tf.multinomial(self.logits[:, -1] / self.temp, 1)[:, 0]
return self.loss, self.sample, self.in_state, self.out_state
评论列表
文章目录