pub struct PositionalEncoding<T: FloatBounds> { /* private fields */ }Expand description
Positional encoding implementation for transformer architectures
Adds positional information to input embeddings to help the model understand the order of elements in a sequence.
Implementations§
Source§impl<T: FloatBounds + ScalarOperand + From<f64>> PositionalEncoding<T>
impl<T: FloatBounds + ScalarOperand + From<f64>> PositionalEncoding<T>
Sourcepub fn new(
max_seq_len: usize,
d_model: usize,
encoding_type: PositionalEncodingType,
dropout_rate: T,
scale_embeddings: bool,
) -> NeuralResult<Self>
pub fn new( max_seq_len: usize, d_model: usize, encoding_type: PositionalEncodingType, dropout_rate: T, scale_embeddings: bool, ) -> NeuralResult<Self>
Create a new positional encoding layer
Sourcepub fn encode(&self, embeddings: &Array3<T>) -> NeuralResult<Array3<T>>
pub fn encode(&self, embeddings: &Array3<T>) -> NeuralResult<Array3<T>>
Apply positional encoding to input embeddings
Sourcepub fn get_encodings(&self, seq_len: usize) -> NeuralResult<Array2<T>>
pub fn get_encodings(&self, seq_len: usize) -> NeuralResult<Array2<T>>
Get positional encodings for a specific sequence length
Sourcepub fn update_position_embeddings(
&mut self,
gradients: &Array2<T>,
learning_rate: T,
) -> NeuralResult<()>
pub fn update_position_embeddings( &mut self, gradients: &Array2<T>, learning_rate: T, ) -> NeuralResult<()>
Update learnable position embeddings (for gradient-based optimization)
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get the number of parameters
Trait Implementations§
Source§impl<T: Clone + FloatBounds> Clone for PositionalEncoding<T>
impl<T: Clone + FloatBounds> Clone for PositionalEncoding<T>
Source§fn clone(&self) -> PositionalEncoding<T>
fn clone(&self) -> PositionalEncoding<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for PositionalEncoding<T>where
T: Freeze,
impl<T> RefUnwindSafe for PositionalEncoding<T>where
T: RefUnwindSafe,
impl<T> Send for PositionalEncoding<T>
impl<T> Sync for PositionalEncoding<T>
impl<T> Unpin for PositionalEncoding<T>where
T: Unpin,
impl<T> UnsafeUnpin for PositionalEncoding<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for PositionalEncoding<T>where
T: UnwindSafe + RefUnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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