pub struct CharsRandomSwapAugmenter { /* private fields */ }Expand description
Augmenter that swaps random chars in random words in text
§Examples
use fast_aug::base::BaseAugmenter;
use fast_aug::text::{CharsRandomSwapAugmenter, TextAugmentParameters};
let rng = &mut rand::thread_rng();
let augmenter = CharsRandomSwapAugmenter::new(
TextAugmentParameters::new(0.5, None, None),
TextAugmentParameters::new(0.5, None, None),
None,
);
augmenter.augment("Some text!".to_string(), rng);
augmenter.augment_batch(vec!["Some text!".to_string()], rng);Implementations§
Source§impl CharsRandomSwapAugmenter
impl CharsRandomSwapAugmenter
pub fn new( word_params: TextAugmentParameters, char_params: TextAugmentParameters, stopwords: Option<HashSet<String>>, ) -> Self
Trait Implementations§
Source§impl BaseAugmenter<String, Doc> for CharsRandomSwapAugmenter
impl BaseAugmenter<String, Doc> for CharsRandomSwapAugmenter
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 CharsRandomSwapAugmenter
impl BaseTextAugmenter for CharsRandomSwapAugmenter
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 CharsRandomSwapAugmenter
impl RefUnwindSafe for CharsRandomSwapAugmenter
impl Send for CharsRandomSwapAugmenter
impl Sync for CharsRandomSwapAugmenter
impl Unpin for CharsRandomSwapAugmenter
impl UnwindSafe for CharsRandomSwapAugmenter
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