Skip to content

Commit 297a169

Browse files
committed
Fix doc of warpctc, array_read, edit_distance and sequence_reshape.
1 parent e0a8c58 commit 297a169

File tree

2 files changed

+522
-283
lines changed

2 files changed

+522
-283
lines changed

python/paddle/fluid/layers/control_flow.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
import contextlib
1515

16-
from layer_function_generator import autodoc
16+
from layer_function_generator import autodoc, templatedoc
1717
from tensor import assign, fill_constant
1818
from .. import core
1919
from ..framework import Program, Variable, Operator
@@ -721,26 +721,22 @@ def lod_rank_table(x, level=0):
721721
return table
722722

723723

724+
@templatedoc()
724725
def max_sequence_len(rank_table):
725-
"""Max Sequence Len Operator. Given a LoDRankTable object, this layer
726-
returns the max length of a batch of sequences. In fact, a LoDRankTable
727-
object contains a list of tuples(<sequence index, sequence length>) and
728-
the list is already sorted by sequence length in descending order, so the
729-
operator just returns the sequence length of the first tuple element.
726+
"""
727+
${comment}
728+
729+
>>> import paddle.fluid as fluid
730+
>>> x = fluid.layers.data(name='x', shape=[10], dtype='float32',
731+
>>> lod_level=1)
732+
>>> rank_table = layers.lod_rank_table(x=x, level=0)
733+
>>> max_seq_len = layers.max_sequence_len(rank_table)
730734
731735
Args:
732-
rank_table (Variable): Input variable which is a LoDRankTable object.
736+
rank_table(${rank_table_type}): ${rank_table_comment}.
733737
734738
Returns:
735-
Variable: The max length of sequence.
736-
737-
Examples:
738-
.. code-block:: python
739-
740-
x = fluid.layers.data(name='x', shape=[10],
741-
dtype='float32', lod_level=1)
742-
rank_table = layers.lod_rank_table(x=x, level=0)
743-
max_seq_len = layers.max_sequence_len(rank_table)
739+
${out_comment}.
744740
"""
745741
helper = LayerHelper("max_seqence_len", **locals())
746742
res = helper.create_tmp_variable(dtype="int64")
@@ -978,19 +974,38 @@ def equal(x, y, cond=None, **ignored):
978974

979975

980976
def array_read(array, i):
981-
"""This function performs the operation to read the data in as an
977+
"""
978+
This function performs the operation to read the data in as an
982979
LOD_TENSOR_ARRAY.
980+
981+
.. code-block:: text
982+
983+
Given:
984+
985+
array = [0.6, 0.1, 0.3, 0.1]
986+
987+
And:
988+
989+
i = 2
990+
991+
Then:
992+
993+
output = 0.3
994+
983995
Args:
984-
array (Variable|list): The input tensor that will be written to an array.
985-
i (Variable|list): The subscript index in tensor array, that points the
986-
place where data will be written to.
996+
array (Variable|list): The input tensor that store data to be read.
997+
i (Variable|list): The index of the data to be read from input array.
998+
987999
Returns:
9881000
Variable: The tensor type variable that has the data written to it.
1001+
9891002
Examples:
990-
.. code-block::python
991-
tmp = fluid.layers.zeros(shape=[10], dtype='int32')
992-
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10)
993-
arr = layers.array_read(tmp, i=i)
1003+
.. code-block:: python
1004+
1005+
tmp = fluid.layers.zeros(shape=[10], dtype='int32')
1006+
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10)
1007+
arr = layers.array_read(tmp, i=i)
1008+
9941009
"""
9951010
helper = LayerHelper('array_read', **locals())
9961011
if not isinstance(

0 commit comments

Comments
 (0)