pub struct LayerNormalization<T: Float + Debug + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Layer normalization implementation
Implementations§
Source§impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> LayerNormalization<T>
impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> LayerNormalization<T>
Sourcepub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
pub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
Forward pass through layer normalization.
Rejects inputs whose width differs from the configured dimension instead of indexing out of bounds.
Sourcepub fn backward(
&mut self,
input: &Array2<T>,
grad_output: &Array2<T>,
learning_rate: T,
) -> Result<Array2<T>>
pub fn backward( &mut self, input: &Array2<T>, grad_output: &Array2<T>, learning_rate: T, ) -> Result<Array2<T>>
Backward pass through layer normalization.
With xhat = (x - mu) / sqrt(var + eps) and y = gamma * xhat + beta,
the exact input gradient for one row is
dL/dx = (1/sigma) * (g' - mean(g') - xhat * mean(g' * xhat))
where g' = dL/dy * gamma. gamma and beta are updated in place with
a plain SGD step and the input gradient is returned.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Get parameter count
Auto Trait Implementations§
impl<T> Freeze for LayerNormalization<T>
impl<T> RefUnwindSafe for LayerNormalization<T>
impl<T> Send for LayerNormalization<T>
impl<T> Sync for LayerNormalization<T>
impl<T> Unpin for LayerNormalization<T>
impl<T> UnsafeUnpin for LayerNormalization<T>
impl<T> UnwindSafe for LayerNormalization<T>
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> 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
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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.