Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a9d327bd
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a9d327bd
编写于
9月 15, 2016
作者:
H
Haonan
提交者:
emailweixu
9月 15, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add wrapper for out_prod_layer (#83)
上级
df28da76
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
2 deletion
+38
-2
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+35
-1
python/paddle/trainer_config_helpers/tests/layers_test_config.py
...paddle/trainer_config_helpers/tests/layers_test_config.py
+3
-1
未找到文件。
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
a9d327bd
...
@@ -52,7 +52,7 @@ __all__ = ["full_matrix_projection", "AggregateLevel", "ExpandLevel",
...
@@ -52,7 +52,7 @@ __all__ = ["full_matrix_projection", "AggregateLevel", "ExpandLevel",
'cross_entropy_with_selfnorm'
,
'cross_entropy'
,
'cross_entropy_with_selfnorm'
,
'cross_entropy'
,
'multi_binary_label_cross_entropy'
,
'multi_binary_label_cross_entropy'
,
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'block_expand_layer'
,
'block_expand_layer'
,
'out_prod_layer'
,
]
]
...
@@ -93,6 +93,7 @@ class LayerType(object):
...
@@ -93,6 +93,7 @@ class LayerType(object):
POWER_LAYER
=
'power'
POWER_LAYER
=
'power'
SCALING_LAYER
=
'scaling'
SCALING_LAYER
=
'scaling'
TRANS_LAYER
=
'trans'
TRANS_LAYER
=
'trans'
OUT_PROD_LAYER
=
'out_prod'
MEMORY
=
'memory'
MEMORY
=
'memory'
MAXID_LAYER
=
'maxid'
MAXID_LAYER
=
'maxid'
...
@@ -2345,6 +2346,39 @@ def maxid_layer(input, name=None, layer_attr=None):
...
@@ -2345,6 +2346,39 @@ def maxid_layer(input, name=None, layer_attr=None):
layer_type
=
LayerType
.
MAXID_LAYER
,
layer_type
=
LayerType
.
MAXID_LAYER
,
parents
=
[
input
])
parents
=
[
input
])
@
wrap_name_default
()
def
out_prod_layer
(
input1
,
input2
,
name
=
None
,
layer_attr
=
None
):
"""
A layer for computing the outer product of two vectors
The result is a matrix of size(input1) x size(input2)
The example usage is:
.. code-block:: python
out_prod = out_prod_layer(input1=vec1, input2=vec2)
:param name: Layer name.
:type name: basestring
:param input1: The first input layer name.
:type input: LayerOutput
:param input2: The second input layer name.
:type input2: LayerOutput
:param layer_attr: extra layer attributes.
:type layer_attr: ExtraLayerAttribute.
:return: LayerOutput object.
:rtype: LayerOutput
"""
assert
isinstance
(
input1
,
LayerOutput
)
assert
isinstance
(
input2
,
LayerOutput
)
Layer
(
name
=
name
,
type
=
"out_prod"
,
inputs
=
[
input1
.
name
,
input2
.
name
],
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
))
return
LayerOutput
(
name
=
name
,
layer_type
=
LayerType
.
OUT_PROD_LAYER
,
parents
=
[
input1
,
input2
])
@
wrap_name_default
()
@
wrap_name_default
()
def
eos_layer
(
input
,
eos_id
,
name
=
None
,
layer_attr
=
None
):
def
eos_layer
(
input
,
eos_id
,
name
=
None
,
layer_attr
=
None
):
...
...
python/paddle/trainer_config_helpers/tests/layers_test_config.py
浏览文件 @
a9d327bd
...
@@ -19,6 +19,8 @@ num_classes = 5
...
@@ -19,6 +19,8 @@ num_classes = 5
x
=
data_layer
(
name
=
"input1"
,
size
=
3
)
x
=
data_layer
(
name
=
"input1"
,
size
=
3
)
y
=
data_layer
(
name
=
"input2"
,
size
=
5
)
y
=
data_layer
(
name
=
"input2"
,
size
=
5
)
z
=
out_prod_layer
(
input1
=
x
,
input2
=
y
)
x1
=
fc_layer
(
input
=
x
,
size
=
5
)
x1
=
fc_layer
(
input
=
x
,
size
=
5
)
y1
=
fc_layer
(
input
=
y
,
size
=
5
)
y1
=
fc_layer
(
input
=
y
,
size
=
5
)
y2
=
fc_layer
(
input
=
y
,
size
=
15
)
y2
=
fc_layer
(
input
=
y
,
size
=
15
)
...
@@ -28,7 +30,7 @@ cos3 = cos_sim(a=x1, b=y2, size=3)
...
@@ -28,7 +30,7 @@ cos3 = cos_sim(a=x1, b=y2, size=3)
linear_comb
=
linear_comb_layer
(
weights
=
x1
,
vectors
=
y2
,
size
=
3
)
linear_comb
=
linear_comb_layer
(
weights
=
x1
,
vectors
=
y2
,
size
=
3
)
out
=
fc_layer
(
input
=
[
cos1
,
cos3
,
linear_comb
],
out
=
fc_layer
(
input
=
[
cos1
,
cos3
,
linear_comb
,
z
],
size
=
num_classes
,
size
=
num_classes
,
act
=
SoftmaxActivation
())
act
=
SoftmaxActivation
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录