Struct rust_bert::pipelines::text_generation::TextGenerationModel
source · pub struct TextGenerationModel { /* private fields */ }Expand description
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-GenerateConfigobject containing the resource references (model, vocabulary, configuration), generation options and device placement (CPU/GPU)model_type-ModelTypeenum variant indicating the type of model to use for generation
Example
use rust_bert::pipelines::common::ModelType;
use rust_bert::pipelines::text_generation::TextGenerationModel;
let generation_model = TextGenerationModel::new(Default::default())?;pub fn half(&mut self)
pub fn float(&mut self)
pub fn set_device(&mut self, device: Device)
sourcepub fn generate<'a, S>(
&self,
texts: &[S],
prefix: impl Into<Option<&'a str>>
) -> Vec<String> ⓘwhere
S: AsRef<str> + Sync,
pub fn generate<'a, S>(
&self,
texts: &[S],
prefix: impl Into<Option<&'a str>>
) -> Vec<String> ⓘwhere
S: AsRef<str> + Sync,
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);