Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
49cf5b43
提交
49cf5b43
authored
9月 30, 2015
作者:
fvisin
提交者:
Francesco Visin
12月 02, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add LogSoftmax gradient test and gradient optimization test
上级
8b447002
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
3 行删除
+27
-3
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+27
-3
没有找到文件。
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
49cf5b43
...
@@ -170,6 +170,11 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -170,6 +170,11 @@ class T_LogSoftmax(utt.InferShapeTester):
return
logsoftmax_op
(
a
)[:,
3
]
return
logsoftmax_op
(
a
)[:,
3
]
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
def
test_matrix
(
self
):
def
f
(
a
):
return
logsoftmax_op
(
a
)
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
3
,
4
)])
def
test_vector
(
self
):
def
test_vector
(
self
):
x
=
T
.
vector
()
x
=
T
.
vector
()
f
=
theano
.
function
([
x
],
logsoftmax_op
(
x
))
f
=
theano
.
function
([
x
],
logsoftmax_op
(
x
))
...
@@ -180,7 +185,7 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -180,7 +185,7 @@ class T_LogSoftmax(utt.InferShapeTester):
def
test_vector_grad
(
self
):
def
test_vector_grad
(
self
):
def
f
(
a
):
def
f
(
a
):
return
softmax_op
(
a
)
return
log
softmax_op
(
a
)
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
4
)])
utt
.
verify_grad
(
f
,
[
numpy
.
random
.
rand
(
4
)])
def
test_allclose
(
self
):
def
test_allclose
(
self
):
...
@@ -226,7 +231,7 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -226,7 +231,7 @@ class T_LogSoftmax(utt.InferShapeTester):
def
test_local_softmax_optimization
(
self
):
def
test_local_softmax_optimization
(
self
):
"""Test the Logsoftmax substitution
"""Test the Logsoftmax substitution
Check that Log(Softmax(x)) is substituted
to
Logsoftmax(x). Note that
Check that Log(Softmax(x)) is substituted
with
Logsoftmax(x). Note that
only the forward pass is checked (i.e., doesn't check the gradient)
only the forward pass is checked (i.e., doesn't check the gradient)
"""
"""
x
,
y
=
tensor
.
matrices
(
'xy'
)
x
,
y
=
tensor
.
matrices
(
'xy'
)
...
@@ -234,7 +239,26 @@ class T_LogSoftmax(utt.InferShapeTester):
...
@@ -234,7 +239,26 @@ class T_LogSoftmax(utt.InferShapeTester):
logsm
=
tensor
.
log
(
sm
)
logsm
=
tensor
.
log
(
sm
)
f
=
theano
.
function
([
x
],
logsm
)
f
=
theano
.
function
([
x
],
logsm
)
assert
isinstance
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
,
assert
isinstance
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
,
theano
.
tensor
.
nnet
.
nnet
.
LogSoftmax
)
theano
.
tensor
.
nnet
.
nnet
.
LogSoftmax
)
def
test_local_softmax_grad_optimization_and_big_input
(
self
):
"""Test the Logsoftmax's grad substitution.
Check that Log(Softmax(x))'s grad is substituted with Logsoftmax(x)'s
grad and that the new operation does not explode for big inputs.
Note that only the grad is checked.
"""
# some inputs that are large to make the gradient explode in the non
# optimized case
a
=
numpy
.
exp
(
10
*
numpy
.
random
.
rand
(
5
,
10
)
.
astype
(
theano
.
config
.
floatX
))
def
myfunc
(
x
):
sm
=
tensor
.
nnet
.
softmax
(
x
)
logsm
=
tensor
.
log
(
sm
)
return
logsm
# We set step to 0.1 because for big values we need a big epsilon
utt
.
verify_grad
(
myfunc
,
[
a
],
eps
=
0.1
)
class
T_SoftmaxGrad
(
utt
.
InferShapeTester
):
class
T_SoftmaxGrad
(
utt
.
InferShapeTester
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论