Struct TransformerModel

Source
pub struct TransformerModel<T = f64> {
    pub config: StandardModelConfig<T>,
    pub features: ModelFeatures,
    pub params: DeepModelParams<T>,
}

Fields§

§config: StandardModelConfig<T>§features: ModelFeatures§params: DeepModelParams<T>

Implementations§

Source§

impl<T> TransformerModel<T>

Source

pub fn new(config: StandardModelConfig<T>, features: ModelFeatures) -> Self
where T: Clone + Default,

Source

pub fn init(self) -> Self

Source

pub const fn config(&self) -> &StandardModelConfig<T>

returns a reference to the model configuration

Source

pub const fn config_mut(&mut self) -> &mut StandardModelConfig<T>

returns a mutable reference to the model configuration

Source

pub const fn features(&self) -> ModelFeatures

returns the model features

Source

pub const fn features_mut(&mut self) -> &mut ModelFeatures

returns a mutable reference to the model features

Source

pub const fn params(&self) -> &DeepModelParams<T>

returns a reference to the model parameters

Source

pub const fn params_mut(&mut self) -> &mut DeepModelParams<T>

returns a mutable reference to the model parameters

Source

pub fn set_config(&mut self, config: StandardModelConfig<T>) -> &mut Self

set the current configuration and return a mutable reference to the model

Source

pub fn set_features(&mut self, features: ModelFeatures) -> &mut Self

set the current features and return a mutable reference to the model

Source

pub fn set_params(&mut self, params: DeepModelParams<T>) -> &mut Self

set the current parameters and return a mutable reference to the model

Source

pub fn with_config(self, config: StandardModelConfig<T>) -> Self

consumes the current instance to create another with the given configuration

Source

pub fn with_features(self, features: ModelFeatures) -> Self

consumes the current instance to create another with the given features

Source

pub fn with_params(self, params: DeepModelParams<T>) -> Self

consumes the current instance to create another with the given parameters

Trait Implementations§

Source§

impl<T: Clone> Clone for TransformerModel<T>

Source§

fn clone(&self) -> TransformerModel<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TransformerModel<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A, U, V> Forward<U> for TransformerModel<A>
where A: Float + FromPrimitive + ScalarOperand, V: ReLU<Output = V> + Sigmoid<Output = V> + for<'a> Add<&'a Array1<A>, Output = V>, Params<A>: Forward<U, Output = V> + Forward<V, Output = V>, for<'a> &'a U: Dot<Array2<A>, Output = V> + Add<&'a Array1<A>>,

Source§

type Output = V

Source§

fn forward(&self, input: &U) -> Result<Self::Output>

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<T> Model<T> for TransformerModel<T>

Source§

type Config = StandardModelConfig<T>

The type of configuration used for the model
Source§

type Layout = ModelFeatures

The type of ModelLayout used by the model for this implementation.
Source§

fn config(&self) -> &StandardModelConfig<T>

returns an immutable reference to the models configuration; this is typically used to access the models hyperparameters (i.e. learning rate, momentum, etc.) and other related control parameters.
Source§

fn config_mut(&mut self) -> &mut StandardModelConfig<T>

returns a mutable reference to the models configuration; useful for setting hyperparams
Source§

fn layout(&self) -> ModelFeatures

returns a copy of the model’s current layout (features); a type providing the model with a particular number of features for the various layers of a deep neural network. Read more
Source§

fn params(&self) -> &DeepModelParams<T>

returns an immutable reference to the model parameters
Source§

fn params_mut(&mut self) -> &mut DeepModelParams<T>

returns a mutable reference to the model’s parameters
Source§

fn predict<U, V>(&self, inputs: &U) -> Result<V, ModelError>
where Self: Predict<U, Output = V>,

propagates the input through the model; each layer is applied in sequence meaning that the output of each previous layer is the input to the next layer. This pattern repeats until the output layer returns the final result. Read more
Source§

fn train<U, V, W>( &mut self, dataset: &DatasetBase<U, V>, ) -> Result<W, ModelError>
where Self: Train<U, V, Output = W>,

a convience method that trains the model using the provided dataset; this method requires that the model implements the Train trait and that the dataset
Source§

impl<A, S, T> Train<ArrayBase<S, Dim<[usize; 1]>>, ArrayBase<T, Dim<[usize; 1]>>> for TransformerModel<A>
where A: Float + FromPrimitive + NumAssign + ScalarOperand + Debug, S: Data<Elem = A>, T: Data<Elem = A>,

Source§

type Output = A

Source§

fn train( &mut self, input: &ArrayBase<S, Ix1>, target: &ArrayBase<T, Ix1>, ) -> Result<Self::Output, ModelError>

Source§

fn train_for( &mut self, input: &X, target: &Y, epochs: usize, ) -> Result<Self::Output, ModelError>

Source§

impl<A, S, T> Train<ArrayBase<S, Dim<[usize; 2]>>, ArrayBase<T, Dim<[usize; 2]>>> for TransformerModel<A>
where A: Float + FromPrimitive + NumAssign + ScalarOperand + Debug, S: Data<Elem = A>, T: Data<Elem = A>,

Source§

type Output = A

Source§

fn train( &mut self, input: &ArrayBase<S, Ix2>, target: &ArrayBase<T, Ix2>, ) -> Result<Self::Output, ModelError>

Source§

fn train_for( &mut self, input: &X, target: &Y, epochs: usize, ) -> Result<Self::Output, ModelError>

Auto Trait Implementations§

§

impl<T> Freeze for TransformerModel<T>

§

impl<T> RefUnwindSafe for TransformerModel<T>
where T: RefUnwindSafe,

§

impl<T> Send for TransformerModel<T>
where T: Send,

§

impl<T> Sync for TransformerModel<T>
where T: Sync,

§

impl<T> Unpin for TransformerModel<T>
where T: Unpin,

§

impl<T> UnwindSafe for TransformerModel<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CallInPlace<T> for T
where T: CallInto<T>,

Source§

fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
where F: FnMut(&mut T) -> <T as CallInto<T>>::Output,

The call_on_mut method allows an object to be passed onto a function that takes a mutable reference to the object. This is useful for cases where you want to perform an operation on an object and mutate it in the process.
Source§

impl<T> CallInto<T> for T

Source§

type Output = T

Source§

fn call_into<F>(self, f: F) -> <T as CallInto<T>>::Output
where F: FnOnce(T) -> <T as CallInto<T>>::Output,

The call_into method allows an object to be passed into a function that takes ownership of the object. This is useful for cases where you want to perform an operation on an object and consume it in the process.
Source§

impl<T> CallOn<T> for T
where T: CallInto<T>,

Source§

fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
where F: FnMut(&T) -> <T as CallInto<T>>::Output,

The call_on method allows an object to be passed onto a function that takes a reference to the object. This is useful for cases where you want to perform an operation on an object without needing to extract it from a container or context.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<K, S> Identity<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Identity<K>>::Item

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<Q> RawState for Q
where Q: Send + Sync + Debug,

Source§

fn __private__(&self) -> Seal

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more