RNN - 1 vs 22¶
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 → RNN22 +31 -51
RNN1 → RNN22
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
|
-
X - input tensor
|
4
|
+
* X - input tensor
|
5
|
-
|
6
|
-
i - input gate
|
5
|
+
* i - input gate
|
7
|
-
|
8
|
-
t - time step (t-1 means previous time step)
|
6
|
+
* t - time step (t-1 means previous time step)
|
9
|
-
|
10
|
-
Wi - W parameter weight matrix for input gate
|
7
|
+
* Wi - W parameter weight matrix for input gate
|
11
|
-
|
12
|
-
Ri - R recurrence weight matrix for input gate
|
8
|
+
* Ri - R recurrence weight matrix for input gate
|
13
|
-
|
14
|
-
Wbi - W parameter bias vector for input gate
|
9
|
+
* Wbi - W parameter bias vector for input gate
|
15
|
-
|
16
|
-
Rbi - R parameter bias vector for input gate
|
10
|
+
* Rbi - R parameter bias vector for input gate
|
17
|
-
|
18
|
-
WBi - W parameter weight matrix for backward input gate
|
11
|
+
* WBi - W parameter weight matrix for backward input gate
|
19
|
-
|
20
|
-
RBi - R recurrence weight matrix for backward input gate
|
12
|
+
* RBi - R recurrence weight matrix for backward input gate
|
21
|
-
|
22
|
-
WBbi - WR bias vectors for backward input gate
|
13
|
+
* WBbi - WR bias vectors for backward input gate
|
23
|
-
|
24
|
-
RBbi - RR bias vectors for backward input gate
|
14
|
+
* RBbi - RR bias vectors for backward input gate
|
25
|
-
|
26
|
-
H - Hidden state
|
15
|
+
* H - Hidden state
|
27
|
-
|
28
|
-
num_directions - 2 if direction == bidirectional else 1
|
16
|
+
* num_directions - 2 if direction == bidirectional else 1
|
29
17
|
Activation functions:
|
30
|
-
|
18
|
+
* Relu(x) - max(0, x)
|
19
|
+
* Tanh(x) - (1 - e^{-2x})/(1 + e^{-2x})
|
20
|
+
* Sigmoid(x) - 1/(1 + e^{-x})
|
31
|
-
|
21
|
+
NOTE: Below are optional
|
32
|
-
Sigmoid(x) - 1/(1 + e^{-x})
|
33
|
-
|
34
|
-
(NOTE: Below are optional)
|
35
|
-
|
36
|
-
|
22
|
+
* Affine(x) - alpha*x + beta
|
37
|
-
|
38
|
-
|
23
|
+
* LeakyRelu(x) - x if x >= 0 else alpha * x
|
39
|
-
|
40
|
-
|
24
|
+
* ThresholdedRelu(x) - x if x >= alpha else 0
|
41
|
-
|
42
|
-
|
25
|
+
* ScaledTanh(x) - alpha*Tanh(beta*x)
|
43
|
-
|
44
|
-
|
26
|
+
* HardSigmoid(x) - min(max(alpha*x + beta, 0), 1)
|
45
|
-
|
46
|
-
|
27
|
+
* Elu(x) - x if x >= 0 else alpha*(e^x - 1)
|
47
|
-
|
48
|
-
|
28
|
+
* Softsign(x) - x/(1 + |x|)
|
49
|
-
|
50
|
-
|
29
|
+
* Softplus(x) - log(1 + e^x)
|
51
30
|
Equations (Default: f=Tanh):
|
52
|
-
|
31
|
+
* Ht = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)
|
32
|
+
This operator has **optional** inputs/outputs. See [ONNX IR](https://github.com/onnx/onnx/blob/main/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.
|
53
33
|
### Attributes
|
54
34
|
* **activation_alpha - FLOATS** :
|
55
35
|
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.For example with LeakyRelu, the default alpha is 0.01.
|
56
36
|
* **activation_beta - FLOATS** :
|
57
37
|
Optional scaling values used by some activation functions. The values are consumed in the order of activation functions, for example (f, g, h) in LSTM. Default values are the same as of corresponding ONNX operators.
|
58
38
|
* **activations - STRINGS** (default is ['Tanh', 'Tanh']):
|
59
39
|
One (or two if bidirectional) activation function for input gate. The activation function must be one of the activation functions specified above. Optional: Default Tanh if not specified.
|
60
40
|
* **clip - FLOAT** :
|
61
41
|
Cell clip threshold. Clipping bounds the elements of a tensor in the range of [-threshold, +threshold] and is applied to the input of activations. No clip if not specified.
|
62
42
|
* **direction - STRING** (default is 'forward'):
|
63
43
|
Specify if the RNN is forward, reverse, or bidirectional. Must be one of forward (default), reverse, or bidirectional.
|
64
44
|
* **hidden_size - INT** :
|
65
45
|
Number of neurons in the hidden layer
|
66
|
-
* **
|
46
|
+
* **layout - INT** (default is '0'):
|
67
|
-
The
|
47
|
+
The shape format of inputs X, initial_h and outputs Y, Y_h. If 0, the following shapes are expected: X.shape = [seq_length, batch_size, input_size], Y.shape = [seq_length, num_directions, batch_size, hidden_size], initial_h.shape = Y_h.shape = [num_directions, batch_size, hidden_size]. If 1, the following shapes are expected: X.shape = [batch_size, seq_length, input_size], Y.shape = [batch_size, seq_length, num_directions, hidden_size], initial_h.shape = Y_h.shape = [batch_size, num_directions, hidden_size].
|
68
48
|
### Inputs
|
69
49
|
Between 3 and 6 inputs.
|
70
50
|
- **X** (heterogeneous) - **T**:
|
71
51
|
The input sequences packed (and potentially padded) into one 3-D tensor with the shape of [seq_length, batch_size, input_size].
|
72
52
|
- **W** (heterogeneous) - **T**:
|
73
53
|
The weight tensor for input gate. Concatenation of Wi and WBi (if bidirectional). The tensor has shape [num_directions, hidden_size, input_size].
|
74
54
|
- **R** (heterogeneous) - **T**:
|
75
55
|
The recurrence weight tensor. Concatenation of Ri and RBi (if bidirectional). The tensor has shape [num_directions, hidden_size, hidden_size].
|
76
56
|
- **B** (optional, heterogeneous) - **T**:
|
77
57
|
The bias tensor for input gate. Concatenation of [Wbi, Rbi] and [WBbi, RBbi] (if bidirectional). The tensor has shape [num_directions, 2*hidden_size]. Optional: If not specified - assumed to be 0.
|
78
58
|
- **sequence_lens** (optional, heterogeneous) - **T1**:
|
79
59
|
Optional tensor specifying lengths of the sequences in a batch. If not specified - assumed all sequences in the batch to have length seq_length. It has shape [batch_size].
|
80
60
|
- **initial_h** (optional, heterogeneous) - **T**:
|
81
61
|
Optional initial value of the hidden. If not specified - assumed to be 0. It has shape [num_directions, batch_size, hidden_size].
|
82
62
|
### Outputs
|
83
63
|
Between 0 and 2 outputs.
|
84
64
|
- **Y** (optional, heterogeneous) - **T**:
|
85
|
-
A tensor that concats all the intermediate output values of the hidden. It has shape [seq_length, num_directions, batch_size, hidden_size].
|
65
|
+
A tensor that concats all the intermediate output values of the hidden. It has shape [seq_length, num_directions, batch_size, hidden_size].
|
86
66
|
- **Y_h** (optional, heterogeneous) - **T**:
|
87
67
|
The last output value of the hidden. It has shape [num_directions, batch_size, hidden_size].
|
88
68
|
### Type Constraints
|
89
|
-
* **T** in ( tensor(double), tensor(float), tensor(float16) ):
|
69
|
+
* **T** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):
|
90
70
|
Constrain input and output types to float tensors.
|
91
71
|
* **T1** in ( tensor(int32) ):
|
92
72
|
Constrain seq_lens to integer tensor.
|