pub struct RnnConfig {
pub d_input: usize,
pub d_hidden: usize,
pub bias: bool,
pub initializer: Initializer,
pub batch_first: bool,
pub reverse: bool,
pub clip: Option<f64>,
pub hidden_activation: ActivationConfig,
}Expand description
Configuration to create a Rnn module using the init function.
Fields§
§d_input: usizeThe size of the input features.
The size of the hidden state.
bias: boolIf a bias should be applied during the Rnn transformation.
initializer: InitializerRnn initializer
batch_first: boolIf true, the input tensor is expected to be [batch_size, seq_length, input_size].
If false, the input tensor is expected to be [seq_length, batch_size, input_size].
reverse: boolIf true, process the sequence in reverse order. This is useful for implementing reverse-direction RNNs (e.g., ONNX reverse direction).
clip: Option<f64>Optional hidden state clip threshold. If provided, hidden state values are clipped
to the range [-clip, +clip] after each timestep. This can help prevent
exploding values during inference.
Activation function applied to the hidden state before computing hidden output. Default is Tanh, which is standard for Rnn.
Implementations§
Source§impl RnnConfig
impl RnnConfig
Sourcepub fn new(d_input: usize, d_hidden: usize, bias: bool) -> RnnConfig
pub fn new(d_input: usize, d_hidden: usize, bias: bool) -> RnnConfig
Create a new instance of the config.
§Arguments
§Required Arguments
§d_input
The size of the input features.
§d_hidden
The size of the hidden state.
§bias
If a bias should be applied during the Rnn transformation.
§Optional Arguments
§clip
Optional hidden state clip threshold. If provided, hidden state values are clipped
to the range [-clip, +clip] after each timestep. This can help prevent
exploding values during inference.
- Defaults to
None
§Default Arguments
§initializer
Rnn initializer
- Defaults to
"Initializer::XavierNormal{gain:1.0}"
§batch_first
If true, the input tensor is expected to be [batch_size, seq_length, input_size].
If false, the input tensor is expected to be [seq_length, batch_size, input_size].
- Defaults to
true
§reverse
If true, process the sequence in reverse order. This is useful for implementing reverse-direction RNNs (e.g., ONNX reverse direction).
- Defaults to
false
§hidden_activation
Activation function applied to the hidden state before computing hidden output. Default is Tanh, which is standard for Rnn.
- Defaults to
"ActivationConfig::Tanh"
Source§impl RnnConfig
impl RnnConfig
Sourcepub fn with_initializer(self, initializer: Initializer) -> RnnConfig
pub fn with_initializer(self, initializer: Initializer) -> RnnConfig
Sets the value for the field initializer.
Rnn initializer
- Defaults to
"Initializer::XavierNormal{gain:1.0}"
Sourcepub fn with_batch_first(self, batch_first: bool) -> RnnConfig
pub fn with_batch_first(self, batch_first: bool) -> RnnConfig
Sets the value for the field batch_first.
If true, the input tensor is expected to be [batch_size, seq_length, input_size].
If false, the input tensor is expected to be [seq_length, batch_size, input_size].
- Defaults to
true
Sourcepub fn with_reverse(self, reverse: bool) -> RnnConfig
pub fn with_reverse(self, reverse: bool) -> RnnConfig
Sets the value for the field reverse.
If true, process the sequence in reverse order. This is useful for implementing reverse-direction RNNs (e.g., ONNX reverse direction).
- Defaults to
false
Sets the value for the field hidden_activation.
Activation function applied to the hidden state before computing hidden output. Default is Tanh, which is standard for Rnn.
- Defaults to
"ActivationConfig::Tanh"
Sourcepub fn with_clip(self, clip: Option<f64>) -> RnnConfig
pub fn with_clip(self, clip: Option<f64>) -> RnnConfig
Sets the value for the field clip.
Optional hidden state clip threshold. If provided, hidden state values are clipped
to the range [-clip, +clip] after each timestep. This can help prevent
exploding values during inference.
- Defaults to
None