pub struct TransformerEncoderLayer { /* private fields */ }Expand description
Transformer Encoder Layer.
Consists of self-attention followed by a feed-forward network, with residual connections and layer normalization.
x = x + Dropout(SelfAttention(LayerNorm(x)))
x = x + Dropout(FFN(LayerNorm(x)))Implementations§
Source§impl TransformerEncoderLayer
impl TransformerEncoderLayer
Sourcepub fn new(
d_model: usize,
nhead: usize,
dim_feedforward: usize,
) -> TransformerEncoderLayer
pub fn new( d_model: usize, nhead: usize, dim_feedforward: usize, ) -> TransformerEncoderLayer
Create a new Transformer Encoder Layer.
§Arguments
d_model- Dimension of the modelnhead- Number of attention headsdim_feedforward- Dimension of the feedforward network (typically 4 *d_model)
Sourcepub fn with_dropout(self, dropout: f32) -> TransformerEncoderLayer
pub fn with_dropout(self, dropout: f32) -> TransformerEncoderLayer
Set dropout probability.
Trait Implementations§
Source§impl Debug for TransformerEncoderLayer
impl Debug for TransformerEncoderLayer
Source§impl Module for TransformerEncoderLayer
impl Module for TransformerEncoderLayer
Source§fn parameters_mut(&mut self) -> Vec<&mut Tensor>
fn parameters_mut(&mut self) -> Vec<&mut Tensor>
Get mutable references to all learnable parameters. Read more
Source§fn refresh_caches(&mut self)
fn refresh_caches(&mut self)
Refresh any cached computations after parameters have been modified. Read more
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Get the number of learnable parameters.
Auto Trait Implementations§
impl !Freeze for TransformerEncoderLayer
impl !RefUnwindSafe for TransformerEncoderLayer
impl Send for TransformerEncoderLayer
impl Sync for TransformerEncoderLayer
impl Unpin for TransformerEncoderLayer
impl UnsafeUnpin for TransformerEncoderLayer
impl !UnwindSafe for TransformerEncoderLayer
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more