|
13 | 13 | # limitations under the License.
|
14 | 14 | import contextlib
|
15 | 15 |
|
16 |
| -from layer_function_generator import autodoc |
| 16 | +from layer_function_generator import autodoc, templatedoc |
17 | 17 | from tensor import assign, fill_constant
|
18 | 18 | from .. import core
|
19 | 19 | from ..framework import Program, Variable, Operator
|
@@ -721,26 +721,22 @@ def lod_rank_table(x, level=0):
|
721 | 721 | return table
|
722 | 722 |
|
723 | 723 |
|
| 724 | +@templatedoc() |
724 | 725 | 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) |
730 | 734 |
|
731 | 735 | Args:
|
732 |
| - rank_table (Variable): Input variable which is a LoDRankTable object. |
| 736 | + rank_table(${rank_table_type}): ${rank_table_comment}. |
733 | 737 |
|
734 | 738 | 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}. |
744 | 740 | """
|
745 | 741 | helper = LayerHelper("max_seqence_len", **locals())
|
746 | 742 | res = helper.create_tmp_variable(dtype="int64")
|
@@ -978,19 +974,38 @@ def equal(x, y, cond=None, **ignored):
|
978 | 974 |
|
979 | 975 |
|
980 | 976 | 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 |
982 | 979 | 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 | +
|
983 | 995 | 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 | +
|
987 | 999 | Returns:
|
988 | 1000 | Variable: The tensor type variable that has the data written to it.
|
| 1001 | +
|
989 | 1002 | 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 | +
|
994 | 1009 | """
|
995 | 1010 | helper = LayerHelper('array_read', **locals())
|
996 | 1011 | if not isinstance(
|
|
0 commit comments