test_loss_masking.py 文件源码

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

项目:deep-coref 作者: clarkkev 项目源码 文件源码
def test_loss_masking_time(self):
        theano.config.mode = 'FAST_COMPILE'
        weighted_loss = weighted_objective(objectives.get('categorical_crossentropy'))
        shape = (3, 4, 2)
        X = np.arange(24).reshape(shape)
        Y = 2 * X

        weights = np.ones((3, 4, 1))  # Normally the trailing 1 is added by standardize_weights
        weights[0, 0] = 0
        mask = np.ones((3, 4))
        mask[1, 0] = 0

        out = weighted_loss(X, Y, weights, mask).eval()
        weights[0, 0] = 1e-9  # so that nonzero() doesn't remove this weight
        out2 = weighted_loss(X, Y, weights, mask).eval()
        print(out)
        print(out2)
        assert abs(out - out2) < 1e-8
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号