Struct rust_bert::marian::MarianGenerator
source · [−]pub struct MarianGenerator { /* private fields */ }Expand description
Implementations
sourceimpl MarianGenerator
impl MarianGenerator
sourcepub fn new(
generate_config: GenerateConfig
) -> Result<MarianGenerator, RustBertError>
pub fn new(
generate_config: GenerateConfig
) -> Result<MarianGenerator, RustBertError>
Build a new marianGenerator
Arguments
vocab_path- Path to the model vocabulary, expected to have a structure following the Transformers library conventionsentencepiece_model_path- Path to the sentencepiece model (native protobuf expected)config_path- Path to the model configuration, expected to have a structure following the Transformers library conventionweights_path- Path to the model weight files. These need to be converted form the.binto.otformat using the utility script provided.device- Device to run the model on, e.g.Device::CpuorDevice::Cuda(0)
Example
use rust_bert::marian::MarianGenerator;
use rust_bert::pipelines::generation_utils::GenerateConfig;
let device = Device::cuda_if_available();
let generate_config = GenerateConfig {
max_length: 512,
do_sample: true,
num_beams: 6,
temperature: 1.0,
num_return_sequences: 1,
..Default::default()
};
let marian_generator = MarianGenerator::new(generate_config)?;pub fn new_with_tokenizer(
generate_config: GenerateConfig,
tokenizer: TokenizerOption
) -> Result<MarianGenerator, RustBertError>
Trait Implementations
sourceimpl LanguageGenerator<MarianForConditionalGeneration, MarianVocab, MarianTokenizer> for MarianGenerator
impl LanguageGenerator<MarianForConditionalGeneration, MarianVocab, MarianTokenizer> for MarianGenerator
sourcefn generate<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedTextOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator, where
S: AsRef<str> + Sync,
fn generate<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedTextOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator, where
S: AsRef<str> + Sync,
A: Allocator,
Generate text based on a vector of promp texts. Read more
sourcefn generate_indices<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedIndicesOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator, where
S: AsRef<str> + Sync,
fn generate_indices<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedIndicesOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator, where
S: AsRef<str> + Sync,
A: Allocator,
Generate token indices without decoding (useful for token-level operations before returning final text or as validation step during training). Read more
sourcefn generate_from_ids_and_past(
&self,
input_ids: Tensor,
attention_mask: Option<Tensor>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedIndicesOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn generate_from_ids_and_past(
&self,
input_ids: Tensor,
attention_mask: Option<Tensor>,
generate_options: Option<GenerateOptions<'_>>
) -> Vec<GeneratedIndicesOutput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Generate token indices given a list of indices (useful when the input has been pre-tokenized). Returns a list of output tokens that need to be decoded using a tokenizer. Read more
sourcefn get_tokenizer(&self) -> &TokenizerOption
fn get_tokenizer(&self) -> &TokenizerOption
Returns a reference to the text generator’s tokenizer Read more
fn half(&mut self)
fn float(&mut self)
fn set_device(&mut self, device: Device)
Auto Trait Implementations
impl !RefUnwindSafe for MarianGenerator
impl Send for MarianGenerator
impl !Sync for MarianGenerator
impl Unpin for MarianGenerator
impl !UnwindSafe for MarianGenerator
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more