pub struct LayerNorm1D<const M: usize> {
    pub gamma: Tensor1D<M>,
    pub beta: Tensor1D<M>,
    pub epsilon: f32,
}
Expand description

Implements layer normalization as described in Layer Normalization.

This calls normalize() on the last axis of the input to normalize to 0 mean and unit std dev, and then does an element-wise affine transform using learnable parameters Self::gamma and Self::beta.

Self::epsilon is passed to normalize() and added to the variance to ensure big enough numbers. It defaults to 1e-5.

Generics

  • M The size of the affine transform tensors.

Examples

let model: LayerNorm1D<5> = Default::default();
let x: Tensor1D<5> = Default::default();
let _: Tensor1D<5> = model.forward(x);

Fields

gamma: Tensor1D<M>beta: Tensor1D<M>epsilon: f32

Trait Implementations

Updates Self::gamma and Self::beta.

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Fills Self::gamma with 1s and Self::beta with 0s and sets Self::epsilon to 1e-5.

Reads this object from a ZipArchive. r with a base filename of filename_prefix. Read more
Loads data from a .npz zip archive at the specified path. Read more
The type that this unit produces given Input.
The type that this unit produces given Input.
The type that this unit produces given Input.
The type that this unit produces given Input.
Forward Input through the module and produce ModuleMut::Output. Read more

Fills Self::gamma with 1s and Self::beta with 0s.

Write this object into ZipWriter w with a base filename of filename_prefix. Read more
Save this object into the .npz file determined located at path. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.