RNN - 1 vs 14#
Next section compares an older to a newer version of the same operator after both definition are converted into markdown text. Green means an addition to the newer version, red means a deletion. Anything else is unchanged.
- RNN1 → RNN14 +4 -13
RNN1 → RNN14
RENAMED
@@ -1 +1 @@
|
|
1
1
|
Computes an one-layer simple RNN. This operator is usually supported
|
2
2
|
via some custom implementation such as CuDNN.
|
3
3
|
Notations:
|
4
4
|
X - input tensor
|
5
5
|
i - input gate
|
6
6
|
t - time step (t-1 means previous time step)
|
7
7
|
Wi - W parameter weight matrix for input gate
|
8
8
|
Ri - R recurrence weight matrix for input gate
|
9
9
|
Wbi - W parameter bias vector for input gate
|
10
10
|
Rbi - R parameter bias vector for input gate
|
11
11
|
WBi - W parameter weight matrix for backward input gate
|
12
12
|
RBi - R recurrence weight matrix for backward input gate
|
13
13
|
WBbi - WR bias vectors for backward input gate
|
14
14
|
RBbi - RR bias vectors for backward input gate
|
15
15
|
H - Hidden state
|
16
16
|
num_directions - 2 if direction == bidirectional else 1
|
17
17
|
Activation functions:
|
18
18
|
Relu(x) - max(0, x)
|
19
19
|
Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
|
20
20
|
Sigmoid(x) - 1/(1 + e^{-x})
|
21
21
|
(NOTE: Below are optional)
|
22
22
|
Affine(x) - alpha*x + beta
|
23
23
|
LeakyRelu(x) - x if x >= 0 else alpha * x
|
24
24
|
ThresholdedRelu(x) - x if x >= alpha else 0
|
25
25
|
ScaledTanh(x) - alpha*Tanh(beta*x)
|
26
26
|
HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)
|
27
27
|
Elu(x) - x if x >= 0 else alpha*(e^x - 1)
|
28
28
|
Softsign(x) - x/(1 + |x|)
|
29
29
|
Softplus(x) - log(1 + e^x)
|
30
30
|
Equations (Default: f=Tanh):
|
31
|
-
- Ht = f(Xt*(Wi^T) + Ht-1*
|
31
|
+
- Ht = f(Xt*(Wi^T) + Ht-1*Ri + Wbi + Rbi)
|
32
|
-
This operator has **optional** inputs/outputs. See ONNX <https://github.com/onnx/onnx/blob/master/docs/IR.md>_ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
|
33
32
|
**Attributes**
|
34
33
|
* **activation_alpha**:
|
35
34
|
Optional scaling values used by some activation functions. The
|
36
35
|
values are consumed in the order of activation functions, for
|
37
36
|
example (f, g, h) in LSTM. Default values are the same as of
|
38
37
|
corresponding ONNX operators.For example with LeakyRelu, the default
|
39
38
|
alpha is 0.01.
|
40
39
|
* **activation_beta**:
|
41
40
|
Optional scaling values used by some activation functions. The
|
42
41
|
values are consumed in the order of activation functions, for
|
43
42
|
example (f, g, h) in LSTM. Default values are the same as of
|
44
43
|
corresponding ONNX operators.
|
45
44
|
* **activations**:
|
46
45
|
One (or two if bidirectional) activation function for input gate.
|
47
46
|
The activation function must be one of the activation functions
|
48
47
|
specified above. Optional: Default Tanh if not specified.
|
49
48
|
* **clip**:
|
50
49
|
Cell clip threshold. Clipping bounds the elements of a tensor in the
|
51
50
|
range of [-threshold, +threshold] and is applied to the input of
|
52
51
|
activations. No clip if not specified.
|
53
52
|
* **direction**:
|
54
53
|
Specify if the RNN is forward, reverse, or bidirectional. Must be
|
55
54
|
one of forward (default), reverse, or bidirectional.
|
56
55
|
* **hidden_size**:
|
57
56
|
Number of neurons in the hidden layer
|
57
|
+
* **output_sequence**:
|
58
|
+
The sequence output for the hidden is optional if 0. Default 0.
|
58
|
-
* **layout**:
|
59
|
-
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0,
|
60
|
-
the following shapes are expected: X.shape = [seq_length,
|
61
|
-
batch_size, input_size], Y.shape = [seq_length, num_directions,
|
62
|
-
batch_size, hidden_size], initial_h.shape = Y_h.shape =
|
63
|
-
[num_directions, batch_size, hidden_size]. If 1, the following
|
64
|
-
shapes are expected: X.shape = [batch_size, seq_length, input_size],
|
65
|
-
Y.shape = [batch_size, seq_length, num_directions, hidden_size],
|
66
|
-
initial_h.shape = Y_h.shape = [batch_size, num_directions,
|
67
|
-
hidden_size].
|
68
59
|
**Inputs**
|
69
60
|
Between 3 and 6 inputs.
|
70
61
|
* **X** (heterogeneous) - **T**:
|
71
62
|
The input sequences packed (and potentially padded) into one 3-D
|
72
63
|
tensor with the shape of [seq_length, batch_size, input_size].
|
73
64
|
* **W** (heterogeneous) - **T**:
|
74
65
|
The weight tensor for input gate. Concatenation of Wi and WBi
|
75
66
|
(if bidirectional). The tensor has shape [num_directions,
|
76
67
|
hidden_size, input_size].
|
77
68
|
* **R** (heterogeneous) - **T**:
|
78
69
|
The recurrence weight tensor. Concatenation of Ri and RBi (if
|
79
70
|
bidirectional). The tensor has shape [num_directions, hidden_size,
|
80
71
|
hidden_size].
|
81
72
|
* **B** (optional, heterogeneous) - **T**:
|
82
73
|
The bias tensor for input gate. Concatenation of [Wbi, Rbi] and
|
83
74
|
[WBbi, RBbi] (if bidirectional). The tensor has shape
|
84
75
|
[num_directions, 2*hidden_size]. Optional: If not specified -
|
85
76
|
assumed to be 0.
|
86
77
|
* **sequence_lens** (optional, heterogeneous) - **T1**:
|
87
78
|
Optional tensor specifying lengths of the sequences in a batch. If
|
88
79
|
not specified - assumed all sequences in the batch to have length
|
89
80
|
seq_length. It has shape [batch_size].
|
90
81
|
* **initial_h** (optional, heterogeneous) - **T**:
|
91
82
|
Optional initial value of the hidden. If not specified - assumed to
|
92
83
|
be 0. It has shape [num_directions, batch_size, hidden_size].
|
93
84
|
**Outputs**
|
94
85
|
Between 0 and 2 outputs.
|
95
86
|
* **Y** (optional, heterogeneous) - **T**:
|
96
87
|
A tensor that concats all the intermediate output values of the
|
97
88
|
hidden. It has shape [seq_length, num_directions, batch_size,
|
98
|
-
hidden_size].
|
89
|
+
hidden_size]. It is optional if output_sequence is 0.
|
99
90
|
* **Y_h** (optional, heterogeneous) - **T**:
|
100
91
|
The last output value of the hidden. It has shape [num_directions,
|
101
92
|
batch_size, hidden_size].
|
102
93
|
**Type Constraints**
|
103
94
|
* **T** in (
|
104
95
|
tensor(double),
|
105
96
|
tensor(float),
|
106
97
|
tensor(float16)
|
107
98
|
):
|
108
99
|
Constrain input and output types to float tensors.
|
109
100
|
* **T1** in (
|
110
101
|
tensor(int32)
|
111
102
|
):
|
112
103
|
Constrain seq_lens to integer tensor.
|