pub struct WordsRandomSubstituteAugmenter { /* private fields */ }Expand description
Augmenter that substitutes random words with random words from vocabulary
§Examples
use fast_aug::base::BaseAugmenter;
use fast_aug::text::{WordsRandomSubstituteAugmenter, TextAugmentParameters};
let rng = &mut rand::thread_rng();
let augmenter = WordsRandomSubstituteAugmenter::new(
TextAugmentParameters::new(0.5, None, None),
vec!["A", "B", "C", "D", "E"].into_iter().map(|s| s.to_string()).collect(),
None,
);
augmenter.augment("Some text!".to_string(), rng);
augmenter.augment_batch(vec!["Some text!".to_string()], rng);Implementations§
Trait Implementations§
Source§impl BaseAugmenter<String, Doc> for WordsRandomSubstituteAugmenter
impl BaseAugmenter<String, Doc> for WordsRandomSubstituteAugmenter
Source§fn augment_inner(&self, input: Doc, rng: &mut dyn RngCore) -> Doc
fn augment_inner(&self, input: Doc, rng: &mut dyn RngCore) -> Doc
“Private” method to augment an input of inner type (K)
fn convert_to_inner(&self, input: String) -> Doc
fn convert_to_outer(&self, input: Doc) -> String
Source§fn augment(&self, input: T, rng: &mut dyn RngCore) -> T
fn augment(&self, input: T, rng: &mut dyn RngCore) -> T
Public method to augment an input Read more
fn augment_batch(&self, inputs: Vec<T>, rng: &mut dyn RngCore) -> Vec<T>
Source§impl BaseTextAugmenter for WordsRandomSubstituteAugmenter
impl BaseTextAugmenter for WordsRandomSubstituteAugmenter
Source§fn select_word_tokens_to_augment<'a>(
&self,
rng: &mut dyn RngCore,
candidate_tokens: &'a mut Vec<(usize, &'a mut Token)>,
num_elements: usize,
stopwords: Option<&HashSet<String>>,
) -> Vec<(usize, &'a mut Token)>
fn select_word_tokens_to_augment<'a>( &self, rng: &mut dyn RngCore, candidate_tokens: &'a mut Vec<(usize, &'a mut Token)>, num_elements: usize, stopwords: Option<&HashSet<String>>, ) -> Vec<(usize, &'a mut Token)>
Select random word tokens to augment given a number of elements
Returns a vector of tuples (index, &mut token)
TODO: optimize this function
Auto Trait Implementations§
impl Freeze for WordsRandomSubstituteAugmenter
impl RefUnwindSafe for WordsRandomSubstituteAugmenter
impl Send for WordsRandomSubstituteAugmenter
impl Sync for WordsRandomSubstituteAugmenter
impl Unpin for WordsRandomSubstituteAugmenter
impl UnwindSafe for WordsRandomSubstituteAugmenter
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