Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7561c1c2
提交
7561c1c2
authored
3月 03, 2016
作者:
Vincent Michalski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added some more tests for nnet
上级
93b50c70
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
4 行删除
+16
-4
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+16
-4
没有找到文件。
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
7561c1c2
...
@@ -143,9 +143,10 @@ class T_SoftmaxWithBias(utt.InferShapeTester):
...
@@ -143,9 +143,10 @@ class T_SoftmaxWithBias(utt.InferShapeTester):
a
=
theano
.
shared
(
a
=
theano
.
shared
(
numpy
.
random
.
randn
(
3
)
.
astype
(
config
.
floatX
))
numpy
.
random
.
randn
(
3
)
.
astype
(
config
.
floatX
))
b
=
theano
.
shared
(
numpy
.
float32
(
numpy
.
random
.
randn
()))
b
=
theano
.
shared
(
numpy
.
float32
(
numpy
.
random
.
randn
()))
sm
=
T
.
softmax
(
a
+
b
)
sm
=
T
.
nnet
.
softmax
(
a
+
b
)
f
=
theano
.
function
([],
sm
)
f
=
theano
.
function
([],
sm
)
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
print
(
'f.maker.fgraph.outputs[0]: {0}'
.
format
(
f
.
maker
.
fgraph
.
outputs
[
0
],
))
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
admat
=
matrix
()
admat
=
matrix
()
...
@@ -209,11 +210,11 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -209,11 +210,11 @@ class T_LogSoftmax(utt.InferShapeTester):
# numerically stable log-softmax with crossentropy
# numerically stable log-softmax with crossentropy
logsm
=
tensor
.
nnet
.
logsoftmax
(
x
)
logsm
=
tensor
.
nnet
.
logsoftmax
(
x
)
sm2
=
tensor
.
exp
(
logsm
)
# just used to show equivalence with sm
sm2
=
tensor
.
exp
(
logsm
)
# just used to show equivalence with sm
cm2
=
-
tensor
.
sum
(
y
*
logsm
,
axis
=
1
)
cm2
=
-
tensor
.
sum
(
y
*
logsm
,
axis
=
1
)
grad
=
tensor
.
grad
(
cm2
.
mean
(),
x
)
grad
=
tensor
.
grad
(
cm2
.
mean
(),
x
)
# create some inputs into a softmax that are large and labels
# create some inputs into a softmax that are large and labels
a
=
numpy
.
exp
(
10
*
numpy
.
random
.
rand
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
))
a
=
numpy
.
exp
(
10
*
numpy
.
random
.
rand
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
))
# create some one-hot coded labels
# create some one-hot coded labels
b
=
numpy
.
eye
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
)
b
=
numpy
.
eye
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
)
...
@@ -266,7 +267,7 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -266,7 +267,7 @@ class T_LogSoftmax(utt.InferShapeTester):
m
.
check_isfinite
=
False
m
.
check_isfinite
=
False
# some inputs that are large to make the gradient explode in the non
# some inputs that are large to make the gradient explode in the non
# optimized case
# optimized case
a
=
numpy
.
exp
(
10
*
numpy
.
random
.
rand
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
))
a
=
numpy
.
exp
(
10
*
numpy
.
random
.
rand
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
))
def
myfunc
(
x
):
def
myfunc
(
x
):
sm
=
tensor
.
nnet
.
softmax
(
x
)
sm
=
tensor
.
nnet
.
softmax
(
x
)
...
@@ -1426,6 +1427,9 @@ class Test_softmax_opt:
...
@@ -1426,6 +1427,9 @@ class Test_softmax_opt:
# test that function contains softmax and no div.
# test that function contains softmax and no div.
f
=
theano
.
function
([
c
],
p_y
,
mode
=
self
.
mode
)
f
=
theano
.
function
([
c
],
p_y
,
mode
=
self
.
mode
)
assert
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
f_ops
=
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
f_ops
=
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
# print '--- f ='
# print '--- f ='
# printing.debugprint(f)
# printing.debugprint(f)
...
@@ -1440,6 +1444,9 @@ class Test_softmax_opt:
...
@@ -1440,6 +1444,9 @@ class Test_softmax_opt:
# test that function contains softmax and no div.
# test that function contains softmax and no div.
f
=
theano
.
function
([
c
],
p_y
,
mode
=
self
.
mode
)
f
=
theano
.
function
([
c
],
p_y
,
mode
=
self
.
mode
)
assert
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
f_ops
=
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
f_ops
=
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
# print '--- f ='
# print '--- f ='
# printing.debugprint(f)
# printing.debugprint(f)
...
@@ -1458,6 +1465,7 @@ class Test_softmax_opt:
...
@@ -1458,6 +1465,7 @@ class Test_softmax_opt:
config
.
warn
.
sum_div_dimshuffle_bug
=
False
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
try
:
g
=
theano
.
function
([
c
,
w
],
T
.
grad
((
p_y
*
w
)
.
sum
(),
c
))
g
=
theano
.
function
([
c
,
w
],
T
.
grad
((
p_y
*
w
)
.
sum
(),
c
))
hasattr
(
g
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
finally
:
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
g_ops
=
[
n
.
op
for
n
in
g
.
maker
.
fgraph
.
toposort
()]
g_ops
=
[
n
.
op
for
n
in
g
.
maker
.
fgraph
.
toposort
()]
...
@@ -1485,6 +1493,7 @@ class Test_softmax_opt:
...
@@ -1485,6 +1493,7 @@ class Test_softmax_opt:
config
.
warn
.
sum_div_dimshuffle_bug
=
False
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
try
:
g
=
theano
.
function
([
c
],
T
.
grad
(
p_y
.
sum
(),
c
))
g
=
theano
.
function
([
c
],
T
.
grad
(
p_y
.
sum
(),
c
))
hasattr
(
g
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
finally
:
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
# printing.debugprint(g)
# printing.debugprint(g)
...
@@ -1497,6 +1506,7 @@ class Test_softmax_opt:
...
@@ -1497,6 +1506,7 @@ class Test_softmax_opt:
# test that function contains softmax and no div.
# test that function contains softmax and no div.
f
=
theano
.
function
([
c
],
p_y
)
f
=
theano
.
function
([
c
],
p_y
)
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
# printing.debugprint(f)
# printing.debugprint(f)
# test that function contains softmax and no div.
# test that function contains softmax and no div.
...
@@ -1504,6 +1514,7 @@ class Test_softmax_opt:
...
@@ -1504,6 +1514,7 @@ class Test_softmax_opt:
config
.
warn
.
sum_div_dimshuffle_bug
=
False
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
try
:
g
=
theano
.
function
([
c
],
T
.
grad
(
p_y
.
sum
(),
c
))
g
=
theano
.
function
([
c
],
T
.
grad
(
p_y
.
sum
(),
c
))
hasattr
(
g
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
finally
:
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
# printing.debugprint(g)
# printing.debugprint(g)
...
@@ -1543,6 +1554,7 @@ def test_stabilize_log_softmax():
...
@@ -1543,6 +1554,7 @@ def test_stabilize_log_softmax():
z
=
theano
.
tensor
.
log
(
y
)
z
=
theano
.
tensor
.
log
(
y
)
f
=
theano
.
function
([
x
],
z
,
mode
=
mode
)
f
=
theano
.
function
([
x
],
z
,
mode
=
mode
)
assert
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
)
# check that the softmax has been optimized out
# check that the softmax has been optimized out
for
node
in
f
.
maker
.
fgraph
.
toposort
():
for
node
in
f
.
maker
.
fgraph
.
toposort
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论