pub struct Transformer { /* private fields */ }
Expand description
Implements a standard Transformer model.
The implementation is based on “Attention Is All You Need” https://arxiv.org/abs/1706.03762.
The Transformer model contains an encoder and a decoder. The encoder processes the input sequence and the decoder generates the output sequence. The interaction between encoder and decoder happens through the attention mechanism.
Implementations§
Source§impl Transformer
impl Transformer
Source§impl Transformer
impl Transformer
Sourcepub const DEFAULT_DIMENSIONS: i32 = 512i32
pub const DEFAULT_DIMENSIONS: i32 = 512i32
Default value for dimensions
Sourcepub const DEFAULT_NUM_HEADS: i32 = 8i32
pub const DEFAULT_NUM_HEADS: i32 = 8i32
Default value for num_heads
Sourcepub const DEFAULT_ENCODER_LAYERS_COUNT: usize = 6usize
pub const DEFAULT_ENCODER_LAYERS_COUNT: usize = 6usize
Default number of encoder layers
Sourcepub const DEFAULT_DECODER_LAYERS_COUNT: usize = 6usize
pub const DEFAULT_DECODER_LAYERS_COUNT: usize = 6usize
Default number of decoder layers
Sourcepub const DEFAULT_DROPOUT: f32 = 0f32
pub const DEFAULT_DROPOUT: f32 = 0f32
Default value for dropout
Sourcepub const DEFAULT_NORM_FIRST: bool = false
pub const DEFAULT_NORM_FIRST: bool = false
Default value for activation
Trait Implementations§
Source§impl Buildable for Transformer
impl Buildable for Transformer
Source§type Builder = TransformerBuilder
type Builder = TransformerBuilder
The builder type for this buildable type
Source§impl Builder<Transformer> for TransformerBuilder
impl Builder<Transformer> for TransformerBuilder
Source§type Error = TransformerBulidError
type Error = TransformerBulidError
Error with building
Source§impl Clone for Transformer
impl Clone for Transformer
Source§fn clone(&self) -> Transformer
fn clone(&self) -> Transformer
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Transformer
impl Debug for Transformer
Source§impl<'a, Input> Module<Input> for Transformerwhere
Input: Into<TransformerInput<'a>>,
impl<'a, Input> Module<Input> for Transformerwhere
Input: Into<TransformerInput<'a>>,
Source§impl ModuleParameters for Transformer
impl ModuleParameters for Transformer
Source§fn freeze_parameters(&mut self, recursive: bool)
fn freeze_parameters(&mut self, recursive: bool)
Freeze all parameters in the module.
Source§fn unfreeze_parameters(&mut self, recursive: bool)
fn unfreeze_parameters(&mut self, recursive: bool)
Unfreeze all parameters in the module.
Source§fn parameters(&self) -> ModuleParamRef<'_>
fn parameters(&self) -> ModuleParamRef<'_>
Get references to the module parameters.
Source§fn parameters_mut(&mut self) -> ModuleParamMut<'_>
fn parameters_mut(&mut self) -> ModuleParamMut<'_>
Get mutable references to the module parameters.
Source§fn trainable_parameters(&self) -> ModuleParamRef<'_>
fn trainable_parameters(&self) -> ModuleParamRef<'_>
Get references to the trainable parameters. A parameter is trainable if it is NOT frozen.
Source§fn all_frozen(&self) -> Option<bool>
fn all_frozen(&self) -> Option<bool>
Check if all parameters in the module are frozen. Returns
None
if there are no parameters.Source§fn any_frozen(&self) -> Option<bool>
fn any_frozen(&self) -> Option<bool>
Check if any parameter in the module is frozen. Returns
None
if there are no parameters.Source§fn update(&mut self, parameters: ModuleParam)
fn update(&mut self, parameters: ModuleParam)
Update the module parameters.
Source§fn update_flattened(&mut self, flattened_parameters: FlattenedModuleParam)
fn update_flattened(&mut self, flattened_parameters: FlattenedModuleParam)
Update the module parameters from a flattened representation.
Source§impl Quantizable for Transformer
impl Quantizable for Transformer
Source§type Quantized = Transformer
type Quantized = Transformer
The quantized type.
Source§type QuantizationError = Exception
type QuantizationError = Exception
The error type for quantization.
Source§fn try_into_quantized(
self,
group_size: i32,
bits: i32,
) -> Result<Self::Quantized, Self::QuantizationError>
fn try_into_quantized( self, group_size: i32, bits: i32, ) -> Result<Self::Quantized, Self::QuantizationError>
Quantize the module with the specified group size and number of bits.
Source§const DEFAULT_GROUP_SIZE: i32 = 64i32
const DEFAULT_GROUP_SIZE: i32 = 64i32
The default group size for quantization.
Source§const DEFAULT_BITS: i32 = 4i32
const DEFAULT_BITS: i32 = 4i32
The default number of bits for quantization.
Auto Trait Implementations§
impl Freeze for Transformer
impl !RefUnwindSafe for Transformer
impl !Send for Transformer
impl !Sync for Transformer
impl Unpin for Transformer
impl !UnwindSafe for Transformer
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> 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 moreSource§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Convert into an
Option
.Source§impl<T> IntoStrideBy for T
impl<T> IntoStrideBy for T
Source§impl<T> ModuleParametersExt for Twhere
T: ModuleParameters,
impl<T> ModuleParametersExt for Twhere
T: ModuleParameters,
Source§impl<T> Parameter for Twhere
T: ModuleParameters,
impl<T> Parameter for Twhere
T: ModuleParameters,
Source§fn is_frozen(&self) -> Option<bool>
fn is_frozen(&self) -> Option<bool>
Check if the parameter is frozen. Returns
None
if the parameter is a module that has no
parameters.Source§fn as_nested_value(&self) -> NestedValue<Rc<str>, &Array>
fn as_nested_value(&self) -> NestedValue<Rc<str>, &Array>
Get the parameter as a nested value.
Source§fn as_nested_value_mut(&mut self) -> NestedValue<Rc<str>, &mut Array>
fn as_nested_value_mut(&mut self) -> NestedValue<Rc<str>, &mut Array>
Get the parameter as a mutable nested value.
Source§fn as_trainable_nested_value(&self) -> Option<NestedValue<Rc<str>, &Array>>
fn as_trainable_nested_value(&self) -> Option<NestedValue<Rc<str>, &Array>>
Get the parameter as a nested value if it is trainable.
Source§impl<T> Updatable for Twhere
T: ModuleParameters,
impl<T> Updatable for Twhere
T: ModuleParameters,
Source§fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
fn updatable_states(&self) -> impl IntoIterator<Item = &Array>
Returns a list of references to the updatable states. Read more
Source§fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
fn updatable_states_mut(&mut self) -> impl IntoIterator<Item = &mut Array>
Returns a list of mutable references to the updatable states. Read more