Skip to content

Commit ce60bbf

Browse files
authored
Merge pull request #11314 from typhoonzero/fix_api_reference_docs
Fix api reference docs
2 parents 4360963 + 7a56705 commit ce60bbf

File tree

13 files changed

+252
-197
lines changed

13 files changed

+252
-197
lines changed

paddle/fluid/operators/chunk_eval_op.cc

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,64 +91,63 @@ class ChunkEvalOpMaker : public framework::OpProtoAndCheckerMaker {
9191
"(int64_t). The number of chunks both in Inference and Label on the "
9292
"given mini-batch.");
9393
AddAttr<int>("num_chunk_types",
94-
"(int). The number of chunk type. See below for details.");
95-
AddAttr<std::string>(
96-
"chunk_scheme",
97-
"(string, default IOB). The labeling scheme indicating "
98-
"how to encode the chunks. Must be IOB, IOE, IOBES or plain. See below "
99-
"for details.")
94+
"The number of chunk type. See the description for details.");
95+
AddAttr<std::string>("chunk_scheme",
96+
"The labeling scheme indicating "
97+
"how to encode the chunks. Must be IOB, IOE, IOBES or "
98+
"plain. See the description"
99+
"for details.")
100100
.SetDefault("IOB");
101101
AddAttr<std::vector<int>>("excluded_chunk_types",
102-
"(list<int>) A list including chunk type ids "
102+
"A list including chunk type ids "
103103
"indicating chunk types that are not counted. "
104-
"See below for details.")
104+
"See the description for details.")
105105
.SetDefault(std::vector<int>{});
106106
AddComment(R"DOC(
107107
For some basics of chunking, please refer to
108-
Chunking with Support Vector Machines <https://aclanthology.info/pdf/N/N01/N01-1025.pdf>.
108+
'Chunking with Support Vector Machines <https://aclanthology.info/pdf/N/N01/N01-1025.pdf>'.
109109
110-
111-
CheckEvalOp computes the precision, recall, and F1-score of chunk detection,
110+
ChunkEvalOp computes the precision, recall, and F1-score of chunk detection,
112111
and supports IOB, IOE, IOBES and IO (also known as plain) tagging schemes.
113112
Here is a NER example of labeling for these tagging schemes:
114-
115-
Li Ming works at Agricultural Bank of China in Beijing.
116-
IO: I-PER I-PER O O I-ORG I-ORG I-ORG I-ORG O I-LOC
117-
IOB: B-PER I-PER O O B-ORG I-ORG I-ORG I-ORG O B-LOC
118-
IOE: I-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O E-LOC
119-
IOBES: B-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O S-LOC
113+
114+
Li Ming works at Agricultural Bank of China in Beijing.
115+
IO I-PER I-PER O O I-ORG I-ORG I-ORG I-ORG O I-LOC
116+
IOB B-PER I-PER O O B-ORG I-ORG I-ORG I-ORG O B-LOC
117+
IOE I-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O E-LOC
118+
IOBES B-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O S-LOC
120119
121120
There are three chunk types(named entity types) including PER(person), ORG(organization)
122121
and LOC(LOCATION), and we can see that the labels have the form <tag type>-<chunk type>.
123122
124123
Since the calculations actually use label ids rather than labels, extra attention
125124
should be paid when mapping labels to ids to make CheckEvalOp work. The key point
126125
is that the listed equations are satisfied by ids.
127-
128-
tag_type = label % num_tag_type
129-
chunk_type = label / num_tag_type
126+
127+
tag_type = label % num_tag_type
128+
chunk_type = label / num_tag_type
130129
131130
where `num_tag_type` is the num of tag types in the tagging scheme, `num_chunk_type`
132131
is the num of chunk types, and `tag_type` get its value from the following table.
133-
134-
Scheme Begin Inside End Single
135-
plain 0 - - -
136-
IOB 0 1 - -
137-
IOE - 0 1 -
138-
IOBES 0 1 2 3
132+
133+
Scheme Begin Inside End Single
134+
plain 0 - - -
135+
IOB 0 1 - -
136+
IOE - 0 1 -
137+
IOBES 0 1 2 3
139138
140139
Still use NER as example, assuming the tagging scheme is IOB while chunk types are ORG,
141140
PER and LOC. To satisfy the above equations, the label map can be like this:
142141
143-
B-ORG 0
144-
I-ORG 1
145-
B-PER 2
146-
I-PER 3
147-
B-LOC 4
148-
I-LOC 5
149-
O 6
142+
B-ORG 0
143+
I-ORG 1
144+
B-PER 2
145+
I-PER 3
146+
B-LOC 4
147+
I-LOC 5
148+
O 6
150149
151-
Its not hard to verify the equations noting that the num of chunk types
150+
It's not hard to verify the equations noting that the num of chunk types
152151
is 3 and the num of tag types in IOB scheme is 2. For example, the label
153152
id of I-LOC is 5, the tag type id of I-LOC is 1, and the chunk type id of
154153
I-LOC is 2, which consistent with the results from the equations.

paddle/fluid/operators/conv_transpose_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Parameters(strides, paddings) are two elements. These two elements represent hei
156156
and width, respectively.
157157
The input(X) size and output(Out) size may be different.
158158
159-
Example:
159+
For an example:
160160
Input:
161161
Input shape: $(N, C_{in}, H_{in}, W_{in})$
162162
Filter shape: $(C_{in}, C_{out}, H_f, W_f)$

paddle/fluid/operators/cos_sim_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ class CosSimOpMaker : public framework::OpProtoAndCheckerMaker {
7676
.AsIntermediate();
7777

7878
AddComment(R"DOC(
79-
Cosine Similarity Operator.
79+
**Cosine Similarity Operator**
8080
81-
$Out = X^T * Y / (\sqrt{X^T * X} * \sqrt{Y^T * Y})$
81+
$Out = \frac{X^T * Y}{(\sqrt{X^T * X} * \sqrt{Y^T * Y})}$
8282
8383
The input X and Y must have the same shape, except that the 1st dimension
8484
of input Y could be just 1 (different from input X), which will be

paddle/fluid/operators/crf_decoding_op.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,18 @@ sequence of observed tags.
5353
The output of this operator changes according to whether Input(Label) is given:
5454
5555
1. Input(Label) is given:
56-
57-
This happens in training. This operator is used to co-work with the chunk_eval
58-
operator.
59-
60-
When Input(Label) is given, the crf_decoding operator returns a row vector
61-
with shape [N x 1] whose values are fixed to be 0, indicating an incorrect
62-
prediction, or 1 indicating a tag is correctly predicted. Such an output is the
63-
input to chunk_eval operator.
56+
This happens in training. This operator is used to co-work with the chunk_eval
57+
operator.
58+
When Input(Label) is given, the crf_decoding operator returns a row vector
59+
with shape [N x 1] whose values are fixed to be 0, indicating an incorrect
60+
prediction, or 1 indicating a tag is correctly predicted. Such an output is the
61+
input to chunk_eval operator.
6462
6563
2. Input(Label) is not given:
66-
67-
This is the standard decoding process.
64+
This is the standard decoding process.
6865
6966
The crf_decoding operator returns a row vector with shape [N x 1] whose values
70-
range from 0 to maximum tag number - 1. Each element indicates an index of a
67+
range from 0 to maximum tag number - 1, Each element indicates an index of a
7168
predicted tag.
7269
)DOC");
7370
}

paddle/fluid/operators/detection/iou_similarity_op.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ class IOUSimilarityOpMaker : public framework::OpProtoAndCheckerMaker {
6868
"representing pairwise iou scores.");
6969

7070
AddComment(R"DOC(
71-
IOU Similarity Operator.
71+
**IOU Similarity Operator**
72+
7273
Computes intersection-over-union (IOU) between two box lists.
73-
Box list 'X' should be a LoDTensor and 'Y' is a common Tensor,
74-
boxes in 'Y' are shared by all instance of the batched inputs of X.
75-
Given two boxes A and B, the calculation of IOU is as follows:
74+
Box list 'X' should be a LoDTensor and 'Y' is a common Tensor,
75+
boxes in 'Y' are shared by all instance of the batched inputs of X.
76+
Given two boxes A and B, the calculation of IOU is as follows:
7677
7778
$$
7879
IOU(A, B) =
79-
\frac{area(A\cap B)}{area(A)+area(B)-area(A\cap B)}
80+
\\frac{area(A\\cap B)}{area(A)+area(B)-area(A\\cap B)}
8081
$$
8182
8283
)DOC");

paddle/fluid/operators/linear_chain_crf_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ CRF. Please refer to http://www.cs.columbia.edu/~mcollins/fb.pdf and
8484
http://cseweb.ucsd.edu/~elkan/250Bwinter2012/loglinearCRFs.pdf for details.
8585
8686
Equation:
87+
8788
1. Denote Input(Emission) to this operator as $x$ here.
8889
2. The first D values of Input(Transition) to this operator are for starting
8990
weights, denoted as $a$ here.
@@ -106,6 +107,7 @@ Finally, the linear chain CRF operator outputs the logarithm of the conditional
106107
likelihood of each training sample in a mini-batch.
107108
108109
NOTE:
110+
109111
1. The feature function for a CRF is made up of the emission features and the
110112
transition features. The emission feature weights are NOT computed in
111113
this operator. They MUST be computed first before this operator is called.

paddle/fluid/operators/lstm_op.cc

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,32 @@ Long-Short Term Memory (LSTM) Operator.
184184
The defalut implementation is diagonal/peephole connection
185185
(https://arxiv.org/pdf/1402.1128.pdf), the formula is as follows:
186186
187-
$$
188-
i_t = \sigma(W_{ix}x_{t} + W_{ih}h_{t-1} + W_{ic}c_{t-1} + b_i) \\
187+
$$ i_t = \\sigma(W_{ix}x_{t} + W_{ih}h_{t-1} + W_{ic}c_{t-1} + b_i) $$
189188
190-
f_t = \sigma(W_{fx}x_{t} + W_{fh}h_{t-1} + W_{fc}c_{t-1} + b_f) \\
189+
$$ f_t = \\sigma(W_{fx}x_{t} + W_{fh}h_{t-1} + W_{fc}c_{t-1} + b_f) $$
191190
192-
\tilde{c_t} = act_g(W_{cx}x_t + W_{ch}h_{t-1} + b_c) \\
191+
$$ \\tilde{c_t} = act_g(W_{cx}x_t + W_{ch}h_{t-1} + b_c) $$
193192
194-
o_t = \sigma(W_{ox}x_{t} + W_{oh}h_{t-1} + W_{oc}c_t + b_o) \\
193+
$$ o_t = \\sigma(W_{ox}x_{t} + W_{oh}h_{t-1} + W_{oc}c_t + b_o) $$
195194
196-
c_t = f_t \odot c_{t-1} + i_t \odot \tilde{c_t} \\
195+
$$ c_t = f_t \\odot c_{t-1} + i_t \\odot \\tilde{c_t} $$
197196
198-
h_t = o_t \odot act_h(c_t)
199-
$$
197+
$$ h_t = o_t \\odot act_h(c_t) $$
200198
201-
where the W terms denote weight matrices (e.g. $W_{xi}$ is the matrix
202-
of weights from the input gate to the input), $W_{ic}, W_{fc}, W_{oc}$
203-
are diagonal weight matrices for peephole connections. In our implementation,
204-
we use vectors to reprenset these diagonal weight matrices. The b terms
205-
denote bias vectors ($b_i$ is the input gate bias vector), $\sigma$
206-
is the non-line activations, such as logistic sigmoid function, and
207-
$i, f, o$ and $c$ are the input gate, forget gate, output gate,
208-
and cell activation vectors, respectively, all of which have the same size as
209-
the cell output activation vector $h$.
210-
211-
The $\odot$ is the element-wise product of the vectors. $act_g$ and $act_h$
212-
are the cell input and cell output activation functions and `tanh` is usually
213-
used for them. $\tilde{c_t}$ is also called candidate hidden state,
214-
which is computed based on the current input and the previous hidden state.
199+
- W terms denote weight matrices (e.g. $W_{xi}$ is the matrix
200+
of weights from the input gate to the input), $W_{ic}, W_{fc}, W_{oc}$
201+
are diagonal weight matrices for peephole connections. In our implementation,
202+
we use vectors to reprenset these diagonal weight matrices.
203+
- The b terms denote bias vectors ($b_i$ is the input gate bias vector).
204+
- $\sigma$ is the non-line activations, such as logistic sigmoid function.
205+
- $i, f, o$ and $c$ are the input gate, forget gate, output gate,
206+
and cell activation vectors, respectively, all of which have the same size as
207+
the cell output activation vector $h$.
208+
- The $\odot$ is the element-wise product of the vectors.
209+
- $act_g$ and $act_h$ are the cell input and cell output activation functions
210+
and `tanh` is usually used for them.
211+
- $\tilde{c_t}$ is also called candidate hidden state,
212+
which is computed based on the current input and the previous hidden state.
215213
216214
Set `use_peepholes` False to disable peephole connection. The formula
217215
is omitted here, please refer to the paper

paddle/fluid/operators/roi_pool_op.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,20 @@ class ROIPoolOpMaker : public framework::OpProtoAndCheckerMaker {
139139
"The pooled output width.")
140140
.SetDefault(1);
141141
AddComment(R"DOC(
142-
ROIPool operator
142+
**ROIPool Operator**
143+
144+
Region of interest pooling (also known as RoI pooling) is to perform
145+
is to perform max pooling on inputs of nonuniform sizes to obtain
146+
fixed-size feature maps (e.g. 7*7).
147+
148+
The operator has three steps:
149+
150+
1. Dividing each region proposal into equal-sized sections with
151+
the pooled_width and pooled_height
152+
153+
2. Finding the largest value in each section
154+
155+
3. Copying these max values to the output buffer
143156
144157
ROI Pooling for Faster-RCNN. The link below is a further introduction:
145158
https://stackoverflow.com/questions/43430056/what-is-roi-layer-in-fast-rcnn

paddle/fluid/operators/scale_op.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class ScaleOpMaker : public framework::OpProtoAndCheckerMaker {
4141
AddInput("X", "(Tensor) Input tensor of scale operator.");
4242
AddOutput("Out", "(Tensor) Output tensor of scale operator.");
4343
AddComment(R"DOC(
44-
Scale operator
44+
**Scale operator**
45+
46+
Multiply the input tensor with a float scalar to scale the input tensor.
4547
4648
$$Out = scale*X$$
4749
)DOC");
48-
AddAttr<float>("scale",
49-
"(float, default 1.0)"
50-
"The scaling factor of the scale operator.")
50+
AddAttr<float>("scale", "The scaling factor of the scale operator.")
5151
.SetDefault(1.0);
5252
}
5353
};

python/paddle/fluid/layers/io.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,35 @@ def __exit__(self, exc_type, exc_val, exc_tb):
109109

110110
class ListenAndServ(object):
111111
"""
112-
ListenAndServ class.
112+
**ListenAndServ Layer**
113+
114+
ListenAndServ is used to create a rpc server bind and listen
115+
on specific TCP port, this server will run the sub-block when
116+
received variables from clients.
117+
118+
Args:
119+
endpoint(string): IP:port string which the server will listen on.
120+
inputs(list): a list of variables that the server will get from clients.
121+
fan_in(int): how many client are expected to report to this server, default: 1.
122+
optimizer_mode(bool): whether to run the server as a parameter server, default: True.
123+
124+
Examples:
125+
.. code-block:: python
113126
114-
ListenAndServ class is used to wrap listen_and_serv op to create a server
115-
which can receive variables from clients and run a block.
127+
with fluid.program_guard(main):
128+
serv = layers.ListenAndServ(
129+
"127.0.0.1:6170", ["X"], optimizer_mode=False)
130+
with serv.do():
131+
x = layers.data(
132+
shape=[32, 32],
133+
dtype='float32',
134+
name="X",
135+
append_batch_size=False)
136+
fluid.initializer.Constant(value=1.0)(x, main.global_block())
137+
layers.scale(x=x, scale=10.0, out=out_var)
138+
139+
exe = fluid.Executor(place)
140+
exe.run(main)
116141
"""
117142

118143
def __init__(self, endpoint, inputs, fan_in=1, optimizer_mode=True):

0 commit comments

Comments
 (0)