pub trait Model<T = f32> {
// Required methods
fn config(&self) -> &StandardModelConfig<T>;
fn config_mut(&mut self) -> &mut StandardModelConfig<T>;
fn features(&self) -> ModelFeatures;
fn params(&self) -> &ModelParams<T>;
fn params_mut(&mut self) -> &mut ModelParams<T>;
// Provided methods
fn forward<U, V>(&self, inputs: &U) -> Result<V>
where Self: Forward<U, Output = V> { ... }
fn train<U, V>(
&mut self,
dataset: Dataset<U, V>,
) -> Trainer<'_, Self, T, Dataset<U, V>>
where Self: Sized,
T: Default { ... }
}Expand description
This trait defines the base interface for all models, providing access to the models configuration, layout, and learned parameters.
Required Methods§
Sourcefn config(&self) -> &StandardModelConfig<T>
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.
Sourcefn config_mut(&mut self) -> &mut StandardModelConfig<T>
fn config_mut(&mut self) -> &mut StandardModelConfig<T>
returns a mutable reference to the models configuration; useful for setting hyperparams
Sourcefn features(&self) -> ModelFeatures
fn features(&self) -> ModelFeatures
returns a copy of the models features (or layout); this is used to define the structure of the model and its consituents.
Sourcefn params(&self) -> &ModelParams<T>
fn params(&self) -> &ModelParams<T>
returns an immutable reference to the model parameters
Sourcefn params_mut(&mut self) -> &mut ModelParams<T>
fn params_mut(&mut self) -> &mut ModelParams<T>
returns a mutable reference to the model’s parameters
Provided Methods§
Sourcefn forward<U, V>(&self, inputs: &U) -> Result<V>where
Self: Forward<U, Output = V>,
fn forward<U, V>(&self, inputs: &U) -> Result<V>where
Self: Forward<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.
By default, the trait simply passes each output from one layer to the next, however, custom models will likely override this method to inject activation methods and other related logic
Sourcefn train<U, V>(
&mut self,
dataset: Dataset<U, V>,
) -> Trainer<'_, Self, T, Dataset<U, V>>
fn train<U, V>( &mut self, dataset: Dataset<U, V>, ) -> Trainer<'_, Self, T, Dataset<U, V>>
returns a model trainer prepared to train the model; this is a convenience method
that creates a new trainer instance and returns it. Trainers are lazily evaluated
meaning that the training process won’t begin until the user calls the begin method.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.