Skip to content

Commit ea8e050

Browse files
author
ranqiu
committed
Update doc of layers.py
1 parent 0e73967 commit ea8e050

File tree

1 file changed

+106
-72
lines changed
  • python/paddle/trainer_config_helpers

1 file changed

+106
-72
lines changed

python/paddle/trainer_config_helpers/layers.py

Lines changed: 106 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,9 +4495,9 @@ def conv_projection(input,
44954495
param_attr=None,
44964496
trans=False):
44974497
"""
4498-
Different from img_conv_layer and conv_op, conv_projection is an Projection,
4499-
which can be used in mixed_layer and conat_layer. It use cudnn to implement
4500-
conv and only support GPU mode.
4498+
Different from img_conv_layer and conv_op, conv_projection is a Projection,
4499+
which can be used in mixed_layer and concat_layer. It uses cudnn to implement
4500+
convolution and only supports GPU mode.
45014501
45024502
The example usage is:
45034503
@@ -4510,32 +4510,45 @@ def conv_projection(input,
45104510
45114511
:param input: The input of this layer.
45124512
:type input: LayerOutput
4513-
:param filter_size: The x dimension of a filter kernel.
4514-
:type filter_size: int
4515-
:param filter_size_y: The y dimension of a filter kernel. Since
4516-
PaddlePaddle now supports rectangular filters,
4517-
the filter's shape can be (filter_size, filter_size_y).
4513+
:param filter_size: The dimensions of the filter kernel. If the parameter is
4514+
set to one integer, the two dimensions on x and y axises
4515+
will be same when filter_size_y is not set. If it is set
4516+
to a list, the first element indicates the dimension on
4517+
the x axis, and the second is used to specify the dimension
4518+
on the y axis when filter_size is not provided.
4519+
:type filter_size: int | tuple | list
4520+
:param filter_size_y: The dimension of the filter kernel on the y axis. If the parameter
4521+
is not set, it will be set automatically according to filter_size.
45184522
:type filter_size_y: int
4519-
:param num_filters: channel of output data.
4523+
:param num_filters: The number of filters.
45204524
:type num_filters: int
4521-
:param num_channels: channel of input data.
4525+
:param num_channels: The number of the input channels.
45224526
:type num_channels: int
4523-
:param stride: The x dimension of the stride.
4524-
:type stride: int
4525-
:param stride_y: The y dimension of the stride.
4527+
:param stride: The strides. If the parameter is set to one integer, the strides
4528+
on x and y axises will be same when stride_y is not set. If it is
4529+
set to a list, the first element indicates the stride on the x axis,
4530+
and the second is used to specify the stride on the y axis when
4531+
stride_y is not provided.
4532+
:type stride: int | tuple | list
4533+
:param stride_y: The stride on the y axis.
45264534
:type stride_y: int
4527-
:param padding: The x dimension of padding.
4528-
:type padding: int
4529-
:param padding_y: The y dimension of padding.
4535+
:param padding: The padding sizes. If the parameter is set to one integer, the padding
4536+
sizes on x and y axises will be same when padding_y is not set. If it
4537+
is set to a list, the first element indicates the padding size on the
4538+
x axis, and the second is used to specify the padding size on the y axis
4539+
when padding_y is not provided.
4540+
:type padding: int | tuple | list
4541+
:param padding_y: The padding size on the y axis.
45304542
:type padding_y: int
45314543
:param groups: The group number.
45324544
:type groups: int
4533-
:param param_attr: Convolution param attribute. None means default attribute
4545+
:param param_attr: The parameter attribute of the convolution. See ParameterAttribute for
4546+
details.
45344547
:type param_attr: ParameterAttribute
4535-
:param trans: whether it is convTrans or conv
4548+
:param trans: Whether it is ConvTransProjection or ConvProjection
45364549
:type trans: bool
4537-
:return: A DotMulProjection Object.
4538-
:rtype: DotMulProjection
4550+
:return: A Projection Object.
4551+
:rtype: ConvTransProjection | ConvProjection
45394552
"""
45404553
if num_channels is None:
45414554
assert input.num_filters is not None
@@ -4600,13 +4613,13 @@ def pad_layer(input,
46004613
layer_attr=None):
46014614
"""
46024615
This operation pads zeros to the input data according to pad_c,pad_h
4603-
and pad_w. pad_c, pad_h, pad_w specifies the which dimension and size
4604-
of padding. And the input data shape is NCHW.
4616+
and pad_w. pad_c, pad_h, pad_w specify the size in the corresponding
4617+
dimension. And the input data shape is NCHW.
46054618
4606-
For example, pad_c=[2,3] means padding 2 zeros before the
4607-
input data and 3 zeros after the input data in channel dimension.
4608-
pad_h means padding zeros in height dimension. pad_w means padding zeros
4609-
in width dimension.
4619+
For example, pad_c=[2,3] means padding 2 zeros before the input data
4620+
and 3 zeros after the input data in the channel dimension. pad_h means
4621+
padding zeros in the height dimension. pad_w means padding zeros in the
4622+
width dimension.
46104623
46114624
For example,
46124625
@@ -4643,13 +4656,14 @@ def pad_layer(input,
46434656
46444657
:param input: The input of this layer.
46454658
:type input: LayerOutput
4646-
:param pad_c: padding size in channel dimension.
4659+
:param pad_c: The padding size in the channel dimension.
46474660
:type pad_c: list | None
4648-
:param pad_h: padding size in height dimension.
4661+
:param pad_h: The padding size in the height dimension.
46494662
:type pad_h: list | None
4650-
:param pad_w: padding size in width dimension.
4663+
:param pad_w: The padding size in the width dimension.
46514664
:type pad_w: list | None
4652-
:param layer_attr: Extra Layer Attribute.
4665+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4666+
details.
46534667
:type layer_attr: ExtraLayerAttribute
46544668
:param name: The name of this layer. It is optional.
46554669
:type name: basestring
@@ -4698,7 +4712,7 @@ def pad_layer(input,
46984712
@layer_support()
46994713
def conv_shift_layer(a, b, name=None, layer_attr=None):
47004714
"""
4701-
This layer performs cyclic convolution for two input. For example:
4715+
This layer performs cyclic convolution on two inputs. For example:
47024716
- a[in]: contains M elements.
47034717
- b[in]: contains N elements (N should be odd).
47044718
- c[out]: contains M elements.
@@ -4707,7 +4721,7 @@ def conv_shift_layer(a, b, name=None, layer_attr=None):
47074721
47084722
c[i] = \sum_{j=-(N-1)/2}^{(N-1)/2}a_{i+j} * b_{j}
47094723
4710-
In this formular:
4724+
In this formula:
47114725
- a's index is computed modulo M. When it is negative, then get item from
47124726
the right side (which is the end of array) to the left.
47134727
- b's index is computed modulo N. When it is negative, then get item from
@@ -4721,11 +4735,12 @@ def conv_shift_layer(a, b, name=None, layer_attr=None):
47214735
47224736
:param name: The name of this layer. It is optional.
47234737
:type name: basestring
4724-
:param a: Input layer a.
4738+
:param a: The first input of this layer.
47254739
:type a: LayerOutput
4726-
:param b: input layer b.
4740+
:param b: The second input of this layer.
47274741
:type b: LayerOutput
4728-
:param layer_attr: layer's extra attribute.
4742+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4743+
details.
47294744
:type layer_attr: ExtraLayerAttribute
47304745
:return: LayerOutput object.
47314746
:rtype: LayerOutput
@@ -4756,8 +4771,8 @@ def tensor_layer(a,
47564771
bias_attr=None,
47574772
layer_attr=None):
47584773
"""
4759-
This layer performs tensor operation for two input.
4760-
For example, each sample:
4774+
This layer performs tensor operation on two inputs.
4775+
For example:
47614776
47624777
.. math::
47634778
y_{i} = a * W_{i} * {b^\mathrm{T}}, i=0,1,...,K-1
@@ -4777,21 +4792,23 @@ def tensor_layer(a,
47774792
47784793
:param name: The name of this layer. It is optional.
47794794
:type name: basestring
4780-
:param a: Input layer a.
4795+
:param a: The first input of this layer.
47814796
:type a: LayerOutput
4782-
:param b: input layer b.
4797+
:param b: The second input of this layer.
47834798
:type b: LayerOutput
4784-
:param size: the layer dimension.
4785-
:type size: int.
4799+
:param size: The dimension of this layer.
4800+
:type size: int
47864801
:param act: Activation type. LinearActivation is the default.
47874802
:type act: BaseActivation
4788-
:param param_attr: The Parameter Attribute.
4803+
:param param_attr: The parameter attribute. See ParameterAttribute for
4804+
details.
47894805
:type param_attr: ParameterAttribute
47904806
:param bias_attr: The bias attribute. If the parameter is set to False or an object
47914807
whose type is not ParameterAttribute, no bias is defined. If the
47924808
parameter is set to True, the bias is initialized to zero.
47934809
:type bias_attr: ParameterAttribute | None | bool | Any
4794-
:param layer_attr: Extra Layer config.
4810+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4811+
details.
47954812
:type layer_attr: ExtraLayerAttribute | None
47964813
:return: LayerOutput object.
47974814
:rtype: LayerOutput
@@ -4827,7 +4844,7 @@ def selective_fc_layer(input,
48274844
layer_attr=None):
48284845
"""
48294846
Selectived fully connected layer. Different from fc_layer, the output
4830-
of this layer maybe sparse. It requires an additional input to indicate
4847+
of this layer can be sparse. It requires an additional input to indicate
48314848
several selected columns for output. If the selected columns is not
48324849
specified, selective_fc_layer acts exactly like fc_layer.
48334850
@@ -4841,21 +4858,33 @@ def selective_fc_layer(input,
48414858
:type name: basestring
48424859
:param input: The input of this layer.
48434860
:type input: LayerOutput | list | tuple
4844-
:param select: The select layer. The output of select layer should be a
4845-
sparse binary matrix, and treat as the mask of selective fc.
4846-
If is None, acts exactly like fc_layer.
4861+
:param select: The layer to select columns to output. It should be a sparse
4862+
binary matrix, and is treated as the mask of selective fc. If
4863+
it is not set or set to None, selective_fc_layer acts exactly
4864+
like fc_layer.
48474865
:type select: LayerOutput
4848-
:param size: The layer dimension.
4866+
:param size: The dimension of this layer, which should be equal to that of
4867+
the layer 'select'.
48494868
:type size: int
48504869
:param act: Activation type. TanhActivation is the default.
48514870
:type act: BaseActivation
4852-
:param param_attr: The Parameter Attribute.
4871+
:param pass_generation: The flag which indicates whether it is during generation.
4872+
:type pass_generation: bool
4873+
:param has_selected_colums: The flag which indicates whether the parameter 'select'
4874+
has been set. True is the default.
4875+
:type has_selected_colums: bool
4876+
:param mul_ratio: A ratio helps to judge how sparse the output is and determine
4877+
the computation method for speed consideration.
4878+
:type mul_ratio: float
4879+
:param param_attr: The parameter attribute. See ParameterAttribute for
4880+
details.
48534881
:type param_attr: ParameterAttribute
48544882
:param bias_attr: The bias attribute. If the parameter is set to False or an object
48554883
whose type is not ParameterAttribute, no bias is defined. If the
48564884
parameter is set to True, the bias is initialized to zero.
48574885
:type bias_attr: ParameterAttribute | None | bool | Any
4858-
:param layer_attr: Extra Layer config.
4886+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4887+
details.
48594888
:type layer_attr: ExtraLayerAttribute | None
48604889
:return: LayerOutput object.
48614890
:rtype: LayerOutput
@@ -4906,7 +4935,7 @@ def selective_fc_layer(input,
49064935
@layer_support()
49074936
def sampling_id_layer(input, name=None, layer_attr=None):
49084937
"""
4909-
A layer for sampling id from multinomial distribution from the input layer.
4938+
A layer for sampling id from a multinomial distribution from the input layer.
49104939
Sampling one id for one sample.
49114940
49124941
The simple usage is:
@@ -4919,8 +4948,9 @@ def sampling_id_layer(input, name=None, layer_attr=None):
49194948
:type input: LayerOutput
49204949
:param name: The name of this layer. It is optional.
49214950
:type name: basestring
4922-
:param layer_attr: Extra Layer config.
4923-
:type layer_attr: ExtraLayerAttribute | None
4951+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4952+
details.
4953+
:type layer_attr: ExtraLayerAttribute
49244954
:return: LayerOutput object.
49254955
:rtype: LayerOutput
49264956
"""
@@ -4941,8 +4971,7 @@ def slope_intercept_layer(input,
49414971
intercept=0.0,
49424972
layer_attr=None):
49434973
"""
4944-
This layer for applying a slope and an intercept to the input
4945-
element-wise. There is no activation and weight.
4974+
This layer for applying a slope and an intercept to the input.
49464975
49474976
.. math::
49484977
y = slope * x + intercept
@@ -4957,12 +4986,13 @@ def slope_intercept_layer(input,
49574986
:type input: LayerOutput
49584987
:param name: The name of this layer. It is optional.
49594988
:type name: basestring
4960-
:param slope: the scale factor.
4961-
:type slope: float.
4962-
:param intercept: the offset.
4963-
:type intercept: float.
4964-
:param layer_attr: Extra Layer config.
4965-
:type layer_attr: ExtraLayerAttribute | None
4989+
:param slope: The scale factor.
4990+
:type slope: float
4991+
:param intercept: The offset.
4992+
:type intercept: float
4993+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
4994+
details.
4995+
:type layer_attr: ExtraLayerAttribute
49664996
:return: LayerOutput object.
49674997
:rtype: LayerOutput
49684998
"""
@@ -5017,12 +5047,13 @@ def linear_comb_layer(weights, vectors, size=None, name=None, layer_attr=None):
50175047
:type weights: LayerOutput
50185048
:param vectors: The vector layer.
50195049
:type vectors: LayerOutput
5020-
:param size: the dimension of this layer.
5050+
:param size: The dimension of this layer.
50215051
:type size: int
50225052
:param name: The name of this layer. It is optional.
50235053
:type name: basestring
5024-
:param layer_attr: Extra Layer config.
5025-
:type layer_attr: ExtraLayerAttribute | None
5054+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
5055+
details.
5056+
:type layer_attr: ExtraLayerAttribute
50265057
:return: LayerOutput object.
50275058
:rtype: LayerOutput
50285059
"""
@@ -5069,11 +5100,11 @@ def block_expand_layer(input,
50695100
50705101
outputW = 1 + (2 * padding_x + imgSizeW - block_x + stride_x - 1) / stride_x
50715102
5072-
The expand method is the same with ExpandConvLayer, but saved the transposed
5103+
The expanding method is the same with ExpandConvLayer, but saved the transposed
50735104
value. After expanding, output.sequenceStartPositions will store timeline.
5074-
The number of time steps are outputH * outputW and the dimension of each
5105+
The number of time steps is outputH * outputW and the dimension of each
50755106
time step is block_y * block_x * num_channels. This layer can be used after
5076-
convolution neural network, and before recurrent neural network.
5107+
convolutional neural network, and before recurrent neural network.
50775108
50785109
The simple usage is:
50795110
@@ -5088,8 +5119,10 @@ def block_expand_layer(input,
50885119
50895120
:param input: The input of this layer.
50905121
:type input: LayerOutput
5091-
:param num_channels: The channel number of input layer.
5092-
:type num_channels: int | None
5122+
:param num_channels: The number of input channels. If the parameter is not set or
5123+
set to None, its actual value will be automatically set to
5124+
the channels number of the input.
5125+
:type num_channels: int
50935126
:param block_x: The width of sub block.
50945127
:type block_x: int
50955128
:param block_y: The width of sub block.
@@ -5103,9 +5136,10 @@ def block_expand_layer(input,
51035136
:param padding_y: The padding size in vertical direction.
51045137
:type padding_y: int
51055138
:param name: The name of this layer. It is optional.
5106-
:type name: None | basestring.
5107-
:param layer_attr: Extra Layer config.
5108-
:type layer_attr: ExtraLayerAttribute | None
5139+
:type name: basestring.
5140+
:param layer_attr: The extra layer attribute. See ExtraLayerAttribute for
5141+
details.
5142+
:type layer_attr: ExtraLayerAttribute
51095143
:return: LayerOutput object.
51105144
:rtype: LayerOutput
51115145
"""

0 commit comments

Comments
 (0)