pub fn new_from_resources(
        model_resource: Resource,
        config_resource: Resource,
        vocab_resource: Resource,
        sentence_piece_resource: Resource,
        prefix: Option<String>,
        device: Device,
        model_type: ModelType,
    ) -> TranslationConfig {
        TranslationConfig {
            model_resource,
            config_resource,
            vocab_resource,
            merges_resource: sentence_piece_resource,
            min_length: 0,
            max_length: 512,
            do_sample: false,
            early_stopping: false,
            num_beams: 6,
            temperature: 1.0,
            top_k: 50,
            top_p: 1.0,
            repetition_penalty: 1.0,
            length_penalty: 1.0,
            no_repeat_ngram_size: 0,
            num_return_sequences: 1,
            device,
            prefix,
            model_type,
        }
    }
/// Create a new `TranslationConfiguration` from custom (e.g. local) resources.
///
/// # Arguments
///
/// * `model_resource` - `Resource` pointing to the model
/// * `config_resource` - `Resource` pointing to the configuration
/// * `vocab_resource` - `Resource` pointing to the vocabulary
/// * `sentence_piece_resource` - `Resource` pointing to the sentence piece model of the source language
/// * `device` - `Device` to place the model on (CPU/GPU)
///
/// # Example
///
/// ```no_run
/// # fn main() -> anyhow::Result<()> {
/// use rust_bert::pipelines::common::ModelType;
/// use rust_bert::pipelines::translation::TranslationConfig;
/// use rust_bert::resources::{LocalResource, Resource};
/// use std::path::PathBuf;
/// use tch::Device;
///
/// let config_resource = Resource::Local(LocalResource {
///     local_path: PathBuf::from("path/to/config.json"),
/// });
/// let model_resource = Resource::Local(LocalResource {
///     local_path: PathBuf::from("path/to/model.ot"),
/// });
/// let vocab_resource = Resource::Local(LocalResource {
///     local_path: PathBuf::from("path/to/vocab.json"),
/// });
/// let sentence_piece_resource = Resource::Local(LocalResource {
///     local_path: PathBuf::from("path/to/spiece.model"),
/// });
///
/// let translation_config = TranslationConfig::new_from_resources(
///     model_resource,
///     config_resource,
///     vocab_resource,
///     sentence_piece_resource,
///     Some(">>fr<<".to_string()),
///     Device::cuda_if_available(),
///     ModelType::Marian,
/// );
/// # Ok(())
/// # }
/// ```
Create a new `TranslationConfiguration` from custom  resources.
Create a new ` TranslationConfiguration ` from custom resources .
pub fn new_from_resources(
        model_resource: Resource,
        config_resource: Resource,
        vocab_resource: Resource,
        sentence_piece_resource: Resource,
        prefix: Option<String>,
        device: Device,
        model_type: ModelType,
    ) -> TranslationConfig {
        TranslationConfig {
            model_resource,
            config_resource,
            vocab_resource,
            merges_resource: sentence_piece_resource,
            min_length: 0,
            max_length: 512,
            do_sample: false,
            early_stopping: false,
            num_beams: 6,
            temperature: 1.0,
            top_k: 50,
            top_p: 1.0,
            repetition_penalty: 1.0,
            length_penalty: 1.0,
            no_repeat_ngram_size: 0,
            num_return_sequences: 1,
            device,
            prefix,
            model_type,
        }
    }
pub fn new_from_resources ( model_resource : Resource , config_resource : Resource , vocab_resource : Resource , sentence_piece_resource : Resource , prefix : Option < String > , device : Device , model_type : ModelType , ) -> TranslationConfig { TranslationConfig { model_resource , config_resource , vocab_resource , merges_resource : sentence_piece_resource , min_length : 0 , max_length : 512 , do_sample : false , early_stopping : false , num_beams : 6 , temperature : 1.0 , top_k : 50 , top_p : 1.0 , repetition_penalty : 1.0 , length_penalty : 1.0 , no_repeat_ngram_size : 0 , num_return_sequences : 1 , device , prefix , model_type , } }
Create a new `TranslationConfiguration` from custom (e.g.
Create a new ` TranslationConfiguration ` from custom ( e . g .
model_resource
Resource
config_resource
Resource
vocab_resource
Resource
sentence_piece_resource
Resource
prefix
Option<String>
device
Device
model_type
ModelType
model_resource
Resource
config_resource
Resource
vocab_resource
Resource
sentence_piece_resource
Resource
prefix
Option<String>
device
Device
model_type
ModelType
example
None
fn main() -> anyhow::result<()> {
use rust_bert::pipelines::common::ModelType;
use rust_bert::pipelines::translation::TranslationConfig;
use rust_bert::resources::{LocalResource, Resource};
use std::path::PathBuf;
use tch::Device.

let config_resource = Resource::Local(LocalResource {
local_path: PathBuf::from("path/to/config.json"),
});
let model_resource = Resource::Local(LocalResource {
local_path: PathBuf::from("path/to/model.ot"),
});
let vocab_resource = Resource::Local(LocalResource {
local_path: PathBuf::from("path/to/vocab.json"),
});
let sentence_piece_resource = Resource::Local(LocalResource {
local_path: PathBuf::from("path/to/spiece.model"),
}).

let translation_config = TranslationConfig::new_from_resources(
model_resource,
config_resource,
vocab_resource,
sentence_piece_resource,
Some(">>fr<<".to_string()),
Device::cuda_if_available(),
ModelType::Marian,
).
use rust_bert :: pipelines :: common :: ModelType ; use rust_bert :: pipelines :: translation :: TranslationConfig ; use rust_bert :: resources :: { LocalResource Resource } ; use std :: path :: PathBuf ; use tch :: Device . let config_resource = Resource :: Local ( LocalResource { local_path : PathBuf :: from ( " path / to / config . json " ) } ) ; let model_resource = Resource :: Local ( LocalResource { local_path : PathBuf :: from ( " path / to / model . ot " ) } ) ; let vocab_resource = Resource :: Local ( LocalResource { local_path : PathBuf :: from ( " path / to / vocab . json " ) } ) ; let sentence_piece_resource = Resource :: Local ( LocalResource { local_path : PathBuf :: from ( " path / to / spiece . model " ) } ) . let translation_config = TranslationConfig :: new_from_resources ( model_resource config_resource vocab_resource sentence_piece_resource Some ( " >> fr<< " . to_string () ) Device :: cuda_if_available () ModelType :: Marian ) .
ok(())
None
}
None