pub struct PositionalEncoding<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Positional encoding implementation
Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> PositionalEncoding<T>
impl<T: Float + Debug + Send + Sync + 'static> PositionalEncoding<T>
Sourcepub fn new(
max_sequence_length: usize,
model_dimension: usize,
encoding_type: PositionalEncodingType,
) -> Result<Self>
pub fn new( max_sequence_length: usize, model_dimension: usize, encoding_type: PositionalEncodingType, ) -> Result<Self>
Create new positional encoding
Sourcepub fn encode(&self, input: &Array2<T>) -> Result<Array2<T>>
pub fn encode(&self, input: &Array2<T>) -> Result<Array2<T>>
Apply positional encoding to input
Sourcepub fn get_position_encoding(&self, position: usize) -> Result<Array1<T>>
pub fn get_position_encoding(&self, position: usize) -> Result<Array1<T>>
Get encoding for specific position
Sourcepub fn update_learned_embeddings(&mut self, gradients: &Array2<T>) -> Result<()>
pub fn update_learned_embeddings(&mut self, gradients: &Array2<T>) -> Result<()>
Update learned embeddings (for training)
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Get parameter count
Sourcepub fn get_encoding_type(&self) -> PositionalEncodingType
pub fn get_encoding_type(&self) -> PositionalEncodingType
Get encoding type
Sourcepub fn get_max_sequence_length(&self) -> usize
pub fn get_max_sequence_length(&self) -> usize
Get maximum sequence length
Sourcepub fn get_model_dimension(&self) -> usize
pub fn get_model_dimension(&self) -> usize
Get model dimension
Sourcepub fn sinusoidal_with_base(
max_sequence_length: usize,
model_dimension: usize,
base: T,
) -> Result<Self>
pub fn sinusoidal_with_base( max_sequence_length: usize, model_dimension: usize, base: T, ) -> Result<Self>
Create sinusoidal encoding with custom base
Sourcepub fn rotary_with_base(
max_sequence_length: usize,
model_dimension: usize,
base: T,
) -> Result<Self>
pub fn rotary_with_base( max_sequence_length: usize, model_dimension: usize, base: T, ) -> Result<Self>
Create rotary encoding with custom base
Auto 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> 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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.