def test_neg_cross_entropy_colwise(): X, Y = T.matrix(), T.matrix() X.tag.test_value = test_X > 0.2 Y.tag.test_value = test_Y dist = nce(X, Y).sum(axis=0) f = theano.function([X, Y], dist, mode='FAST_COMPILE') res = f(test_X, test_Y) correct = np.allclose(res, [[0.49795728, 0.48932523, 0.61908916]]) assert correct, 'nce loss colwise not working'
def test_neg_cross_entropy(): X, Y = T.matrix(), T.matrix() X.tag.test_value = test_X > 0.2 Y.tag.test_value = test_Y dist = nce(X, Y).sum() f = theano.function([X, Y], dist, mode='FAST_COMPILE') res = f(test_X, test_Y) correct = np.allclose(res, 1.6063716678910529) assert correct, 'nce loss not working'
def test_neg_cross_entropy_rowwise(): X, Y = T.matrix(), T.matrix() X.tag.test_value = test_X > 0.2 Y.tag.test_value = test_Y dist = nce(X, Y).sum(axis=1) f = theano.function([X, Y], dist, mode='FAST_COMPILE') res = f(test_X, test_Y) correct = np.allclose(res, [0.85798192, 0.74838975]) assert correct, 'nce loss rowwise not working'