Skip to content

Commit 2955ff5

Browse files
committed
Polish documentation
* row_conv * uniform_random * layer_norm * create_parameter * hard_shrink * ssd_loss
1 parent 9328c3c commit 2955ff5

File tree

7 files changed

+115
-112
lines changed

7 files changed

+115
-112
lines changed

paddle/fluid/operators/activation_op.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,12 @@ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
276276
AddComment(R"DOC(
277277
HardShrink Activation Operator.
278278
279-
$$
280-
out = \begin{cases}
281-
x, \text{if } x > \lambda \\
282-
x, \text{if } x < -\lambda \\
283-
0, \text{otherwise}
284-
\end{cases}
285-
$$
279+
.. math::
280+
out = \begin{cases}
281+
x, \text{if } x > \lambda \\
282+
x, \text{if } x < -\lambda \\
283+
0, \text{otherwise}
284+
\end{cases}
286285
287286
)DOC");
288287
}

paddle/fluid/operators/layer_norm_op.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,48 @@ class LayerNormOp : public framework::OperatorWithKernel {
6262
class LayerNormOpMaker : public framework::OpProtoAndCheckerMaker {
6363
public:
6464
void Make() override {
65-
AddInput("X", "(LoDTensor) The input tensor.");
65+
AddInput("X", "The input tensor.");
6666
AddInput("Scale",
67-
"(Tensor, optional) Scale is a 1-dimensional tensor of size "
67+
"(optional) Scale is a 1-dimensional tensor of size "
6868
"H(`begin_norm_axis` splits the tensor(`X`) to a matrix [N,H])."
6969
"It is applied to the output.")
7070
.AsDispensable();
7171
AddInput("Bias",
72-
"(Tensor, optional) Bias is a 1-dimensional tensor of size "
72+
"(optional) Bias is a 1-dimensional tensor of size "
7373
"H(`begin_norm_axis` splits the tensor(`X`) to a matrix [N,H])."
7474
"It is applied to the output.")
7575
.AsDispensable();
76-
AddOutput("Y", "(LoDTensor) Result after normalization.");
77-
AddOutput("Mean", "(Tensor) Mean of the current mini batch.")
78-
.AsIntermediate();
79-
AddOutput("Variance", "(Tensor) Variance of the current mini batch.")
76+
AddOutput("Y", "Result after normalization.");
77+
AddOutput("Mean", "Mean of the current mini batch.").AsIntermediate();
78+
AddOutput("Variance", "Variance of the current mini batch.")
8079
.AsIntermediate();
8180

8281
AddAttr<float>("epsilon",
83-
"(float, default 1e-5) Constant for "
84-
"numerical stability")
82+
"Constant for numerical stability [default 1e-5].")
8583
.SetDefault(1e-5)
8684
.AddCustomChecker([](const float &epsilon) {
8785
PADDLE_ENFORCE(epsilon >= 0.0f && epsilon <= 0.001f,
8886
"'epsilon' should be between 0.0 and 0.001.");
8987
});
9088
AddAttr<int>("begin_norm_axis",
91-
"(int default:1), the "
92-
"axis of `begin_norm_axis ... Rank(X) - 1` will be "
89+
"the axis of `begin_norm_axis ... Rank(X) - 1` will be "
9390
"normalized. `begin_norm_axis` splits the tensor(`X`) to a "
94-
"matrix [N,H].")
91+
"matrix [N,H]. [default 1].")
9592
.SetDefault(1)
9693
.AddCustomChecker([](const int &begin_norm_axis) {
9794
PADDLE_ENFORCE_GT(begin_norm_axis, 0,
9895
"'begin_norm_axis' should be greater than zero.");
9996
});
10097

10198
AddComment(R"DOC(
102-
Layer Normalization.
103-
Layer Norm has been implemented as discussed in the paper:
104-
https://arxiv.org/abs/1607.06450
105-
...
99+
Assume feature vectors exist on dimensions
100+
:attr:`begin_norm_axis ... rank(input)` and calculate the moment statistics
101+
along these dimensions for each feature vector :math:`a` with size
102+
:math:`H`, then normalize each feature vector using the corresponding
103+
statistics. After that, apply learnable gain and bias on the normalized
104+
tensor to scale and shift if :attr:`scale` and :attr:`shift` are set.
105+
106+
Refer to `Layer Normalization <https://arxiv.org/pdf/1607.06450v1.pdf>`_
106107
)DOC");
107108
}
108109
};

paddle/fluid/operators/row_conv_op.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ class RowConvOpMaker : public framework::OpProtoAndCheckerMaker {
7878
public:
7979
void Make() override {
8080
AddInput("X",
81-
"(LoDTensor), the input(X) is a LodTensor, which supports "
81+
"the input(X) is a LodTensor, which supports "
8282
"variable time-length input sequences. The underlying tensor "
8383
"in this LoDTensor is a matrix with shape (T x N), where T "
8484
"is the total time steps in this mini-batch and N is the input "
8585
"data dimension.");
8686
AddInput("Filter",
87-
"(Tensor), the input(Filter) is a learnable parameter. It "
87+
"the input(Filter) is a learnable parameter. It "
8888
"is a 2-D tensor with shape (future_context x N), where, "
8989
"future_context is the future context length and N is the data "
9090
"dimension.");
9191
AddOutput("Out",
92-
"(LoDTensor), the output(Out) is a LodTensor, which supports "
92+
"the output(Out) is a LodTensor, which supports "
9393
"variable time-length input sequences. The underlying tensor "
9494
"in this LodTensor is a matrix with shape T x N, i.e., the "
9595
"same shape as X.");
@@ -117,6 +117,20 @@ the output sequence is convolved as:
117117
out_{i, :} = \sum_{j=i}^{i + context} in_{j,:} \dot W_{i-j, :}
118118
$$
119119
120+
In the above equation:
121+
122+
* $Out_{i}$: The i-th row of output variable with shape [1, D].
123+
124+
* $\\tau$: Future context size.
125+
126+
* $X_{j}$: The j-th row of input variable with shape [1, D].
127+
128+
* $W_{i-j}$: The (i-j)-th row of parameters with shape [1, D].
129+
130+
More details about row_conv please refer to
131+
the design document
132+
https://github.com/PaddlePaddle/Paddle/issues/2228#issuecomment-303903645 .
133+
120134
)DOC");
121135
}
122136
};

paddle/fluid/operators/uniform_random_op.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,26 @@ class UniformRandomOp : public framework::OperatorWithKernel {
8686
class UniformRandomOpMaker : public framework::OpProtoAndCheckerMaker {
8787
public:
8888
void Make() override {
89-
AddOutput("Out", "(Tensor) The output tensor of uniform random op");
89+
AddOutput("Out", "The output tensor of uniform random op");
9090
AddComment(R"DOC(
9191
Uniform random operator.
9292
9393
This operator initializes a tensor with random values sampled from a
94-
uniform distribution.
94+
uniform distribution. The random result is in set [min, max].
9595
9696
)DOC");
97-
AddAttr<std::vector<int>>("shape",
98-
"(vector<int>) The shape of the output tensor");
99-
AddAttr<float>("min",
100-
"(float, default -1.0) "
101-
"Minimum value of uniform random")
97+
AddAttr<std::vector<int>>("shape", "The shape of the output tensor");
98+
AddAttr<float>("min", "Minimum value of uniform random. [default -1.0].")
10299
.SetDefault(-1.0f);
103-
AddAttr<float>("max",
104-
"(float, default 1.0) "
105-
"Maximun value of uniform random")
100+
AddAttr<float>("max", "Maximun value of uniform random. [default 1.0].")
106101
.SetDefault(1.0f);
107102
AddAttr<int>("seed",
108-
"(int, default 0) "
109103
"Random seed used for generating samples. "
110104
"0 means use a seed generated by the system."
111105
"Note that if seed is not 0, this operator will always "
112-
"generate the same random numbers every time.")
106+
"generate the same random numbers every time. [default 0].")
113107
.SetDefault(0);
114-
AddAttr<int>("dtype", "(int, default 5(FP32)) Output tensor data type")
108+
AddAttr<int>("dtype", "Output tensor data type. [default 5(FP32)].")
115109
.SetDefault(framework::proto::VarType::FP32);
116110
}
117111
};

python/paddle/fluid/layers/detection.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -373,22 +373,55 @@ def ssd_loss(location,
373373
confidence loss (or classification loss) by performing the following steps:
374374
375375
1. Find matched boundding box by bipartite matching algorithm.
376+
376377
1.1 Compute IOU similarity between ground-truth boxes and prior boxes.
378+
377379
1.2 Compute matched boundding box by bipartite matching algorithm.
380+
378381
2. Compute confidence for mining hard examples
382+
379383
2.1. Get the target label based on matched indices.
384+
380385
2.2. Compute confidence loss.
386+
381387
3. Apply hard example mining to get the negative example indices and update
382388
the matched indices.
389+
383390
4. Assign classification and regression targets
391+
384392
4.1. Encoded bbox according to the prior boxes.
393+
385394
4.2. Assign regression targets.
395+
386396
4.3. Assign classification targets.
397+
387398
5. Compute the overall objective loss.
399+
388400
5.1 Compute confidence loss.
401+
389402
5.1 Compute localization loss.
403+
390404
5.3 Compute the overall weighted loss.
391405
406+
>>> import paddle.fluid.layers as layers
407+
>>> pb = layers.data(
408+
>>> name='prior_box',
409+
>>> shape=[10, 4],
410+
>>> append_batch_size=False,
411+
>>> dtype='float32')
412+
>>> pbv = layers.data(
413+
>>> name='prior_box_var',
414+
>>> shape=[10, 4],
415+
>>> append_batch_size=False,
416+
>>> dtype='float32')
417+
>>> loc = layers.data(name='target_box', shape=[10, 4], dtype='float32')
418+
>>> scores = layers.data(name='scores', shape=[10, 21], dtype='float32')
419+
>>> gt_box = layers.data(
420+
>>> name='gt_box', shape=[4], lod_level=1, dtype='float32')
421+
>>> gt_label = layers.data(
422+
>>> name='gt_label', shape=[1], lod_level=1, dtype='float32')
423+
>>> loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv)
424+
392425
Args:
393426
location (Variable): The location predictions are a 3D Tensor with
394427
shape [N, Np, 4], N is the batch size, Np is total number of
@@ -426,34 +459,12 @@ def ssd_loss(location,
426459
mining_type is 'hard_example'.
427460
428461
Returns:
429-
Variable: The weighted sum of the localization loss and confidence loss,
430-
with shape [N * Np, 1], N and Np are the same as they are
431-
in `location`.
462+
The weighted sum of the localization loss and confidence loss, with \
463+
shape [N * Np, 1], N and Np are the same as they are in `location`.
432464
433465
Raises:
434-
ValueError: If mining_type is 'hard_example', now only support
435-
mining type of `max_negative`.
436-
437-
Examples:
438-
.. code-block:: python
439-
440-
pb = layers.data(
441-
name='prior_box',
442-
shape=[10, 4],
443-
append_batch_size=False,
444-
dtype='float32')
445-
pbv = layers.data(
446-
name='prior_box_var',
447-
shape=[10, 4],
448-
append_batch_size=False,
449-
dtype='float32')
450-
loc = layers.data(name='target_box', shape=[10, 4], dtype='float32')
451-
scores = layers.data(name='scores', shape=[10, 21], dtype='float32')
452-
gt_box = layers.data(
453-
name='gt_box', shape=[4], lod_level=1, dtype='float32')
454-
gt_label = layers.data(
455-
name='gt_label', shape=[1], lod_level=1, dtype='float32')
456-
loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv)
466+
ValueError: If mining_type is 'hard_example', now only support mining \
467+
type of `max_negative`.
457468
"""
458469

459470
helper = LayerHelper('ssd_loss', **locals())

python/paddle/fluid/layers/nn.py

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ def batch_norm(input,
16241624
return helper.append_activation(batch_norm_out)
16251625

16261626

1627+
@templatedoc()
16271628
def layer_norm(input,
16281629
scale=True,
16291630
shift=True,
@@ -1634,27 +1635,23 @@ def layer_norm(input,
16341635
act=None,
16351636
name=None):
16361637
"""
1637-
**Layer Normalization**
1638-
1639-
Assume feature vectors exist on dimensions
1640-
:attr:`begin_norm_axis ... rank(input)` and calculate the moment statistics
1641-
along these dimensions for each feature vector :math:`a` with size
1642-
:math:`H`, then normalize each feature vector using the corresponding
1643-
statistics. After that, apply learnable gain and bias on the normalized
1644-
tensor to scale and shift if :attr:`scale` and :attr:`shift` are set.
1645-
1646-
Refer to `Layer Normalization <https://arxiv.org/pdf/1607.06450v1.pdf>`_
1638+
${comment}
16471639
16481640
The formula is as follows:
16491641
1650-
.. math::
1642+
.. math::
16511643
16521644
\\mu & = \\frac{1}{H}\\sum_{i=1}^{H} a_i
16531645
16541646
\\sigma & = \\sqrt{\\frac{1}{H}\sum_{i=1}^{H}(a_i - \\mu)^2}
16551647
16561648
h & = f(\\frac{g}{\\sigma}(a - \\mu) + b)
16571649
1650+
>>> import paddle.fluid as fluid
1651+
>>> data = fluid.layers.data(name='data', shape=[3, 32, 32],
1652+
>>> dtype='float32')
1653+
>>> x = fluid.layers.layer_norm(input=data, begin_norm_axis=1)
1654+
16581655
Args:
16591656
input(Variable): The input tensor variable.
16601657
scale(bool): Whether to learn the adaptive gain :math:`g` after
@@ -1672,14 +1669,7 @@ def layer_norm(input,
16721669
act(str): Activation to be applied to the output of layer normalizaiton.
16731670
16741671
Returns:
1675-
Variable: A tensor variable with the same shape as the input.
1676-
1677-
Examples:
1678-
.. code-block:: python
1679-
1680-
data = fluid.layers.data(
1681-
name='data', shape=[3, 32, 32], dtype='float32')
1682-
x = fluid.layers.layer_norm(input=data, begin_norm_axis=1)
1672+
${y_comment}
16831673
"""
16841674
helper = LayerHelper('layer_norm', **locals())
16851675
dtype = helper.input_dtype()
@@ -3184,44 +3174,27 @@ def im2sequence(input, filter_size=1, stride=1, padding=0, name=None):
31843174
return out
31853175

31863176

3177+
@templatedoc()
31873178
def row_conv(input, future_context_size, param_attr=None, act=None):
3188-
"""Row Conv Operator. This layer will apply lookahead convolution to
3189-
**input**. The input variable should be a 2D LoDTensor with shape [T, D].
3190-
Parameters with shape [future_context_size + 1, D] will be created. The math
3191-
equation of row convolution is as follows:
3192-
3193-
.. math::
3194-
Out_{i} = \sum_{j = i} ^ {i + \\tau} X_{j} \odot W_{i - j}
3195-
3196-
In the above equation:
3179+
"""
3180+
${comment}
31973181
3198-
* :math:`Out_{i}`: The i-th row of output variable with shape [1, D].
3199-
* :math:`\\tau`: Future context size.
3200-
* :math:`X_{j}`: The j-th row of input variable with shape [1, D].
3201-
* :math:`W_{i-j}`: The (i-j)-th row of parameters with shape [1, D].
3182+
>>> import paddle.fluid as fluid
3183+
>>> x = fluid.layers.data(name='x', shape=[16],
3184+
>>> dtype='float32', lod_level=1)
3185+
>>> out = fluid.layers.row_conv(input=x, future_context_size=2)
32023186
3203-
More details about row_conv please refer to the paper \
3204-
(http://www.cs.cmu.edu/~dyogatam/papers/wang+etal.iclrworkshop2016.pdf) and
3205-
the design document \
3206-
(https://github.com/PaddlePaddle/Paddle/issues/2228#issuecomment-303903645).
32073187
32083188
Args:
3209-
input (Variable): Input variable, a 2D LoDTensor with shape [T, D].
3189+
input (${x_type}): ${x_comment}.
32103190
future_context_size (int): Future context size. Please note, the shape
32113191
of convolution kernel is [future_context_size + 1, D].
32123192
param_attr (ParamAttr): Attributes of parameters, including
32133193
name, initializer etc.
32143194
act (str): Non-linear activation to be applied to output variable.
32153195
32163196
Returns:
3217-
Variable: The output tensor with same shape as input tensor.
3218-
3219-
Examples:
3220-
.. code-block:: python
3221-
3222-
x = fluid.layers.data(name='x', shape=[16],
3223-
dtype='float32', lod_level=1)
3224-
out = fluid.layers.row_conv(input=x, future_context_size=2)
3197+
${out_comment}.
32253198
"""
32263199
helper = LayerHelper('row_conv', **locals())
32273200
dtype = helper.input_dtype()

0 commit comments

Comments
 (0)