pub struct TextGenerationModel { /* private fields */ }
Expand description
§TextGenerationModel to generate texts from a prompt
Implementations§
Source§impl TextGenerationModel
impl TextGenerationModel
Sourcepub fn new(
generation_config: TextGenerationConfig,
) -> Result<TextGenerationModel, RustBertError>
pub fn new( generation_config: TextGenerationConfig, ) -> Result<TextGenerationModel, RustBertError>
Build a new TextGenerationModel
§Arguments
generation_config
-GenerateConfig
object containing the resource references (model, vocabulary, configuration), generation options and device placement (CPU/GPU)
§Example
use rust_bert::pipelines::common::ModelType;
use rust_bert::pipelines::text_generation::TextGenerationModel;
let generation_model = TextGenerationModel::new(Default::default())?;
Sourcepub fn new_with_tokenizer(
generation_config: TextGenerationConfig,
tokenizer: TokenizerOption,
) -> Result<TextGenerationModel, RustBertError>
pub fn new_with_tokenizer( generation_config: TextGenerationConfig, tokenizer: TokenizerOption, ) -> Result<TextGenerationModel, RustBertError>
Build a new TextGenerationModel
with a given tokenizer
§Arguments
generation_config
-GenerateConfig
object containing the resource references (model, vocabulary, configuration), generation options and device placement (CPU/GPU)tokenizer
-TokenizerOption
tokenizer to use for text generation
§Example
use rust_bert::pipelines::common::{ModelType, TokenizerOption};
use rust_bert::pipelines::text_generation::TextGenerationModel;
let tokenizer = TokenizerOption::from_file(
ModelType::GPT2,
"path/to/vocab.json",
Some("path/to/merges.txt"),
false,
None,
None,
)?;
let generation_model = TextGenerationModel::new_with_tokenizer(Default::default(), tokenizer)?;
pub fn get_tokenizer(&self) -> &TokenizerOption
pub fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
pub fn half(&mut self) -> Result<(), RustBertError>
pub fn float(&mut self) -> Result<(), RustBertError>
pub fn set_device(&mut self, device: Device) -> Result<(), RustBertError>
Sourcepub fn generate<'a, S>(
&self,
texts: &[S],
prefix: impl Into<Option<&'a str>>,
) -> Result<Vec<String>, RustBertError>
pub fn generate<'a, S>( &self, texts: &[S], prefix: impl Into<Option<&'a str>>, ) -> Result<Vec<String>, RustBertError>
Generate texts from provided prompts
§Arguments
input
-&[&str]
Array of texts to summarize.prefix
-impl Into<Option<&'a str>>
: Optional string to pass as a prefix for generation. Will be excluded from generated sequences.
§Returns
Vec<String>
Generated texts
§Example
use rust_bert::pipelines::common::ModelType;
use rust_bert::pipelines::text_generation::TextGenerationModel;
let model = TextGenerationModel::new(Default::default())?;
let input = ["The dog", "The cat was"];
let prefix = None;
let output = model.generate(&input, prefix);
Auto Trait Implementations§
impl !Freeze for TextGenerationModel
impl !RefUnwindSafe for TextGenerationModel
impl Send for TextGenerationModel
impl !Sync for TextGenerationModel
impl Unpin for TextGenerationModel
impl !UnwindSafe for TextGenerationModel
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