Skip to content

Commit dfd8def

Browse files
author
skylarch
authored
Update hierarchical_layer_en.rst
fix #9014 and #10304
1 parent 03073df commit dfd8def

File tree

1 file changed

+89
-4
lines changed

1 file changed

+89
-4
lines changed
Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,89 @@
1-
Layers supporting hierarchical sequence as input
2-
================================================
3-
4-
TBD
1+
###########################
2+
Layers that Support Hierarchical Sequences as Input
3+
###########################
4+
 
5+
.. contents::
6+
 
7+
Overview
8+
====
9+
 
10+
A sequence is a common data type in natural language processing tasks. An independent word can be regarded as a non-sequential input or a 0-level sequence. A sentence made up of words is a single-level sequence; a number of sentences make up a paragraph, which is a double-level sequence.
11+
 
12+
A double-level sequence is a nested sequence where each element is a single-level sequence. This is a very flexible way of organizing data that helps us construct some complex input information.
13+
 
14+
We can define non-sequences, single-level sequences, and double-level sequences at the following levels.
15+
 
16+
+ 0-level sequence: an independent element. Its type can be any input data type supported by PaddlePaddle;
17+
+ Single-level sequence: multiple elements arranged in a row; each element is a 0-level sequence. The order of elements is an important input information;
18+
+ Double-level sequence: multiple elements arranged in a row; each element is a single-layer sequence called a subseq of a double-level sequence, and each element of the subseq is a 0-level sequence.
19+
 
20+
In PaddlePaddle, the following layers accept double-layer sequences as input and perform corresponding calculations.
21+
 
22+
`pooling`
23+
========
24+
 
25+
The use of pooling is as follows:
26+
 
27+
.. code-block:: bash
28+
 
29+
        Seq_pool = pooling(input=layer,
30+
                           Pooling_type=pooling.Max(),
31+
                           Agg_level=AggregateLevel.TO_SEQUENCE)
32+
        
33+
- `pooling_type` currently supports two types: pooling.Max() and pooling.Avg().
34+
 
35+
- When ʻagg_level=AggregateLevel.TO_NO_SEQUENCE` (default):
36+
 
37+
  - Effect: a double-level sequence input will be converted into a 0-level sequence, and a single-level sequence will be converted into a 0-level sequence 
38+
  - Input: a double-level sequence or a single-level sequence
39+
  - Output: a 0-level sequence which is the average (or maximum) of the entire input sequence (single or double)
40+
 
41+
- When ʻagg_level=AggregateLevel.TO_SEQUENCE`:
42+
 
43+
  - Effect: a double-level sequence will be transformed into a single-level sequence
44+
  - Input: a double-level sequence
45+
  - Output: a single-level sequence where each element of the sequence is the average (or maximum) value of each subseq element of the original double-level sequence.
46+
 
47+
`last_seq` and `first_seq`
48+
=====================
49+
 
50+
An example of using `last_seq` is as follows (usage of `first_seq` is similar).
51+
 
52+
.. code-block:: bash
53+
 
54+
        Last = last_seq(input=layer,
55+
                        Agg_level=AggregateLevel.TO_SEQUENCE)
56+
        
57+
- When ʻagg_level=AggregateLevel.TO_NO_SEQUENCE` (default):
58+
 
59+
  - Effect: a double-level sequence input will be converted into a 0-level sequence, and a single-level sequence will be converted into a 0-level sequence
60+
  - Input: a double-level sequence or a single-level sequence
61+
  - Output: a 0-level sequence, which is the last or the first element of the input sequence (double or single level).
62+
 
63+
- When ʻagg_level=AggregateLevel.TO_SEQUENCE`:
64+
  - Effect: a double-level sequence will be transformed into a single-level sequence
65+
  - Input: a double-level sequence
66+
  - Output: a single-layer sequence in which each element is the last (or first) element of each subseq in a double-level sequence.
67+
 
68+
`expand`
69+
======
70+
 
71+
The use of expand is as follows.
72+
 
73+
.. code-block:: bash
74+
 
75+
        Ex = expand(input=layer1,
76+
                    Expand_as=layer2,
77+
                    Expand_level=ExpandLevel.FROM_NO_SEQUENCE)
78+
        
79+
- When `expand_level=ExpandLevel.FROM_NO_SEQUENCE` (default):
80+
 
81+
  - Effect: a 0-level sequence is extended to a single-level sequence or a double-level sequence
82+
  - Input: layer1 must be a 0-level sequence to be extended; layer2 can be a single-level sequence or a double-level sequence that provides the extended length information
83+
  - Output: a single-level sequence or a double-level sequence; the type of the output sequence and the number of elements contained in the sequence are the same as layer2. If the output is a single-level sequence, each element of the single-level sequence will be a copy of the layer1 element. If the output is a double-level sequence, each element in the double-level sequence will be a copy of the layer1 element
84+
 
85+
- When `expand_level=ExpandLevel.FROM_SEQUENCE`:
86+
 
87+
  - Effect: a single-level sequence is extended to a double-level sequence
88+
  - Input: layer1 must be a single-level sequence to be extended; layer2 must be a double-level sequence providing extended length information
89+
  - Output: a double-level sequence with the same number of elements as that of layer2. It is required that the number of elements in the single-level sequence be the same as the number of subseq in the double-level sequences. The i-th element of the single-level sequence (the 0-level sequence) is expanded into a single-level sequence that constitutes the i-th subseq of the output, the double-level sequence.

0 commit comments

Comments
 (0)