提交 bae2c6df authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Small changes in the test for softmax optimization

上级 dc02ed59
...@@ -434,9 +434,9 @@ if 0: ...@@ -434,9 +434,9 @@ if 0:
def softmax_grad_simplifier(numerators, denominators): def softmax_grad_simplifier(numerators, denominators):
print "mul simplify numerators" print "mul simplify numerators"
debugprint(numerators) printing.debugprint(numerators)
print "mul simplify denominators" print "mul simplify denominators"
debugprint(denominators) printing.debugprint(denominators)
for numerator in list(numerators): for numerator in list(numerators):
#TODO: a single softmax'd vector?? #TODO: a single softmax'd vector??
if not numerator.type.dtype.startswith('float'): if not numerator.type.dtype.startswith('float'):
......
...@@ -910,32 +910,46 @@ class Test_softmax_opt(): ...@@ -910,32 +910,46 @@ class Test_softmax_opt():
p_y = T.exp(c) / T.exp(c).sum(axis=1).dimshuffle(0,'x') p_y = T.exp(c) / T.exp(c).sum(axis=1).dimshuffle(0,'x')
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c],p_y) f = theano.function([c],p_y)
f_ops = [n.op for n in f.maker.env.toposort()]
print '--- f ='
printing.debugprint(f)
print '==='
assert len(f_ops) == 1
assert softmax in f_ops
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c],T.grad(p_y.sum(), c)) g = theano.function([c],T.grad(p_y.sum(), c))
print '--- g ='
printing.debugprint(g)
print '==='
def test_transpose_basic(self): def test_transpose_basic(self):
# this should be a transposed softmax # this should be a transposed softmax
c = T.matrix() c = T.matrix()
p_y = T.exp(c) / T.exp(c).sum(axis=0) p_y = T.exp(c) / T.exp(c).sum(axis=0)
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c],p_y) f = theano.function([c],p_y)
printing.debugprint(f)
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c],T.grad(p_y.sum(), c)) g = theano.function([c],T.grad(p_y.sum(), c))
printing.debugprint(g)
def test_1d_basic(self): def test_1d_basic(self):
# this should be a softmax, but of a one-row matrix # this should be a softmax, but of a one-row matrix
c = T.vector() c = T.vector()
p_y = T.exp(c) / T.exp(c).sum() p_y = T.exp(c) / T.exp(c).sum()
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c], p_y) f = theano.function([c], p_y)
printing.debugprint(f)
# test that function contains softmax and no div. # test that function contains softmax and no div.
function([c], T.grad(p_y.sum(), c)) g = theano.function([c], T.grad(p_y.sum(), c))
printing.debugprint(g)
# REPEAT 3 CASES in presence of log(softmax) with the advanced indexing etc. # REPEAT 3 CASES in presence of log(softmax) with the advanced indexing etc.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论