pub struct Trainer {
pub history: Vec<EpochStats>,
/* private fields */
}Expand description
Manages the full training pipeline.
Fields§
§history: Vec<EpochStats>Loss history per epoch (populated during train).
Implementations§
Source§impl Trainer
impl Trainer
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Create a new trainer with the given configuration.
use word2vec::{Config, Trainer};
let trainer = Trainer::new(Config::default());
assert!(trainer.history.is_empty());Sourcepub fn train(&mut self, corpus: &[String]) -> Result<Embeddings>
pub fn train(&mut self, corpus: &[String]) -> Result<Embeddings>
Train on a corpus of sentences.
Returns Embeddings which wraps the trained model and vocabulary
for inference queries.
§Errors
Returns Word2VecError if the config is invalid or the corpus
is too small to train.
§Example
use word2vec::{Config, ModelType, Trainer};
let corpus = vec![
"paris is the capital of france".to_string(),
"berlin is the capital of germany".to_string(),
"tokyo is the capital of japan".to_string(),
];
let mut trainer = Trainer::new(Config {
epochs: 3,
embedding_dim: 50,
..Config::default()
});
let embeddings = trainer.train(&corpus).unwrap();
println!("Vocab size: {}", embeddings.vocab_size());Auto Trait Implementations§
impl Freeze for Trainer
impl RefUnwindSafe for Trainer
impl Send for Trainer
impl Sync for Trainer
impl Unpin for Trainer
impl UnsafeUnpin for Trainer
impl UnwindSafe for Trainer
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