pub struct BartGenerator { /* private fields */ }
Expand description
§Language generation model based on the Bart architecture
Implementations§
Source§impl BartGenerator
impl BartGenerator
Sourcepub fn new(
generate_config: GenerateConfig,
) -> Result<BartGenerator, RustBertError>
pub fn new( generate_config: GenerateConfig, ) -> Result<BartGenerator, RustBertError>
Build a new BartGenerator
§Arguments
vocab_path
- Path to the model vocabulary, expected to have a structure following the Transformers library conventionmerges_path
- Path to the bpe merges, expected to have a structure following the Transformers library conventionconfig_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.bin
to.ot
format using the utility script provided.device
- Device to run the model on, e.g.Device::Cpu
orDevice::Cuda(0)
§Example
use rust_bert::bart::BartGenerator;
use rust_bert::pipelines::generation_utils::GenerateConfig;
let device = Device::cuda_if_available();
let generate_config = GenerateConfig {
max_length: Some(30),
do_sample: true,
num_beams: 5,
temperature: 1.1,
num_return_sequences: 3,
..Default::default()
};
let bart_generator = BartGenerator::new(generate_config)?;
pub fn new_with_tokenizer( generate_config: GenerateConfig, tokenizer: TokenizerOption, ) -> Result<BartGenerator, RustBertError>
Trait Implementations§
Source§impl LanguageGenerator for BartGenerator
impl LanguageGenerator for BartGenerator
Source§fn generate<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>,
) -> Result<Vec<GeneratedTextOutput>, RustBertError>
fn generate<S>( &self, prompt_texts: Option<&[S]>, generate_options: Option<GenerateOptions<'_>>, ) -> Result<Vec<GeneratedTextOutput>, RustBertError>
Generate text based on a vector of promp texts. Read more
Source§fn generate_indices<S>(
&self,
prompt_texts: Option<&[S]>,
generate_options: Option<GenerateOptions<'_>>,
) -> Result<Vec<GeneratedIndicesOutput>, RustBertError>
fn generate_indices<S>( &self, prompt_texts: Option<&[S]>, generate_options: Option<GenerateOptions<'_>>, ) -> Result<Vec<GeneratedIndicesOutput>, RustBertError>
Generate token indices without decoding (useful for token-level operations before returning final text or as validation step during training). Read more
Source§fn generate_from_ids_and_past(
&self,
input_ids: Tensor,
attention_mask: Option<Tensor>,
generate_options: Option<GenerateOptions<'_>>,
) -> Result<Vec<GeneratedIndicesOutput>, RustBertError>
fn generate_from_ids_and_past( &self, input_ids: Tensor, attention_mask: Option<Tensor>, generate_options: Option<GenerateOptions<'_>>, ) -> Result<Vec<GeneratedIndicesOutput>, RustBertError>
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
Source§fn get_tokenizer(&self) -> &TokenizerOption
fn get_tokenizer(&self) -> &TokenizerOption
Returns a reference to the text generator’s tokenizer Read more
fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
fn half(&mut self) -> Result<(), RustBertError>
fn float(&mut self) -> Result<(), RustBertError>
fn set_device(&mut self, device: Device) -> Result<(), RustBertError>
Auto Trait Implementations§
impl !Freeze for BartGenerator
impl !RefUnwindSafe for BartGenerator
impl Send for BartGenerator
impl !Sync for BartGenerator
impl Unpin for BartGenerator
impl !UnwindSafe for BartGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more