pub struct TransformerBuilder {
pub dimensions: i32,
pub num_heads: i32,
pub encoder_layer_count: usize,
pub decoder_layer_count: usize,
pub mlp_dimensions: Option<i32>,
pub dropout: f32,
pub activation: Option<Box<dyn Activation>>,
pub norm_first: bool,
}
Expand description
Builder for the Transformer
module
Fields§
§dimensions: i32
number of expected features in the encoder/decoder
num_heads: i32
number of attention heads
encoder_layer_count: usize
number of layers in the encoder
decoder_layer_count: usize
number of layers in the decoder
mlp_dimensions: Option<i32>
hidden dimensions of the MLP block in each layer. Defaults to 4 * dimensions
if not specified
dropout: f32
dropout value for the encode and decoder. Dropout is used after each attention layer and the activation in the MLP layer
activation: Option<Box<dyn Activation>>
the activation layer for the MLP hidden layer
norm_first: bool
if true
encode and decoder layers will perform layer normalization before
attention and MLP operations, otherwise after
Implementations§
Source§impl TransformerBuilder
impl TransformerBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new TransformerBuilder
.
Source§impl TransformerBuilder
impl TransformerBuilder
Sourcepub fn dimensions(self, dimensions: impl Into<i32>) -> Self
pub fn dimensions(self, dimensions: impl Into<i32>) -> Self
Sets the value of [dimensions
].
Sourcepub fn encoder_layer_count(self, encoder_layer_count: impl Into<usize>) -> Self
pub fn encoder_layer_count(self, encoder_layer_count: impl Into<usize>) -> Self
Sets the value of [encoder_layer_count
].
Sourcepub fn decoder_layer_count(self, decoder_layer_count: impl Into<usize>) -> Self
pub fn decoder_layer_count(self, decoder_layer_count: impl Into<usize>) -> Self
Sets the value of [decoder_layer_count
].
Sourcepub fn mlp_dimensions(self, mlp_dimensions: impl Into<Option<i32>>) -> Self
pub fn mlp_dimensions(self, mlp_dimensions: impl Into<Option<i32>>) -> Self
Sets the value of [mlp_dimensions
].
Sourcepub fn activation(
self,
activation: impl Into<Option<Box<dyn Activation>>>,
) -> Self
pub fn activation( self, activation: impl Into<Option<Box<dyn Activation>>>, ) -> Self
Sets the value of [activation
].
Sourcepub fn norm_first(self, norm_first: impl Into<bool>) -> Self
pub fn norm_first(self, norm_first: impl Into<bool>) -> Self
Sets the value of [norm_first
].
Trait Implementations§
Source§impl Builder<Transformer> for TransformerBuilder
impl Builder<Transformer> for TransformerBuilder
Source§type Error = TransformerBulidError
type Error = TransformerBulidError
Source§impl Clone for TransformerBuilder
impl Clone for TransformerBuilder
Auto Trait Implementations§
impl Freeze for TransformerBuilder
impl !RefUnwindSafe for TransformerBuilder
impl !Send for TransformerBuilder
impl !Sync for TransformerBuilder
impl Unpin for TransformerBuilder
impl !UnwindSafe for TransformerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Option
.