Skip to content

Commit bf4b532

Browse files
author
ranqiu
committed
Update annotations of layers.py
1 parent ac29d00 commit bf4b532

File tree

1 file changed

+85
-81
lines changed
  • python/paddle/trainer_config_helpers

1 file changed

+85
-81
lines changed

python/paddle/trainer_config_helpers/layers.py

Lines changed: 85 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,8 +2985,10 @@ def img_cmrnorm_layer(input,
29852985
layer_attr=None):
29862986
"""
29872987
Response normalization across feature maps.
2988-
The details please refer to
2989-
`Alex's paper <http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf>`_.
2988+
2989+
Reference:
2990+
ImageNet Classification with Deep Convolutional Neural Networks
2991+
http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf
29902992
29912993
The example usage is:
29922994
@@ -2995,7 +2997,7 @@ def img_cmrnorm_layer(input,
29952997
norm = img_cmrnorm_layer(input=net, size=5)
29962998
29972999
:param name: The name of this layer. It is optional.
2998-
:type name: None | basestring
3000+
:type name: basestring
29993001
:param input: The input of this layer.
30003002
:type input: LayerOutput
30013003
:param size: Normalize in number of :math:`size` feature maps.
@@ -3004,9 +3006,11 @@ def img_cmrnorm_layer(input,
30043006
:type scale: float
30053007
:param power: The hyper-parameter.
30063008
:type power: float
3007-
:param num_channels: input layer's filers number or channels. If
3008-
num_channels is None, it will be set automatically.
3009-
:param layer_attr: Extra Layer Attribute.
3009+
:param num_channels: The number of input channels. If the parameter is not set or
3010+
set to None, its actual value will be automatically set to
3011+
the channels number of the input.
3012+
:param layer_attr: The extra layer attributes. See ExtraLayerAttribute for
3013+
details.
30103014
:type layer_attr: ExtraLayerAttribute
30113015
:return: LayerOutput object.
30123016
:rtype: LayerOutput
@@ -3034,7 +3038,7 @@ def batch_norm_layer(input,
30343038
use_global_stats=None,
30353039
mean_var_names=None):
30363040
"""
3037-
Batch Normalization Layer. The notation of this layer as follow.
3041+
Batch Normalization Layer. The notation of this layer is as follows.
30383042
30393043
:math:`x` is the input features over a mini-batch.
30403044
@@ -3048,8 +3052,10 @@ def batch_norm_layer(input,
30483052
\\sigma_{\\beta}^{2} + \\epsilon}} \\qquad &//\ normalize \\\\
30493053
y_i &\\gets \\gamma \\hat{x_i} + \\beta \\qquad &//\ scale\ and\ shift
30503054
3051-
The details of batch normalization please refer to this
3052-
`paper <http://arxiv.org/abs/1502.03167>`_.
3055+
Reference:
3056+
Batch Normalization: Accelerating Deep Network Training by Reducing
3057+
Internal Covariate Shift
3058+
http://arxiv.org/abs/1502.03167
30533059
30543060
The example usage is:
30553061
@@ -3059,48 +3065,47 @@ def batch_norm_layer(input,
30593065
30603066
:param name: The name of this layer. It is optional.
30613067
:type name: basestring
3062-
:param input: batch normalization input. Better be linear activation.
3063-
Because there is an activation inside batch_normalization.
3068+
:param input: This layer's input which is to be performed batch normalization on.
30643069
:type input: LayerOutput
30653070
:param batch_norm_type: We have batch_norm, mkldnn_batch_norm and cudnn_batch_norm.
30663071
batch_norm supports CPU, MKLDNN and GPU. cudnn_batch_norm
30673072
requires cuDNN version greater or equal to v4 (>=v4).
30683073
But cudnn_batch_norm is faster and needs less
30693074
memory than batch_norm. mkldnn_batch_norm requires
3070-
enable use_mkldnn. By default (None), we will
3071-
automaticly select cudnn_batch_norm for GPU,
3075+
use_mkldnn is enabled. By default (None), we will
3076+
automatically select cudnn_batch_norm for GPU,
30723077
mkldnn_batch_norm for MKLDNN and batch_norm for CPU.
3073-
Otherwise, select batch norm type based on the
3074-
specified type. If you use cudnn_batch_norm,
3075-
we suggested you use latest version, such as v5.1.
3078+
Users can specify the batch norm type. If you use
3079+
cudnn_batch_norm, we suggested you use latest version,
3080+
such as v5.1.
30763081
:type batch_norm_type: None | string, None or "batch_norm" or "cudnn_batch_norm"
30773082
or "mkldnn_batch_norm"
3078-
:param act: Activation Type. Better be relu. Because batch
3079-
normalization will normalize input near zero.
3083+
:param act: Activation type. ReluActivation is the default activation.
30803084
:type act: BaseActivation
3081-
:param num_channels: num of image channels or previous layer's number of
3082-
filters. None will automatically get from layer's
3083-
input.
3085+
:param num_channels: The number of input channels. If the parameter is not set or
3086+
set to None, its actual value will be automatically set to
3087+
the channels number of the input.
30843088
:type num_channels: int
3085-
:param bias_attr: :math:`\\beta`, better be zero when initialize. So the
3086-
initial_std=0, initial_mean=1 is best practice.
3089+
:param bias_attr: :math:`\\beta`. The bias attribute. If the parameter is set to
3090+
False or an object whose type is not ParameterAttribute, no
3091+
bias is defined. If the parameter is set to True, the bias is
3092+
initialized to zero.
30873093
:type bias_attr: ParameterAttribute | None | bool | Any
3088-
:param param_attr: :math:`\\gamma`, better be one when initialize. So the
3089-
initial_std=0, initial_mean=1 is best practice.
3094+
:param param_attr: :math:`\\gamma`. The parameter attribute. See ParameterAttribute
3095+
for details.
30903096
:type param_attr: ParameterAttribute
3091-
:param layer_attr: Extra Layer Attribute.
3097+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
3098+
details.
30923099
:type layer_attr: ExtraLayerAttribute
3093-
:param use_global_stats: whether use moving mean/variance statistics
3094-
during testing peroid. If None or True,
3095-
it will use moving mean/variance statistics during
3096-
testing. If False, it will use the mean
3097-
and variance of current batch of test data for
3098-
testing.
3100+
:param use_global_stats: Whether use moving mean/variance statistics during
3101+
testing peroid. If the parameter is set to None or
3102+
True, it will use moving mean/variance statistics
3103+
during testing. If the parameter is set to False, it
3104+
will use the mean and variance of the current batch
3105+
of test data.
30993106
:type use_global_stats: bool | None.
3100-
:param moving_average_fraction: Factor used in the moving average
3101-
computation, referred to as facotr,
3102-
:math:`runningMean = newMean*(1-factor)
3103-
+ runningMean*factor`
3107+
:param moving_average_fraction: Factor used in the moving average computation.
3108+
:math:`runningMean = newMean*(1-factor) + runningMean*factor`
31043109
:type moving_average_fraction: float.
31053110
:param mean_var_names: [mean name, variance name]
31063111
:type mean_var_names: string list
@@ -3162,8 +3167,9 @@ def sum_to_one_norm_layer(input, name=None, layer_attr=None):
31623167
:type input: LayerOutput
31633168
:param name: The name of this layer. It is optional.
31643169
:type name: basestring
3165-
:param layer_attr: extra layer attributes.
3166-
:type layer_attr: ExtraLayerAttribute.
3170+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute
3171+
for details.
3172+
:type layer_attr: ExtraLayerAttribute
31673173
:return: LayerOutput object.
31683174
:rtype: LayerOutput
31693175
"""
@@ -3198,7 +3204,8 @@ def row_l2_norm_layer(input, name=None, layer_attr=None):
31983204
:type input: LayerOutput
31993205
:param name: The name of this layer. It is optional.
32003206
:type name: basestring
3201-
:param layer_attr: extra layer attributes.
3207+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute
3208+
for details.
32023209
:type layer_attr: ExtraLayerAttribute.
32033210
:return: LayerOutput object.
32043211
:rtype: LayerOutput
@@ -3235,22 +3242,17 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
32353242
act=ReluActivation(),
32363243
bias_attr=False)
32373244
3238-
This layer just simply add all input layers together, then activate the sum
3239-
inputs. Each input of this layer should be the same size, which is also the
3240-
output size of this layer.
3245+
This layer just simply adds all input layers together, then activates the
3246+
sum. All inputs should share the same dimension, which is also the dimension
3247+
of this layer's output.
32413248
32423249
There is no weight matrix for each input, because it just a simple add
32433250
operation. If you want a complicated operation before add, please use
32443251
mixed_layer.
32453252
3246-
It is a very good way to set dropout outside the layers. Since not all
3247-
PaddlePaddle layer support dropout, you can add an add_to layer, set
3248-
dropout here.
3249-
Please refer to dropout_layer for details.
3250-
32513253
:param name: The name of this layer. It is optional.
32523254
:type name: basestring
3253-
:param input: Input layers. It could be a LayerOutput or list/tuple of
3255+
:param input: The input layers. It could be a LayerOutput or list/tuple of
32543256
LayerOutput.
32553257
:type input: LayerOutput | list | tuple
32563258
:param act: Activation Type. LinearActivation is the default activation.
@@ -3259,7 +3261,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
32593261
whose type is not ParameterAttribute, no bias is defined. If the
32603262
parameter is set to True, the bias is initialized to zero.
32613263
:type bias_attr: ParameterAttribute | None | bool | Any
3262-
:param layer_attr: Extra Layer attribute.
3264+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
3265+
details.
32633266
:type layer_attr: ExtraLayerAttribute
32643267
:return: LayerOutput object.
32653268
:rtype: LayerOutput
@@ -3298,8 +3301,8 @@ def addto_layer(input, act=None, name=None, bias_attr=None, layer_attr=None):
32983301
@layer_support(DROPOUT, ERROR_CLIPPING)
32993302
def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
33003303
"""
3301-
Concat all input vector into one huge vector.
3302-
Inputs can be list of LayerOutput or list of projection.
3304+
Concatenate all input vectors to one vector.
3305+
Inputs can be a list of LayerOutput or a list of projection.
33033306
33043307
The example usage is:
33053308
@@ -3309,11 +3312,12 @@ def concat_layer(input, act=None, name=None, layer_attr=None, bias_attr=None):
33093312
33103313
:param name: The name of this layer. It is optional.
33113314
:type name: basestring
3312-
:param input: input layers or projections
3315+
:param input: The input layers or projections
33133316
:type input: list | tuple | collections.Sequence
33143317
:param act: Activation type. IdentityActivation is the default activation.
33153318
:type act: BaseActivation
3316-
:param layer_attr: Extra Layer Attribute.
3319+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
3320+
details.
33173321
:type layer_attr: ExtraLayerAttribute
33183322
:return: LayerOutput object.
33193323
:rtype: LayerOutput
@@ -3383,7 +3387,7 @@ def __reduce_concat_type__(a, b):
33833387
def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
33843388
bias_attr=None):
33853389
"""
3386-
Concat sequence a with sequence b.
3390+
Concatenate sequence a and sequence b.
33873391
33883392
Inputs:
33893393
- a = [a1, a2, ..., am]
@@ -3402,13 +3406,14 @@ def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
34023406
34033407
:param name: The name of this layer. It is optional.
34043408
:type name: basestring
3405-
:param a: input sequence layer
3409+
:param a: The first input sequence layer
34063410
:type a: LayerOutput
3407-
:param b: input sequence layer
3411+
:param b: The second input sequence layer
34083412
:type b: LayerOutput
34093413
:param act: Activation type. IdentityActivation is the default activation.
34103414
:type act: BaseActivation
3411-
:param layer_attr: Extra Layer Attribute.
3415+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
3416+
details.
34123417
:type layer_attr: ExtraLayerAttribute
34133418
:param bias_attr: The bias attribute. If the parameter is set to False or an object
34143419
whose type is not ParameterAttribute, no bias is defined. If the
@@ -3445,58 +3450,57 @@ def memory(name,
34453450
boot_bias_active_type=None,
34463451
boot_with_const_id=None):
34473452
"""
3448-
The memory layers is a layer cross each time step. Reference this output
3449-
as previous time step layer :code:`name` 's output.
3453+
The memory takes a layer's output at previous time step as its own output.
34503454
3451-
The default memory is zero in first time step, previous time step's
3452-
output in the rest time steps.
3455+
If boot_bias, the activation of the bias is the initial value of the memory.
34533456
3454-
If boot_bias, the first time step value is this bias and
3455-
with activation.
3457+
If boot_with_const_id is set, then the memory's output at the first time step
3458+
is a IndexSlot, the Arguments.ids()[0] is this :code:`cost_id`.
34563459
3457-
If boot_with_const_id, then the first time stop is a IndexSlot, the
3458-
Arguments.ids()[0] is this :code:`cost_id`.
3460+
If boot_layer is specified, the memory's output at the first time step will
3461+
be the boot_layer's output.
34593462
3460-
If boot_layer is not null, the memory is just the boot_layer's output.
3461-
Set :code:`is_seq` is true boot layer is sequence.
3462-
3463-
The same name layer in recurrent group will set memory on each time
3464-
step.
3463+
In other case, the default memory's output at the first time step is zero.
34653464
34663465
.. code-block:: python
34673466
34683467
mem = memory(size=256, name='state')
34693468
state = fc_layer(input=mem, size=256, name='state')
34703469
3471-
If you do not want to specify the name, you can equivalently use set_input()
3472-
to specify the layer needs to be remembered as the following:
3470+
If you do not want to specify the name, you can also use set_input()
3471+
to specify the layer to be remembered as the following:
34733472
34743473
.. code-block:: python
34753474
34763475
mem = memory(size=256)
34773476
state = fc_layer(input=mem, size=256)
34783477
mem.set_input(mem)
34793478
3480-
:param name: the name of the layer which this memory remembers.
3479+
:param name: The name of the layer which this memory remembers.
34813480
If name is None, user should call set_input() to specify the
34823481
name of the layer which this memory remembers.
34833482
:type name: basestring
3484-
:param size: size of memory.
3483+
:param size: The dimensionality of memory.
34853484
:type size: int
3486-
:param memory_name: the name of the memory.
3487-
It is ignored when name is provided.
3485+
:param memory_name: The name of the memory. It is ignored when name is provided.
34883486
:type memory_name: basestring
34893487
:param is_seq: DEPRECATED. is sequence for boot_layer
34903488
:type is_seq: bool
3491-
:param boot_layer: boot layer of memory.
3489+
:param boot_layer: This parameter specifies memory's output at the first time
3490+
step and the output is boot_layer's output.
34923491
:type boot_layer: LayerOutput | None
3493-
:param boot_bias: boot layer's bias
3492+
:param boot_bias: The bias attribute of memory's output at the first time step.
3493+
If the parameter is set to False or an object whose type is not
3494+
ParameterAttribute, no bias is defined. If the parameter is set
3495+
to True, the bias is initialized to zero.
34943496
:type boot_bias: ParameterAttribute | None
3495-
:param boot_bias_active_type: boot layer's active type.
3497+
:param boot_bias_active_type: Activation type for memory's bias at the first time
3498+
step. LinearActivation is the default activation.
34963499
:type boot_bias_active_type: BaseActivation
3497-
:param boot_with_const_id: boot layer's id.
3500+
:param boot_with_const_id: This parameter specifies memory's output at the first
3501+
time step and the output is an index.
34983502
:type boot_with_const_id: int
3499-
:return: LayerOutput object which is a memory.
3503+
:return: LayerOutput object.
35003504
:rtype: LayerOutput
35013505
"""
35023506
if boot_bias_active_type is None:

0 commit comments

Comments
 (0)