|
Mila
Deep Neural Network Library
|
Corpus accumulator and trainer for BPE vocabularies. More...
Public Member Functions | |
| BpeTrainer (const BpeVocabularyConfig &config=BpeVocabularyConfig{}) | |
| Construct with a vocabulary configuration. | |
| void | addCorpusFromFile (const std::filesystem::path &path) |
| Append corpus text from a file. | |
| void | addCorpusFromStream (std::istream &stream) |
| Append corpus text from a stream. | |
| void | clearCorpus () |
| const BpeVocabularyConfig & | getConfig () const |
| size_t | getCorpusSize () const |
| BpeVocabulary | train () |
| Train a BPE vocabulary on the accumulated corpus. | |
Corpus accumulator and trainer for BPE vocabularies.
Typical usage:
|
inlineexplicit |
Construct with a vocabulary configuration.
validate() is called immediately so misconfigured trainers fail at construction rather than at train() time.
| config | BPE vocabulary configuration. |
| std::invalid_argument | if config fails validation. |
|
inline |
Append corpus text from a file.
| path | Path to a UTF-8 text file. |
| std::runtime_error | if the file cannot be opened. |
|
inline |
Append corpus text from a stream.
May be called multiple times to accumulate text from different sources before a single train() call.
| stream | Input stream containing UTF-8 text. |
|
inline |
Train a BPE vocabulary on the accumulated corpus.
Delegates to BpeVocabulary::train() and clears the accumulated corpus afterwards to release memory. The returned vocabulary can be saved via BpeVocabulary::save() and later reloaded with BpeVocabulary::load().
| std::runtime_error | if no corpus has been accumulated. |