Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1fb98839
提交
1fb98839
authored
6月 10, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merged
上级
b2ba9b8b
2f82231c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
41 行删除
+53
-41
test_basic.py
theano/tensor/tests/test_basic.py
+17
-11
test_naacl09.py
theano/tensor/tests/test_naacl09.py
+36
-30
没有找到文件。
theano/tensor/tests/test_basic.py
浏览文件 @
1fb98839
...
@@ -254,17 +254,23 @@ def makeTester(name, op, expected, checks = {}, good = {}, bad_build = {},
...
@@ -254,17 +254,23 @@ def makeTester(name, op, expected, checks = {}, good = {}, bad_build = {},
def
test_grad
(
self
):
def
test_grad
(
self
):
if
skip
:
if
skip
:
raise
SkipTest
(
skip
)
raise
SkipTest
(
skip
)
for
testname
,
inputs
in
self
.
grad
.
items
():
# Disable old warning that may be triggered by this test.
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
backup
=
config
.
warn
.
sum_div_dimshuffle_bug
inputrs
=
[
value
(
input
)
for
input
in
inputs
]
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
try
:
utt
.
verify_grad
(
self
.
op
,
inputs
,
mode
=
self
.
mode
,
rel_tol
=
_grad_rtol
)
for
testname
,
inputs
in
self
.
grad
.
items
():
except
:
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
inputrs
=
[
value
(
input
)
for
input
in
inputs
]
err_msg
=
"Test
%
s::
%
s: Error occurred while computing the gradient on the following inputs:
%
s"
\
try
:
%
(
self
.
op
,
testname
,
inputs
)
utt
.
verify_grad
(
self
.
op
,
inputs
,
mode
=
self
.
mode
,
rel_tol
=
_grad_rtol
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
except
:
raise
type
,
exc_value
,
traceback
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while computing the gradient on the following inputs:
%
s"
\
%
(
self
.
op
,
testname
,
inputs
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
Checker
.
__name__
=
name
Checker
.
__name__
=
name
return
Checker
return
Checker
...
...
theano/tensor/tests/test_naacl09.py
浏览文件 @
1fb98839
...
@@ -26,7 +26,7 @@ class QuadraticDenoisingAA(module.Module):
...
@@ -26,7 +26,7 @@ class QuadraticDenoisingAA(module.Module):
WRITEME
WRITEME
Abstract base class. Requires subclass with functions:
Abstract base class. Requires subclass with functions:
- build_corrupted_input()
- build_corrupted_input()
Introductory article about this model WRITEME.
Introductory article about this model WRITEME.
...
@@ -193,7 +193,7 @@ class QuadraticDenoisingAA(module.Module):
...
@@ -193,7 +193,7 @@ class QuadraticDenoisingAA(module.Module):
if
(
input_size
is
None
)
^
(
hidden_size
is
None
):
if
(
input_size
is
None
)
^
(
hidden_size
is
None
):
raise
ValueError
(
"Must specify input_size and hidden_size or neither."
)
raise
ValueError
(
"Must specify input_size and hidden_size or neither."
)
super
(
QuadraticDenoisingAA
,
self
)
.
_instance_initialize
(
obj
,
{})
super
(
QuadraticDenoisingAA
,
self
)
.
_instance_initialize
(
obj
,
{})
obj
.
random
.
initialize
()
obj
.
random
.
initialize
()
R
=
N
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
seed
))
R
=
N
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
seed
))
if
input_size
is
not
None
:
if
input_size
is
not
None
:
...
@@ -312,7 +312,7 @@ class Module_Nclass(module.FancyModule):
...
@@ -312,7 +312,7 @@ class Module_Nclass(module.FancyModule):
sum_xent
=
T
.
sum
(
xent
)
sum_xent
=
T
.
sum
(
xent
)
self
.
softmax
=
softmax
self
.
softmax
=
softmax
self
.
argmax
=
argmax
self
.
argmax
=
argmax
self
.
max_pr
=
max_pr
self
.
max_pr
=
max_pr
self
.
sum_xent
=
sum_xent
self
.
sum_xent
=
sum_xent
...
@@ -341,7 +341,7 @@ class Module_Nclass(module.FancyModule):
...
@@ -341,7 +341,7 @@ class Module_Nclass(module.FancyModule):
#updates = dict((p, p - self.lr * g) for p, g in zip(self.params, gparams)))
#updates = dict((p, p - self.lr * g) for p, g in zip(self.params, gparams)))
class
ConvolutionalMLP
(
module
.
FancyModule
):
class
ConvolutionalMLP
(
module
.
FancyModule
):
def
__init__
(
self
,
def
__init__
(
self
,
window_size
,
window_size
,
n_quadratic_filters
,
n_quadratic_filters
,
activation_function
,
activation_function
,
...
@@ -417,8 +417,8 @@ class ConvolutionalMLP(module.FancyModule):
...
@@ -417,8 +417,8 @@ class ConvolutionalMLP(module.FancyModule):
zip
(
input_pretraining_params
,
input_pretraining_gradients
)
\
zip
(
input_pretraining_params
,
input_pretraining_gradients
)
\
+
zip
(
hidden_pretraining_params
,
hidden_pretraining_gradients
))
+
zip
(
hidden_pretraining_params
,
hidden_pretraining_gradients
))
self
.
pretraining_update
=
module
.
Method
(
self
.
inputs
,
self
.
pretraining_update
=
module
.
Method
(
self
.
inputs
,
[
input_pretraining_cost
,
hidden_pretraining_cost
],
[
input_pretraining_cost
,
hidden_pretraining_cost
],
pretraining_updates
)
pretraining_updates
)
finetuning_params
=
\
finetuning_params
=
\
...
@@ -464,7 +464,7 @@ class ConvolutionalMLP(module.FancyModule):
...
@@ -464,7 +464,7 @@ class ConvolutionalMLP(module.FancyModule):
assert
(
i
.
w2
==
self
.
input_representations
[
0
]
.
w2
)
.
all
()
assert
(
i
.
w2
==
self
.
input_representations
[
0
]
.
w2
)
.
all
()
assert
(
i
.
b1
==
self
.
input_representations
[
0
]
.
b1
)
.
all
()
assert
(
i
.
b1
==
self
.
input_representations
[
0
]
.
b1
)
.
all
()
assert
(
i
.
b2
==
self
.
input_representations
[
0
]
.
b2
)
.
all
()
assert
(
i
.
b2
==
self
.
input_representations
[
0
]
.
b2
)
.
all
()
assert
N
.
all
((
a
==
b
)
.
all
()
for
a
,
b
in
zip
(
i
.
qfilters
,
self
.
input_representations
[
0
]
.
qfilters
))
assert
N
.
all
((
a
==
b
)
.
all
()
for
a
,
b
in
zip
(
i
.
qfilters
,
self
.
input_representations
[
0
]
.
qfilters
))
self
.
hidden
.
initialize
(
input_size
=
(
len
(
self
.
inputs
)
*
self
.
input_representation_size
),
self
.
hidden
.
initialize
(
input_size
=
(
len
(
self
.
inputs
)
*
self
.
input_representation_size
),
hidden_size
=
self
.
hidden_representation_size
,
noise_level
=
noise_level
,
hidden_size
=
self
.
hidden_representation_size
,
noise_level
=
noise_level
,
...
@@ -472,16 +472,16 @@ class ConvolutionalMLP(module.FancyModule):
...
@@ -472,16 +472,16 @@ class ConvolutionalMLP(module.FancyModule):
self
.
output
.
initialize
(
n_in
=
self
.
hidden_representation_size
,
n_out
=
self
.
output_size
,
lr
=
lr
,
seed
=
R
.
random_integers
(
2
**
30
))
self
.
output
.
initialize
(
n_in
=
self
.
hidden_representation_size
,
n_out
=
self
.
output_size
,
lr
=
lr
,
seed
=
R
.
random_integers
(
2
**
30
))
def
create
(
window_size
=
3
,
def
create
(
window_size
=
3
,
input_dimension
=
9
,
input_dimension
=
9
,
output_vocabsize
=
8
,
output_vocabsize
=
8
,
n_quadratic_filters
=
2
,
n_quadratic_filters
=
2
,
token_representation_size
=
5
,
token_representation_size
=
5
,
concatenated_representation_size
=
7
,
concatenated_representation_size
=
7
,
lr
=
0.01
,
lr
=
0.01
,
seed
=
123
,
seed
=
123
,
noise_level
=
0.2
,
noise_level
=
0.2
,
qfilter_relscale
=
0.1
,
qfilter_relscale
=
0.1
,
compile_mode
=
None
):
compile_mode
=
None
):
""" Create a convolutional model. """
""" Create a convolutional model. """
activation_function
=
T
.
tanh
activation_function
=
T
.
tanh
...
@@ -493,19 +493,25 @@ def create(window_size=3,
...
@@ -493,19 +493,25 @@ def create(window_size=3,
reconstruction_cost_function
=
quadratic
,
reconstruction_cost_function
=
quadratic
,
tie_weights
=
False
tie_weights
=
False
)
)
model
=
architecture
.
make
(
input_size
=
input_dimension
,
input_representation_size
=
token_representation_size
,
hidden_representation_size
=
concatenated_representation_size
,
output_size
=
output_vocabsize
,
lr
=
lr
,
seed
=
seed
,
noise_level
=
noise_level
,
qfilter_relscale
=
qfilter_relscale
,
mode
=
compile_mode
)
backup
=
config
.
warn
.
sum_div_dimshuffle_bug
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
model
=
architecture
.
make
(
input_size
=
input_dimension
,
input_representation_size
=
token_representation_size
,
hidden_representation_size
=
concatenated_representation_size
,
output_size
=
output_vocabsize
,
lr
=
lr
,
seed
=
seed
,
noise_level
=
noise_level
,
qfilter_relscale
=
qfilter_relscale
,
mode
=
compile_mode
)
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
return
model
return
model
def
create_realistic
(
window_size
=
3
,
#7,
def
create_realistic
(
window_size
=
3
,
#7,
input_dimension
=
200
,
input_dimension
=
200
,
output_vocabsize
=
23
,
output_vocabsize
=
23
,
n_quadratic_filters
=
2
,
n_quadratic_filters
=
2
,
token_representation_size
=
150
,
token_representation_size
=
150
,
concatenated_representation_size
=
400
,
concatenated_representation_size
=
400
,
lr
=
0.001
,
lr
=
0.001
,
seed
=
123
,
seed
=
123
,
noise_level
=
0.2
,
noise_level
=
0.2
,
qfilter_relscale
=
0.1
,
qfilter_relscale
=
0.1
,
compile_mode
=
None
):
compile_mode
=
None
):
""" Create a convolutional model. """
""" Create a convolutional model. """
activation_function
=
T
.
tanh
activation_function
=
T
.
tanh
...
@@ -525,7 +531,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
...
@@ -525,7 +531,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
print
"BUILDING MODEL"
print
"BUILDING MODEL"
import
time
import
time
t
=
time
.
time
()
t
=
time
.
time
()
if
optimizer
:
if
optimizer
:
mode
=
theano
.
Mode
(
linker
=
'c|py'
,
optimizer
=
optimizer
)
mode
=
theano
.
Mode
(
linker
=
'c|py'
,
optimizer
=
optimizer
)
else
:
mode
=
get_default_mode
()
else
:
mode
=
get_default_mode
()
...
@@ -533,7 +539,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
...
@@ -533,7 +539,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
if
mode
.
__class__
.
__name__
==
'DebugMode'
:
if
mode
.
__class__
.
__name__
==
'DebugMode'
:
iters_per_unsup
=
1
iters_per_unsup
=
1
iters_per_sup
=
1
iters_per_sup
=
1
if
realistic
:
if
realistic
:
m
=
create_realistic
(
compile_mode
=
mode
)
m
=
create_realistic
(
compile_mode
=
mode
)
else
:
else
:
...
@@ -596,7 +602,7 @@ def real_main():
...
@@ -596,7 +602,7 @@ def real_main():
test_naacl_model
()
test_naacl_model
()
def
profile_main
():
def
profile_main
():
# This is the main function for profiling
# This is the main function for profiling
# We've renamed our original main() above to real_main()
# We've renamed our original main() above to real_main()
import
cProfile
,
pstats
,
StringIO
import
cProfile
,
pstats
,
StringIO
prof
=
cProfile
.
Profile
()
prof
=
cProfile
.
Profile
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论