Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
95967313
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
95967313
编写于
10月 26, 2017
作者:
Y
Yu Yang
提交者:
GitHub
10月 26, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enhance default param_attrs (#5142)
上级
b44f4ccb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
36 deletion
+27
-36
python/paddle/v2/framework/layer_helper.py
python/paddle/v2/framework/layer_helper.py
+19
-8
python/paddle/v2/framework/tests/test_layers.py
python/paddle/v2/framework/tests/test_layers.py
+4
-14
python/paddle/v2/framework/tests/test_word2vec.py
python/paddle/v2/framework/tests/test_word2vec.py
+4
-14
未找到文件。
python/paddle/v2/framework/layer_helper.py
浏览文件 @
95967313
...
...
@@ -75,18 +75,29 @@ class LayerHelper(object):
}
}
actual
=
self
.
kwargs
.
get
(
'param_attr'
,
None
)
return
actual
if
actual
is
not
None
else
default
if
actual
is
None
:
actual
=
default
for
default_field
in
default
.
keys
():
if
default_field
not
in
actual
:
actual
[
default_field
]
=
default
[
default_field
]
return
actual
def
bias_attr
(
self
):
default
=
{
'name'
:
None
,
'init_attr'
:
{
'type'
:
'fill_constant'
,
'value'
:
0.0
}
}
bias_attr
=
self
.
kwargs
.
get
(
'bias_attr'
,
None
)
if
bias_attr
is
True
:
bias_attr
=
{
'name'
:
None
,
'init_attr'
:
{
'type'
:
'fill_constant'
,
'value'
:
0.0
}
}
bias_attr
=
default
if
isinstance
(
bias_attr
,
dict
):
for
default_field
in
default
.
keys
():
if
default_field
not
in
bias_attr
:
bias_attr
[
default_field
]
=
default
[
default_field
]
return
bias_attr
def
multiple_param_attr
(
self
,
length
):
...
...
python/paddle/v2/framework/tests/test_layers.py
浏览文件 @
95967313
...
...
@@ -103,40 +103,30 @@ class TestBook(unittest.TestCase):
next_word
=
layers
.
data
(
name
=
'nextw'
,
shape
=
[
1
],
data_type
=
'int32'
,
program
=
program
)
embed_param_attr_1
=
{
'name'
:
'shared_w'
,
'init_attr'
:
{
'max'
:
1.0
,
'type'
:
'uniform_random'
,
'min'
:
-
1.0
}
}
embed_param_attr_2
=
{
'name'
:
'shared_w'
}
embed_first
=
layers
.
embedding
(
input
=
first_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_1
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
)
embed_second
=
layers
.
embedding
(
input
=
second_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
)
embed_third
=
layers
.
embedding
(
input
=
third_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
)
embed_forth
=
layers
.
embedding
(
input
=
forth_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
)
concat_embed
=
layers
.
concat
(
...
...
python/paddle/v2/framework/tests/test_word2vec.py
浏览文件 @
95967313
...
...
@@ -50,28 +50,18 @@ next_word = layers.data(
program
=
program
,
init_program
=
init_program
)
embed_param_attr_1
=
{
'name'
:
'shared_w'
,
'init_attr'
:
{
'max'
:
1.0
,
'type'
:
'uniform_random'
,
'min'
:
-
1.0
}
}
embed_param_attr_2
=
{
'name'
:
'shared_w'
}
embed_first
=
layers
.
embedding
(
input
=
first_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_1
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
,
init_program
=
init_program
)
embed_second
=
layers
.
embedding
(
input
=
second_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
,
init_program
=
init_program
)
...
...
@@ -79,14 +69,14 @@ embed_third = layers.embedding(
input
=
third_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
,
init_program
=
init_program
)
embed_forth
=
layers
.
embedding
(
input
=
forth_word
,
size
=
[
dict_size
,
embed_size
],
data_type
=
'float32'
,
param_attr
=
embed_param_attr_2
,
param_attr
=
{
'name'
:
'shared_w'
}
,
program
=
program
,
init_program
=
init_program
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录