pub struct NabModel { /* private fields */ }
Expand description
Represents a model using the Functional API
§Examples
use nabla_ml::nab_model::NabModel;
use nabla_ml::nab_layers::NabLayer;
// Create model architecture
let input = NabModel::input(vec![784]);
let dense1 = NabLayer::dense(784, 512, Some("relu"), Some("dense1"));
let x = input.apply(dense1);
let output_layer = NabLayer::dense(512, 10, Some("softmax"), Some("output"));
let output = x.apply(output_layer);
// Create and compile model
let mut model = NabModel::new_functional(vec![input], vec![output]);
model.compile(
"sgd",
0.1,
"categorical_crossentropy",
vec!["accuracy".to_string()]
);
Implementations§
Source§impl NabModel
impl NabModel
Sourcepub fn compile(
&mut self,
optimizer_type: &str,
learning_rate: f64,
loss_type: &str,
metrics: Vec<String>,
)
pub fn compile( &mut self, optimizer_type: &str, learning_rate: f64, loss_type: &str, metrics: Vec<String>, )
Compiles the model with training configuration
§Arguments
optimizer_type
- Optimization algorithm (“sgd”, “adam”, etc)learning_rate
- Learning rate for optimizationloss_type
- Loss function (“mse”, “categorical_crossentropy”)metrics
- Metrics to track during training
Sourcepub fn new_functional(inputs: Vec<Input>, outputs: Vec<Output>) -> Self
pub fn new_functional(inputs: Vec<Input>, outputs: Vec<Output>) -> Self
Creates a new model from input and output nodes
Sourcepub fn fit(
&mut self,
x_train: &NDArray,
y_train: &NDArray,
batch_size: usize,
epochs: usize,
validation_data: Option<(&NDArray, &NDArray)>,
) -> HashMap<String, Vec<f64>>
pub fn fit( &mut self, x_train: &NDArray, y_train: &NDArray, batch_size: usize, epochs: usize, validation_data: Option<(&NDArray, &NDArray)>, ) -> HashMap<String, Vec<f64>>
Trains the model on input data
§Arguments
x_train
- Training featuresy_train
- Training labelsbatch_size
- Mini-batch sizeepochs
- Number of training epochsvalidation_data
- Optional validation dataset
§Returns
HashMap containing training history metrics
§Examples
ⓘ
let history = model.fit(
&x_train,
&y_train,
64, // batch_size
5, // epochs
Some((&x_test, &y_test))
);
Sourcepub fn evaluate(
&mut self,
x_test: &NDArray,
y_test: &NDArray,
batch_size: usize,
) -> HashMap<String, f64>
pub fn evaluate( &mut self, x_test: &NDArray, y_test: &NDArray, batch_size: usize, ) -> HashMap<String, f64>
pub fn print_layers(&self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NabModel
impl RefUnwindSafe for NabModel
impl Send for NabModel
impl Sync for NabModel
impl Unpin for NabModel
impl UnwindSafe for NabModel
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