char_rnn.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:learning-tf 作者: unixpickle 项目源码 文件源码
def loss(self, actual_out):
        """
        Compute the cross-entropy loss between the actual
        output and the desired targets.
        """
        cost_sum = None
        for timestep, actual_term in enumerate(actual_out):
            target_term = self.outputs[timestep]
            log_probs = tf.log(tf.nn.softmax(actual_term))
            loss = -tf.tensordot(log_probs, target_term, axes=2)
            if cost_sum is None:
                cost_sum = loss
            else:
                cost_sum += loss
        return cost_sum / (self.batch * self.length)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号