WordsRandomSubstituteAugmenter

Struct WordsRandomSubstituteAugmenter 

Source
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§

Source§

impl WordsRandomSubstituteAugmenter

Source

pub fn new( word_params: TextAugmentParameters, vocabulary: Vec<String>, stopwords: Option<HashSet<String>>, ) -> Self

Trait Implementations§

Source§

impl BaseAugmenter<String, Doc> for WordsRandomSubstituteAugmenter

Source§

fn augment_inner(&self, input: Doc, rng: &mut dyn RngCore) -> Doc

“Private” method to augment an input of inner type (K)
Source§

fn convert_to_inner(&self, input: String) -> Doc

Source§

fn convert_to_outer(&self, input: Doc) -> String

Source§

fn augment(&self, input: T, rng: &mut dyn RngCore) -> T

Public method to augment an input Read more
Source§

fn augment_batch(&self, inputs: Vec<T>, rng: &mut dyn RngCore) -> Vec<T>

Source§

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)>

Select random word tokens to augment given a number of elements Returns a vector of tuples (index, &mut token) TODO: optimize this function
Source§

fn select_random_element_indexes( &self, rng: &mut dyn RngCore, element_indexes: Vec<usize>, num_elements: usize, ) -> Vec<usize>

Select random elements to augment. Returns a vector of indexes of elements to be augmented. Automatically shuffled. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T