Struct burn_core::nn::transformer::TransformerEncoderConfig
source · pub struct TransformerEncoderConfig {
pub d_model: usize,
pub d_ff: usize,
pub n_heads: usize,
pub n_layers: usize,
pub dropout: f64,
pub norm_first: bool,
pub quiet_softmax: bool,
pub initializer: Initializer,
}Expand description
Configuration to create a Transformer Encoder layer.
Fields§
§d_model: usizeThe size of the model.
d_ff: usizeThe size of the position-wise feed-forward network.
n_heads: usizeThe number of attention heads.
n_layers: usizeThe number of layers.
dropout: f64The dropout rate. Default: 0.1
norm_first: boolLayer norm will be applied first instead of after the other modules.
quiet_softmax: boolUse “quiet softmax” instead of regular softmax.
- Usage may improve performance by allowing attention heads to deposit no information (if the sequence contains no information relevant to that head).
- Usage may reduce the entropy of weights in the model, enhancing quantization and compression.
Reference: https://www.evanmiller.org/attention-is-off-by-one.html
initializer: InitializerThe type of function used to initialize neural network parameters
Implementations§
source§impl TransformerEncoderConfig
impl TransformerEncoderConfig
sourcepub fn with_dropout(self, dropout: f64) -> Self
pub fn with_dropout(self, dropout: f64) -> Self
The dropout rate. Default: 0.1
sourcepub fn with_norm_first(self, norm_first: bool) -> Self
pub fn with_norm_first(self, norm_first: bool) -> Self
Layer norm will be applied first instead of after the other modules.
sourcepub fn with_quiet_softmax(self, quiet_softmax: bool) -> Self
pub fn with_quiet_softmax(self, quiet_softmax: bool) -> Self
Use “quiet softmax” instead of regular softmax.
sourcepub fn with_initializer(self, initializer: Initializer) -> Self
pub fn with_initializer(self, initializer: Initializer) -> Self
The type of function used to initialize neural network parameters
source§impl TransformerEncoderConfig
impl TransformerEncoderConfig
sourcepub fn init<B: Backend>(&self) -> TransformerEncoder<B>
pub fn init<B: Backend>(&self) -> TransformerEncoder<B>
Initialize a new transformer encoder module.
sourcepub fn init_with<B: Backend>(
&self,
record: TransformerEncoderRecord<B>
) -> TransformerEncoder<B>
pub fn init_with<B: Backend>( &self, record: TransformerEncoderRecord<B> ) -> TransformerEncoder<B>
Initialize a new transformer encoder module with a record.