Expand description
This crate provides Rust bindings for OpenNMT/CTranslate2.
This crate provides the following:
- Rust bindings for
ctranslate2::Translator,
ctranslate2::Generator,
and
ctranslate2::Whisper
provided by CTranslate2, specifically
sys::Translator
,sys::Generator
, andsys::Whisper
. - More user-friendly versions of these,
Translator
,Generator
, andWhisper
(whisper
feature is required), which incorporate tokenizers for easier handling.
§Basic Usage
The following example translates two strings using default settings and outputs each to the standard output.
use ct2rs::{Config, Translator, TranslationOptions};
let sources = vec![
"Hallo World!",
"This crate provides Rust bindings for CTranslate2."
];
let translator = Translator::new("/path/to/model", &Default::default())?;
let results = translator.translate_batch(&sources, &Default::default(), None)?;
for (r, _) in results{
println!("{}", r);
}
§Supported Models
The ct2rs
crate has been tested and confirmed to work with the following models:
- BART
- BLOOM
- FALCON
- Marian-MT
- MPT
- NLLB
- GPT-2
- GPT-J
- OPT
- T5
- Whisper
Please see the respective examples for each model.
§Stream API
This crate also offers a streaming API that utilizes callback closures. Please refer to the example code for more information.
Re-exports§
pub use sys::set_log_level;
pub use sys::set_random_seed;
pub use sys::BatchType;
pub use sys::ComputeType;
pub use sys::Config;
pub use sys::Device;
pub use sys::LogLevel;
pub use sys::ScoringOptions;
pub use sys::ScoringResult;
Modules§
- sys
- This module provides raw bindings for CTranslate2.
- tokenizers
- This module provides tokenizers.
Structs§
- Generation
Options - The set of generation options.
- Generation
Step Result - The result for a single generation step.
- Generator
- A text generator with a tokenizer.
- Translation
Options - Options for translation.
- Translator
- A text translator with a tokenizer.
- Whisper
whisper
- A speach transcriber using the Whisper speech recognition model published by OpenAI.
- Whisper
Options whisper
- Options for whisper generation.
Traits§
- Tokenizer
- Defines the necessary functions for a tokenizer.
Functions§
- download_
model hub
- Downloads a model by its ID and returns the path to the directory where the model files are stored.