Skip to content

Commit 3380737

Browse files
author
yi.wu
committed
update by comment
1 parent a83b792 commit 3380737

File tree

7 files changed

+133
-47
lines changed

7 files changed

+133
-47
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/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/detection/iou_similarity_op.cc

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

7070
AddComment(R"DOC(
71-
IOU Similarity Operator.
71+
**IOU Similarity Operator**
7272
7373
Computes intersection-over-union (IOU) between two box lists.
7474
Box list 'X' should be a LoDTensor and 'Y' is a common Tensor,
@@ -77,7 +77,7 @@ Given two boxes A and B, the calculation of IOU is as follows:
7777
7878
$$
7979
IOU(A, B) =
80-
\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)}
8181
$$
8282
8383
)DOC");

paddle/fluid/operators/roi_pool_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class ROIPoolOpMaker : public framework::OpProtoAndCheckerMaker {
139139
"The pooled output width.")
140140
.SetDefault(1);
141141
AddComment(R"DOC(
142-
ROIPool operator
142+
**ROIPool Operator**
143143
144144
Region of interest pooling (also known as RoI pooling) is to perform
145145
is to perform max pooling on inputs of nonuniform sizes to obtain

paddle/fluid/operators/scale_op.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +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+
4546
Multiply the input tensor with a float scalar to scale the input tensor.
4647
4748
$$Out = scale*X$$
4849
)DOC");
49-
AddAttr<float>("scale",
50-
"(float, default 1.0)"
51-
"The scaling factor of the scale operator.")
50+
AddAttr<float>("scale", "The scaling factor of the scale operator.")
5251
.SetDefault(1.0);
5352
}
5453
};

python/paddle/fluid/layers/io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
109109

110110
class ListenAndServ(object):
111111
"""
112+
***ListenAndServ Layer***
113+
112114
ListenAndServ is used to create a rpc server bind and listen
113115
on specific TCP port, this server will run the sub-block when
114116
received variables from clients.

python/paddle/fluid/layers/nn.py

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,12 @@ def crf_decoding(input, param_attr, label=None):
825825
826826
Returns:
827827
Variable: ${viterbi_path_comment}
828+
829+
Examples:
830+
.. code-block:: python
831+
832+
crf_decode = layers.crf_decoding(
833+
input=hidden, param_attr=ParamAttr(name="crfw"))
828834
"""
829835
helper = LayerHelper('crf_decoding', **locals())
830836
transition = helper.get_parameter(param_attr.name)
@@ -1043,9 +1049,70 @@ def chunk_eval(input,
10431049
num_chunk_types,
10441050
excluded_chunk_types=None):
10451051
"""
1052+
***Chunk Evaluator***
1053+
10461054
This function computes and outputs the precision, recall and
10471055
F1-score of chunk detection.
10481056
1057+
For some basics of chunking, please refer to
1058+
'Chunking with Support Vector Machines <https://aclanthology.info/pdf/N/N01/N01-1025.pdf>'.
1059+
1060+
ChunkEvalOp computes the precision, recall, and F1-score of chunk detection,
1061+
and supports IOB, IOE, IOBES and IO (also known as plain) tagging schemes.
1062+
Here is a NER example of labeling for these tagging schemes:
1063+
1064+
.. code-block:: python
1065+
1066+
====== ====== ====== ===== == ============ ===== ===== ===== == =========
1067+
Li Ming works at Agricultural Bank of China in Beijing.
1068+
====== ====== ====== ===== == ============ ===== ===== ===== == =========
1069+
IO I-PER I-PER O O I-ORG I-ORG I-ORG I-ORG O I-LOC
1070+
IOB B-PER I-PER O O B-ORG I-ORG I-ORG I-ORG O B-LOC
1071+
IOE I-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O E-LOC
1072+
IOBES B-PER E-PER O O I-ORG I-ORG I-ORG E-ORG O S-LOC
1073+
====== ====== ====== ===== == ============ ===== ===== ===== == =========
1074+
1075+
There are three chunk types(named entity types) including PER(person), ORG(organization)
1076+
and LOC(LOCATION), and we can see that the labels have the form <tag type>-<chunk type>.
1077+
1078+
Since the calculations actually use label ids rather than labels, extra attention
1079+
should be paid when mapping labels to ids to make CheckEvalOp work. The key point
1080+
is that the listed equations are satisfied by ids.
1081+
1082+
.. code-block:: python
1083+
1084+
tag_type = label % num_tag_type
1085+
chunk_type = label / num_tag_type
1086+
1087+
where `num_tag_type` is the num of tag types in the tagging scheme, `num_chunk_type`
1088+
is the num of chunk types, and `tag_type` get its value from the following table.
1089+
1090+
.. code-block:: python
1091+
1092+
Scheme Begin Inside End Single
1093+
plain 0 - - -
1094+
IOB 0 1 - -
1095+
IOE - 0 1 -
1096+
IOBES 0 1 2 3
1097+
1098+
Still use NER as example, assuming the tagging scheme is IOB while chunk types are ORG,
1099+
PER and LOC. To satisfy the above equations, the label map can be like this:
1100+
1101+
.. code-block:: python
1102+
1103+
B-ORG 0
1104+
I-ORG 1
1105+
B-PER 2
1106+
I-PER 3
1107+
B-LOC 4
1108+
I-LOC 5
1109+
O 6
1110+
1111+
It's not hard to verify the equations noting that the num of chunk types
1112+
is 3 and the num of tag types in IOB scheme is 2. For example, the label
1113+
id of I-LOC is 5, the tag type id of I-LOC is 1, and the chunk type id of
1114+
I-LOC is 2, which consistent with the results from the equations.
1115+
10491116
Args:
10501117
input (Variable): prediction output of the network.
10511118
label (Variable): label of the test data set.
@@ -1057,6 +1124,19 @@ def chunk_eval(input,
10571124
tuple: tuple containing: precision, recall, f1_score,
10581125
num_infer_chunks, num_label_chunks,
10591126
num_correct_chunks
1127+
1128+
Examples:
1129+
.. code-block:: python
1130+
1131+
crf = fluid.layers.linear_chain_crf(
1132+
input=hidden, label=label, param_attr=ParamAttr(name="crfw"))
1133+
crf_decode = fluid.layers.crf_decoding(
1134+
input=hidden, param_attr=ParamAttr(name="crfw"))
1135+
fluid.layers.chunk_eval(
1136+
input=crf_decode,
1137+
label=label,
1138+
chunk_scheme="IOB",
1139+
num_chunk_types=(label_dict_len - 1) / 2)
10601140
"""
10611141
helper = LayerHelper("chunk_eval", **locals())
10621142

@@ -1803,7 +1883,7 @@ def conv2d_transpose(input,
18031883
act=None,
18041884
name=None):
18051885
"""
1806-
**Convlution2D transpose layer**
1886+
***Convlution2D Transpose Layer****
18071887
18081888
The convolution2D transpose layer calculates the output based on the input,
18091889
filter, and dilations, strides, paddings. Input(Input) and output(Output)
@@ -1832,13 +1912,13 @@ def conv2d_transpose(input,
18321912
18331913
- Input:
18341914
1835-
Input shape: $(N, C_{in}, H_{in}, W_{in})$
1915+
Input shape: :math:`(N, C_{in}, H_{in}, W_{in})`
18361916
1837-
Filter shape: $(C_{in}, C_{out}, H_f, W_f)$
1917+
Filter shape: :math:`(C_{in}, C_{out}, H_f, W_f)`
18381918
18391919
- Output:
18401920
1841-
Output shape: $(N, C_{out}, H_{out}, W_{out})$
1921+
Output shape: :math:`(N, C_{out}, H_{out}, W_{out})`
18421922
18431923
Where
18441924
@@ -3513,6 +3593,12 @@ def autoincreased_step_counter(counter_name=None, begin=1, step=1):
35133593
35143594
Returns:
35153595
Variable: The global run counter.
3596+
3597+
Examples:
3598+
.. code-block:: python
3599+
3600+
global_step = fluid.layers.autoincreased_step_counter(
3601+
counter_name='@LR_DECAY_COUNTER@', begin=begin, step=1)
35163602
"""
35173603
helper = LayerHelper('global_step_counter')
35183604
if counter_name is None:

0 commit comments

Comments
 (0)