#![allow(clippy::type_complexity)]
pub mod layers;
pub mod loss;
pub mod models;
pub mod optimizers;
pub mod persistence;
pub mod schedulers;
pub mod text;
pub mod training;
pub mod utils;
pub use layers::bilstm_network::{BiLSTMNetwork, BiLSTMNetworkCache, CombineMode};
pub use layers::dropout::{Dropout, Zoneout};
pub use layers::gru_cell::{GRUCell, GRUCellCache, GRUCellGradients};
pub use layers::linear::{LinearGradients, LinearLayer};
pub use layers::lstm_cell::{LSTMCell, LSTMCellCache, LSTMCellGradients};
pub use layers::peephole_lstm_cell::{
PeepholeLSTMCell, PeepholeLSTMCellCache, PeepholeLSTMCellGradients,
};
pub use loss::{CrossEntropyLoss, LossFunction, MAELoss, MSELoss};
pub use models::gru_network::{
GRUNetwork, GRUNetworkCache, LayerDropoutConfig as GRULayerDropoutConfig,
};
pub use models::lstm_network::{LSTMNetwork, LSTMNetworkCache, LSTMState, LayerDropoutConfig};
pub use optimizers::{Adam, RMSprop, ScheduledOptimizer, SGD};
pub use persistence::{ModelMetadata, ModelPersistence, PersistenceError, PersistentModel};
pub use schedulers::{
AnnealStrategy, ConstantLR, CosineAnnealingLR, CosineAnnealingWarmRestarts, CyclicalLR,
CyclicalMode, ExponentialLR, LRScheduleVisualizer, LearningRateScheduler, LinearLR,
MultiStepLR, OneCycleLR, PolynomialLR, ReduceLROnPlateau, ScaleMode, StepLR, WarmupScheduler,
};
pub use text::{
argmax, sample_nucleus, sample_top_k, sample_with_temperature, softmax, CharacterEmbedding,
EmbeddingGradients, TextVocabulary,
};
pub use training::{
create_adam_batch_trainer, create_basic_batch_trainer, create_basic_trainer,
create_cosine_annealing_trainer, create_one_cycle_trainer, create_step_lr_trainer,
EarlyStopper, EarlyStoppingConfig, EarlyStoppingMetric, LSTMBatchTrainer, LSTMTrainer,
ScheduledLSTMTrainer, TrainingConfig, TrainingMetrics,
};
#[cfg(test)]
mod tests {
use super::*;
use ndarray::arr2;
#[test]
fn test_library_integration() {
let mut network = models::lstm_network::LSTMNetwork::new(2, 3, 1);
let input = arr2(&[[1.0], [0.5]]);
let state = network.zero_state(1);
let (hy, next) = network.forward(&input, &state);
let cy = &next.c[0];
assert_eq!(hy.shape(), &[3, 1]);
assert_eq!(cy.shape(), &[3, 1]);
}
#[test]
fn test_library_with_dropout() {
let mut network = models::lstm_network::LSTMNetwork::new(2, 3, 1)
.with_input_dropout(0.2, false)
.with_recurrent_dropout(0.3, true)
.with_output_dropout(0.1);
let input = arr2(&[[1.0], [0.5]]);
let state = network.zero_state(1);
network.train();
let (hy_train, next_train) = network.forward(&input, &state);
let cy_train = &next_train.c[0];
network.eval();
let (hy_eval, next_eval) = network.forward(&input, &state);
let cy_eval = &next_eval.c[0];
assert_eq!(hy_train.shape(), &[3, 1]);
assert_eq!(cy_train.shape(), &[3, 1]);
assert_eq!(hy_eval.shape(), &[3, 1]);
assert_eq!(cy_eval.shape(), &[3, 1]);
}
}