Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ddd41582
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看板
提交
ddd41582
编写于
12月 22, 2017
作者:
R
ranqiu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the annotations of layers.py
上级
76f0bd83
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
53 deletion
+56
-53
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+56
-53
未找到文件。
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
ddd41582
...
@@ -270,7 +270,7 @@ class LayerType(object):
...
@@ -270,7 +270,7 @@ class LayerType(object):
@
staticmethod
@
staticmethod
def
is_layer_type
(
type_name
):
def
is_layer_type
(
type_name
):
"""
"""
If
type_name is a layer type.
Whether
type_name is a layer type.
:param type_name: layer type name. Because layer type enumerations are
:param type_name: layer type name. Because layer type enumerations are
strings.
strings.
...
@@ -441,7 +441,7 @@ def full_matrix_projection(input, size=0, param_attr=None):
...
@@ -441,7 +441,7 @@ def full_matrix_projection(input, size=0, param_attr=None):
with mixed_layer(size=100) as m:
with mixed_layer(size=100) as m:
m += full_matrix_projection(input=layer)
m += full_matrix_projection(input=layer)
2. When used as an independ
a
nt object like this, you must set the size:
2. When used as an independ
e
nt object like this, you must set the size:
.. code-block:: python
.. code-block:: python
...
@@ -451,11 +451,11 @@ def full_matrix_projection(input, size=0, param_attr=None):
...
@@ -451,11 +451,11 @@ def full_matrix_projection(input, size=0, param_attr=None):
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param size: The
parameter size. Means the width of paramet
er.
:param size: The
dimension of this lay
er.
:type size: int
:type size: int
:param param_attr:
Parameter config, None if use default
.
:param param_attr:
The parameter attribute. See ParameterAttribute for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:return:
A
FullMatrixProjection Object.
:return: FullMatrixProjection Object.
:rtype: FullMatrixProjection
:rtype: FullMatrixProjection
"""
"""
proj
=
FullMatrixProjection
(
proj
=
FullMatrixProjection
(
...
@@ -468,12 +468,12 @@ def full_matrix_projection(input, size=0, param_attr=None):
...
@@ -468,12 +468,12 @@ def full_matrix_projection(input, size=0, param_attr=None):
def
trans_full_matrix_projection
(
input
,
size
=
0
,
param_attr
=
None
):
def
trans_full_matrix_projection
(
input
,
size
=
0
,
param_attr
=
None
):
"""
"""
Different from full_matrix_projection, this projection performs matrix
Different from full_matrix_projection, this projection performs matrix
multiplication, using transpose of weight.
multiplication, using t
he t
ranspose of weight.
.. math::
.. math::
out.row[i] += in.row[i] * w^\mathrm{T}
out.row[i] += in.row[i] * w^\mathrm{T}
:math:`w^\mathrm{T}` means transpose of weight.
:math:`w^\mathrm{T}` means t
he t
ranspose of weight.
The simply usage is:
The simply usage is:
.. code-block:: python
.. code-block:: python
...
@@ -489,9 +489,9 @@ def trans_full_matrix_projection(input, size=0, param_attr=None):
...
@@ -489,9 +489,9 @@ def trans_full_matrix_projection(input, size=0, param_attr=None):
:type input: LayerOutput
:type input: LayerOutput
:param size: The parameter size. Means the width of parameter.
:param size: The parameter size. Means the width of parameter.
:type size: int
:type size: int
:param param_attr:
Parameter config, None if use default
.
:param param_attr:
The parameter attribute. See ParameterAttribute for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:return:
A
TransposedFullMatrixProjection Object.
:return: TransposedFullMatrixProjection Object.
:rtype: TransposedFullMatrixProjection
:rtype: TransposedFullMatrixProjection
"""
"""
proj
=
TransposedFullMatrixProjection
(
proj
=
TransposedFullMatrixProjection
(
...
@@ -521,7 +521,7 @@ def table_projection(input, size=0, param_attr=None):
...
@@ -521,7 +521,7 @@ def table_projection(input, size=0, param_attr=None):
with mixed_layer(size=100) as m:
with mixed_layer(size=100) as m:
m += table_projection(input=layer)
m += table_projection(input=layer)
2. When used as an independ
a
nt object like this, you must set the size:
2. When used as an independ
e
nt object like this, you must set the size:
.. code-block:: python
.. code-block:: python
...
@@ -532,11 +532,11 @@ def table_projection(input, size=0, param_attr=None):
...
@@ -532,11 +532,11 @@ def table_projection(input, size=0, param_attr=None):
:param input: The input of this layer, which must contains id fields.
:param input: The input of this layer, which must contains id fields.
:type input: LayerOutput
:type input: LayerOutput
:param size: The
parameter size. Means the width of parameter
.
:param size: The
dimension of the output
.
:type size: int
:type size: int
:param param_attr:
Parameter config, None if use default
.
:param param_attr:
The parameter attribute. See ParameterAttribute for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:return:
A
TableProjection Object.
:return: TableProjection Object.
:rtype: TableProjection
:rtype: TableProjection
"""
"""
proj
=
TableProjection
(
proj
=
TableProjection
(
...
@@ -547,7 +547,7 @@ def table_projection(input, size=0, param_attr=None):
...
@@ -547,7 +547,7 @@ def table_projection(input, size=0, param_attr=None):
def
identity_projection
(
input
,
offset
=
None
,
size
=
None
):
def
identity_projection
(
input
,
offset
=
None
,
size
=
None
):
"""
"""
1. I
dentityProjection if offset=None. It perform
s:
1. I
f offset=None, it performs IdentityProjection as follow
s:
.. math::
.. math::
out.row[i] += in.row[i]
out.row[i] += in.row[i]
...
@@ -559,9 +559,8 @@ def identity_projection(input, offset=None, size=None):
...
@@ -559,9 +559,8 @@ def identity_projection(input, offset=None, size=None):
proj = identity_projection(input=layer)
proj = identity_projection(input=layer)
2. IdentityOffsetProjection if offset!=None. It likes IdentityProjection,
2. If offset!=None, It executes IdentityOffsetProjection and takes the
but layer size may be smaller than input size.
elements of the input in the range [offset, offset+size) as output.
It select dimesions [offset, offset+layer_size) from input:
.. math::
.. math::
out.row[i] += in.row[i +
\\
textrm{offset}]
out.row[i] += in.row[i +
\\
textrm{offset}]
...
@@ -573,14 +572,20 @@ def identity_projection(input, offset=None, size=None):
...
@@ -573,14 +572,20 @@ def identity_projection(input, offset=None, size=None):
proj = identity_projection(input=layer,
proj = identity_projection(input=layer,
offset=10)
offset=10)
Note that
both of two projections should not have any
parameter.
Note that
neither of the projections have trainable
parameter.
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param offset: Offset, None if use default.
:param offset: The offset from the start of the input. The input's
elements in the range [offset, offset+size) will be
taken as output. If this parameter is not set or set
to None, the output will be the same as the input.
:type offset: int
:type offset: int
:return: A IdentityProjection or IdentityOffsetProjection object
:param size: The dimension of this layer. It will be neglected
:rtype: IdentityProjection or IdentityOffsetProjection
when offset is None or not set.
:type size: int
:return: IdentityProjection or IdentityOffsetProjection object
:rtype: IdentityProjection | IdentityOffsetProjection
"""
"""
if
offset
is
None
:
if
offset
is
None
:
proj
=
IdentityProjection
(
input_layer_name
=
input
.
name
)
proj
=
IdentityProjection
(
input_layer_name
=
input
.
name
)
...
@@ -596,8 +601,8 @@ def identity_projection(input, offset=None, size=None):
...
@@ -596,8 +601,8 @@ def identity_projection(input, offset=None, size=None):
def
slice_projection
(
input
,
slices
):
def
slice_projection
(
input
,
slices
):
"""
"""
slice_projection
can slice
the input value into multiple parts,
slice_projection
slices
the input value into multiple parts,
and then select some of them to merge
into a new output.
then selects and merges some of them
into a new output.
.. math::
.. math::
output = [input.slices()]
output = [input.slices()]
...
@@ -608,15 +613,13 @@ def slice_projection(input, slices):
...
@@ -608,15 +613,13 @@ def slice_projection(input, slices):
proj = slice_projection(input=layer, slices=[(0, 10), (20, 30)])
proj = slice_projection(input=layer, slices=[(0, 10), (20, 30)])
Note that slice_projection
should not have any
parameter.
Note that slice_projection
has no trainable
parameter.
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param slices: An array of slice parameters.
:param slices: A list of start and end offsets of each slice.
Each slice contains the start and end offsets based
:type slices: list of tuple
on the input.
:return: SliceProjection object.
:type slices: pair of int
:return: A SliceProjection object
:rtype: SliceProjection
:rtype: SliceProjection
"""
"""
assert
len
(
slices
)
>=
1
assert
len
(
slices
)
>=
1
...
@@ -636,8 +639,7 @@ def slice_projection(input, slices):
...
@@ -636,8 +639,7 @@ def slice_projection(input, slices):
@
wrap_param_attr_default
()
@
wrap_param_attr_default
()
def
scaling_projection
(
input
,
param_attr
=
None
):
def
scaling_projection
(
input
,
param_attr
=
None
):
"""
"""
scaling_projection multiplies the input with a scalar parameter and add to
scaling_projection multiplies the input with a scalar parameter.
the output.
.. math::
.. math::
out += w * in
out += w * in
...
@@ -650,9 +652,9 @@ def scaling_projection(input, param_attr=None):
...
@@ -650,9 +652,9 @@ def scaling_projection(input, param_attr=None):
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param param_attr:
Parameter config, None if use default
.
:param param_attr:
The parameter attribute. See ParameterAttribute for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:return:
A ScalingProjection object
:return:
ScalingProjection object.
:rtype: ScalingProjection
:rtype: ScalingProjection
"""
"""
proj
=
ScalingProjection
(
input_layer_name
=
input
.
name
,
**
param_attr
.
attr
)
proj
=
ScalingProjection
(
input_layer_name
=
input
.
name
,
**
param_attr
.
attr
)
...
@@ -663,8 +665,8 @@ def scaling_projection(input, param_attr=None):
...
@@ -663,8 +665,8 @@ def scaling_projection(input, param_attr=None):
@
wrap_param_attr_default
()
@
wrap_param_attr_default
()
def
dotmul_projection
(
input
,
param_attr
=
None
):
def
dotmul_projection
(
input
,
param_attr
=
None
):
"""
"""
DotMulProjection
with a layer as input.
DotMulProjection
takes a layer as input and performs
It performs
element-wise multiplication with weight.
element-wise multiplication with weight.
.. math::
.. math::
out.row[i] += in.row[i] .* weight
out.row[i] += in.row[i] .* weight
...
@@ -679,9 +681,9 @@ def dotmul_projection(input, param_attr=None):
...
@@ -679,9 +681,9 @@ def dotmul_projection(input, param_attr=None):
:param input: The input of this layer.
:param input: The input of this layer.
:type input: LayerOutput
:type input: LayerOutput
:param param_attr:
Parameter config, None if use default
.
:param param_attr:
The parameter attribute. See ParameterAttribute for details
.
:type param_attr: ParameterAttribute
:type param_attr: ParameterAttribute
:return:
A DotMulProjection O
bject.
:return:
DotMulProjection o
bject.
:rtype: DotMulProjection
:rtype: DotMulProjection
"""
"""
proj
=
DotMulProjection
(
proj
=
DotMulProjection
(
...
@@ -698,7 +700,7 @@ def dotmul_operator(a=None, b=None, scale=1, **kwargs):
...
@@ -698,7 +700,7 @@ def dotmul_operator(a=None, b=None, scale=1, **kwargs):
out.row[i] += scale * (a.row[i] .* b.row[i])
out.row[i] += scale * (a.row[i] .* b.row[i])
where :math:`.*` means element-wise multiplication, and
where :math:`.*` means element-wise multiplication, and
scale is a config scalar, its default value is
one
.
scale is a config scalar, its default value is
1
.
The example usage is:
The example usage is:
...
@@ -706,13 +708,13 @@ def dotmul_operator(a=None, b=None, scale=1, **kwargs):
...
@@ -706,13 +708,13 @@ def dotmul_operator(a=None, b=None, scale=1, **kwargs):
op = dotmul_operator(a=layer1, b=layer2, scale=0.5)
op = dotmul_operator(a=layer1, b=layer2, scale=0.5)
:param a:
Input layer1
:param a:
The first input of this layer.
:type a: LayerOutput
:type a: LayerOutput
:param b:
Input layer2
:param b:
The second input of this layer.
:type b: LayerOutput
:type b: LayerOutput
:param scale:
config scalar, default value is one
.
:param scale:
A scalar to scale the product. Its default value is 1
.
:type scale: float
:type scale: float
:return:
A DotMulOperator O
bject.
:return:
DotMulOperator o
bject.
:rtype: DotMulOperator
:rtype: DotMulOperator
"""
"""
if
'x'
in
kwargs
or
'y'
in
kwargs
:
if
'x'
in
kwargs
or
'y'
in
kwargs
:
...
@@ -738,28 +740,29 @@ def context_projection(input,
...
@@ -738,28 +740,29 @@ def context_projection(input,
"""
"""
Context Projection.
Context Projection.
It just
simply reorganizes input sequence, combines "context_len" sequenc
e
It just
reorganizes input sequence, combines "context_len" elements of th
e
to one context from context_start. "context_start" will be set to
sequence
to one context from context_start. "context_start" will be set to
-(context_len - 1) / 2 by default.
If context position
out of sequence
-(context_len - 1) / 2 by default.
When context position is
out of sequence
length, padding will be filled as zero if padding_attr = False, otherwise
length, padding will be filled as zero if padding_attr = False, otherwise
it is trainable.
it is trainable.
For example, origin sequence is [A B C D E F G], context len is 3,
then
For example, origin sequence is [A B C D E F G], context len is 3,
padding_attr
after context projection and not set padding_attr
, sequence will
is not set, then after context projection
, sequence will
be [ 0AB ABC BCD CDE DEF EFG FG0 ].
be [ 0AB ABC BCD CDE DEF EFG FG0 ].
:param input: The input of this layer, which should be a sequence.
:param input: The input of this layer, which should be a sequence.
:type input: LayerOutput
:type input: LayerOutput
:param context_len:
context length
.
:param context_len:
The length of the context
.
:type context_len: int
:type context_len: int
:param context_start:
context start position. Default
is
:param context_start:
The start position of the context. The default value
is
-(context_len - 1)/2
-(context_len - 1)/2
:type context_start: int
:type context_start: int
:param padding_attr: Padding Parameter Attribute. If false, it means padding
:param padding_attr: Parameter attribute of the padding. If the parameter is
always be zero. Otherwise Padding is learnable, and
set to False, padding will be zero. In other cases, the
parameter attribute is set by this parameter.
padding is trainable, and its parameter attribute is set
by this parameter.
:type padding_attr: bool | ParameterAttribute
:type padding_attr: bool | ParameterAttribute
:return: Projection
:return: Projection
object.
:rtype: Projection
:rtype: Projection
"""
"""
context_start
=
-
(
context_start
=
-
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录