pub struct KeywordExtractionModel<'a> {
pub sentence_embeddings_model: SentenceEmbeddingsModel,
pub tokenizer: StopWordsTokenizer<'a>,
/* private fields */
}
Expand description
KeywordExtractionModel to extract keywords from input texts
It contains a sentence embeddings model to compute word-document similarities, a tokenizer to define a keyword candidates list and a scorer to rank these keywords.
sentence_embeddings_model
: Sentence embeddings modeltokenizer
: tokenizer used to generate the list of candidates (differs from the transformer tokenizer)
Fields§
§sentence_embeddings_model: SentenceEmbeddingsModel
§tokenizer: StopWordsTokenizer<'a>
Implementations§
source§impl<'a> KeywordExtractionModel<'a>
impl<'a> KeywordExtractionModel<'a>
sourcepub fn new(
config: KeywordExtractionConfig<'a>
) -> Result<KeywordExtractionModel<'a>, RustBertError>
pub fn new( config: KeywordExtractionConfig<'a> ) -> Result<KeywordExtractionModel<'a>, RustBertError>
Build a new KeywordExtractionModel
Arguments
config
-KeywordExtractionConfig
object containing a sentence embeddings configuration and tokenizer-specific options
Example
use rust_bert::pipelines::keywords_extraction::KeywordExtractionModel;
let keyword_extraction_model = KeywordExtractionModel::new(Default::default())?;
sourcepub fn get_tokenizer(&self) -> &TokenizerOption
pub fn get_tokenizer(&self) -> &TokenizerOption
Get a reference to the model tokenizer.
sourcepub fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
pub fn get_tokenizer_mut(&mut self) -> &mut TokenizerOption
Get a mutable reference to the model tokenizer.
sourcepub fn predict<S>(
&self,
inputs: &[S]
) -> Result<Vec<Vec<Keyword>>, RustBertError>
pub fn predict<S>( &self, inputs: &[S] ) -> Result<Vec<Vec<Keyword>>, RustBertError>
Extract keywords from a list of input texts.
Arguments
inputs
- slice of string-like input texts to extract keywords from
Returns
Result<Vec<Vec<Keyword>>, RustBertError>
containing a list of keyword for each input text
Example
use rust_bert::pipelines::keywords_extraction::KeywordExtractionModel;
let keyword_extraction_model = KeywordExtractionModel::new(Default::default())?;
let input = [
"This is a first sentence to extract keywords from.",
"Some keywords will be extracted from this text too.",
];
let output = keyword_extraction_model.predict(&input);
Auto Trait Implementations§
impl<'a> RefUnwindSafe for KeywordExtractionModel<'a>
impl<'a> Send for KeywordExtractionModel<'a>
impl<'a> !Sync for KeywordExtractionModel<'a>
impl<'a> Unpin for KeywordExtractionModel<'a>
impl<'a> UnwindSafe for KeywordExtractionModel<'a>
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