Crate ct2rs

Source
Expand description

This crate provides Rust bindings for OpenNMT/CTranslate2.

This crate provides the following:

§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§

GenerationOptions
The set of generation options.
GenerationStepResult
The result for a single generation step.
Generator
A text generator with a tokenizer.
TranslationOptions
Options for translation.
Translator
A text translator with a tokenizer.
Whisperwhisper
A speach transcriber using the Whisper speech recognition model published by OpenAI.
WhisperOptionswhisper
Options for whisper generation.

Traits§

Tokenizer
Defines the necessary functions for a tokenizer.

Functions§

download_modelhub
Downloads a model by its ID and returns the path to the directory where the model files are stored.