### Initialize KeyboardAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/char/keyboard.html Instantiate the KeyboardAug augmenter. No specific setup is required beyond importing the library. ```python import nlpaug.augmenter.char as nac aug = nac.KeyboardAug() ``` -------------------------------- ### Example Usage of ShiftAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/shift.html Demonstrates how to create and use the ShiftAug augmenter with a specified sampling rate. ```python import nlpaug.augmenter.audio as naa aug = naa.ShiftAug(sampling_rate=44010) ``` -------------------------------- ### Initialize Sequential Flow Source: https://nlpaug.readthedocs.io/en/latest/flow/sequential.html Instantiate a Sequential flow by providing a list of augmenters. This example shows combining character and word augmenters. ```python import nlpaug.flow as naf import nlpaug.augmenter.char as nac import nlpaug.augmenter.word as naw flow = naf.Sequential([nac.RandomCharAug(), naw.RandomWordAug()]) ``` -------------------------------- ### Initialize NoiseAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/noise.html Initialize the NoiseAug augmenter. This is the basic setup for applying noise injection to audio data. ```python import nlpaug.augmenter.audio as naa aug = naa.NoiseAug() ``` -------------------------------- ### Initialize ReservedAug with default parameters Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/reserved.html Instantiate the ReservedAug augmenter. This example shows basic usage without specifying custom parameters. ```python import nlpaug.augmenter.word as naw aug = naw.ReservedAug(reserved_tokens=[["FWD", "Fwd", "FW"], ["Sincerely", "Best Regards"]]) ``` -------------------------------- ### WordEmbsAug Initialization Example Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/word_embs.html Demonstrates how to initialize the WordEmbsAug augmenter for text augmentation using word embeddings. Specify the model type and path to your pre-trained model. ```python import nlpaug.augmenter.word as naw aug = naw.WordEmbsAug(model_type='word2vec', model_path='.') ``` -------------------------------- ### Initialize AbstSummAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/sentence/abst_summ.html Initialize the augmenter with default or custom model paths. Ensure transformers library is installed for model loading. ```python import nlpaug.augmenter.sentence as nas aug = nas.AbstSummAug() ``` -------------------------------- ### Initialize SpeedAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/speed.html Instantiate the SpeedAug augmenter. Configure parameters like zone, coverage, and speed factor. The 'zone' parameter defines the portion of audio to be augmented, 'coverage' specifies the proportion of the zone to augment, and 'factor' determines the speed adjustment range. ```python import nlpaug.augmenter.audio as naa # Initialize SpeedAug augmenter with default parameters aug = naa.SpeedAug() # Initialize SpeedAug augmenter with custom parameters # zone: Augment audio between 20% and 80% of its duration # coverage: Augment 70% of the specified zone # factor: Speed can be increased or decreased within the range of 0.5 to 2.0 aug_custom = naa.SpeedAug(zone=(0.2, 0.8), coverage=0.7, factor=(0.5, 2.0)) ``` -------------------------------- ### Initialize VtlpAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/vtlp.html Instantiate the VtlpAug augmenter with custom parameters for sampling rate, augmentation zone, coverage, frequency boundary, and factor. This is useful for fine-tuning the VTLP effect on audio data. ```python from nlpaug.augmenter.audio import VtlpAug aug = VtlpAug(sampling_rate=16000, zone=(0.2, 0.8), coverage=0.1, factor=(0.9, 1.1)) ``` -------------------------------- ### RandomCharAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/char/random.html Augmenter that generate character error by random values. For example, people may type i as o incorrectly. ```APIDOC ## RandomCharAug ### Description Augmenter that generate character error by random values. For example, people may type i as o incorrectly. ### Parameters * **action** (str) - Possible values are 'insert', 'substitute', 'swap' and 'delete'. If value is 'insert', a new character will be injected to randomly. If value is 'substitute', a random character will be replaced original character randomly. If value is 'swap', adjacent characters within sample word will be swapped randomly. If value is 'delete', character will be removed randomly. * **aug_char_p** (float) - Percentage of character (per token) will be augmented. * **aug_char_min** (int) - Minimum number of character will be augmented. * **aug_char_max** (int) - Maximum number of character will be augmented. If None is passed, number of augmentation is calculated via aup_char_p. If calculated result from aug_char_p is smaller than aug_char_max, will use calculated result from aup_char_p. Otherwise, using aug_max. * **aug_word_p** (float) - Percentage of word will be augmented. * **aug_word_min** (int) - Minimum number of word will be augmented. * **aug_word_max** (int) - Maximum number of word will be augmented. If None is passed, number of augmentation is calculated via aup_word_p. If calculated result from aug_word_p is smaller than aug_word_max, will use calculated result from aug_word_p. Otherwise, using aug_max. * **include_upper_case** (bool) - If True, upper case character may be included in augmented data. If `candidates' value is provided, this param will be ignored. * **include_lower_case** (bool) - If True, lower case character may be included in augmented data. If `candidates' value is provided, this param will be ignored. * **include_numeric** (bool) - If True, numeric character may be included in augmented data. If `candidates' value is provided, this param will be ignored. * **min_char** (int) - If word less than this value, do not draw word for augmentation * **swap_mode** (str) - When action is 'swap', you may pass 'adjacent', 'middle' or 'random'. 'adjacent' means swap action only consider adjacent character (within same word). 'middle' means swap action consider adjacent character but not the first and last character of word. 'random' means swap action will be executed without constraint. * **spec_char** (str) - Special character may be included in augmented data. If `candidates' value is provided, this param will be ignored. * **stopwords** (list) - List of words which will be skipped from augment operation. * **stopwords_regex** (str) - Regular expression for matching words which will be skipped from augment operation. * **tokenizer** (func) - Customize tokenization process * **reverse_tokenizer** (func) - Customize reverse of tokenization process * **candidates** (List) - List of string for augmentation. E.g. ['AAA', '11', '===']. If values is provided, `include_upper_case`, `include_lower_case`, `include_numeric` and `spec_char` will be ignored. * **name** (str) - Name of this augmenter. ### Example ```python import nlpaug.augmenter.char as nac aug = nac.RandomCharAug() ``` ``` -------------------------------- ### Initialize SpeedAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/speed.html Instantiate the SpeedAug augmenter with customizable parameters like zone, coverage, and speed factor. The `zone` parameter defines the portion of the audio to be augmented, `coverage` specifies the percentage of the zone to augment, and `factor` determines the range of speed adjustments. ```python import nlpaug.augmenter.audio as naa # Example usage with default parameters aug = naa.SpeedAug() # Example usage with custom parameters # aug = naa.SpeedAug(zone=(0.1, 0.9), coverage=0.8, factor=(0.8, 1.2)) ``` -------------------------------- ### Initialize AntonymAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/antonym.html Instantiate the AntonymAug augmenter. This class substitutes words with their antonyms. It requires no specific setup beyond instantiation. ```python import nlpaug.augmenter.word as naw aug = naw.AntonymAug() ``` -------------------------------- ### Import DownloadUtil Source: https://nlpaug.readthedocs.io/en/latest/util/download.html Import the DownloadUtil class from the nlpaug.util.file.download module. ```python from nlpaug.util.file.download import DownloadUtil ``` -------------------------------- ### Initialize AbstSummAug with custom model and parameters Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/sentence/abst_summ.html Configure the AbstSummAug augmenter with a specific model path, tokenizer path, and fine-tune generation parameters such as min_length, max_length, temperature, top_k, and top_p for customized summarization output. ```python import nlpaug.augmenter.sentence as nas aug = nas.AbstSummAug( model_path='facebook/bart-large-cnn', tokenizer_path='facebook/bart-large-cnn', min_length=30, max_length=100, temperature=0.7, top_k=40, top_p=0.8, device='cuda' ) ``` -------------------------------- ### Initialize PitchAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/pitch.html Instantiate the PitchAug augmenter with a specified sampling rate. Ensure the sampling rate matches your audio data. ```python import nlpaug.augmenter.audio as naa aug = naa.PitchAug(sampling_rate=44010) ``` -------------------------------- ### TF-IDF Augmenter Initialization with Parameters Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/tfidf.html Demonstrates initializing the TfIdfAug augmenter with various parameters to control augmentation. This includes setting the action, augmentation probability, minimum and maximum words to augment, and the top_k value for selecting candidate words. ```python import nlpaug.augmenter.word as naw from nlpaug.util import Action aug = naw.TfIdfAug(model_path='.', action=Action.SUBSTITUTE, name='TfIdf_Aug', aug_min=1, aug_max=10, aug_p=0.3, top_k=5, stopwords=None, tokenizer=None, reverse_tokenizer=None, stopwords_regex=None, verbose=0) ``` -------------------------------- ### Initialize NoiseAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/noise.html Instantiate the NoiseAug augmenter with default or custom parameters. This is the primary way to set up noise injection for audio data. ```python import nlpaug.augmenter.audio as naa aug = naa.NoiseAug() ``` -------------------------------- ### Initialize OCR Augmenter with Default Model Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/char/ocr.html Loads the default OCR model for English characters to initialize the augmenter. This is useful for quick setup when no custom model is needed. ```python default_path = os.path.join(LibraryUtil.get_res_dir(), 'char', 'ocr', 'en.json') model = ReadUtil.read_json(default_path) return nmc.Ocr(model=model) ``` -------------------------------- ### TF-IDF Model Initialization Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/tfidf.html This method provides a way to get or initialize the TF-IDF model. It allows for forcing a reload of the model if needed, ensuring that the latest model is used for augmentation. ```python def get_model(self, force_reload=False): return init_tfidf_model(self.model_path, force_reload) ``` -------------------------------- ### KeyboardAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/char/keyboard.html Augmenter that simulate typo error by random values. For example, people may type i as o incorrectly. One keyboard distance is leveraged to replace character by possible keyboard error. ```APIDOC ## KeyboardAug ### Description Augmenter that simulate typo error by random values. For example, people may type i as o incorrectly. One keyboard distance is leveraged to replace character by possible keyboard error. ### Parameters * **aug_char_p** (float) - Percentage of character (per token) will be augmented. * **aug_char_min** (int) - Minimum number of character will be augmented. * **aug_char_max** (int) - Maximum number of character will be augmented. If None is passed, number of augmentation is calculated via aup_char_p. If calculated result from aug_char_p is smaller than aug_char_max, will use calculated result from aug_char_p. Otherwise, using aug_max. * **aug_word_p** (float) - Percentage of word will be augmented. * **aug_word_min** (int) - Minimum number of word will be augmented. * **aug_word_max** (int) - Maximum number of word will be augmented. If None is passed, number of augmentation is calculated via aup_word_p. If calculated result from aug_word_p is smaller than aug_word_max, will use calculated result from aug_word_p. Otherwise, using aug_max. * **stopwords** (list) - List of words which will be skipped from augment operation. * **stopwords_regex** (str) - Regular expression for matching words which will be skipped from augment operation. * **tokenizer** (func) - Customize tokenization process * **reverse_tokenizer** (func) - Customize reverse of tokenization process * **include_special_char** (bool) - Include special character * **include_upper_case** (bool) - If True, upper case character may be included in augmented data. * **include_numeric** (bool) - If True, numeric character may be included in augmented data. * **min_char** (int) - If word less than this value, do not draw word for augmentation * **model_path** (str) - Loading customize model from file system * **lang** (str) - Indicate built-in language model. Default value is 'en'. Possible values are 'en', 'th' (Thai), 'tr'(Turkish), 'de'(German), 'es'(Spanish), 'fr'(French), 'it'(Italian), 'nl'(Dutch), 'pl'(Polish), 'uk'(Ukrainian), 'he'(Hebrew). If custom model is used (passing model_path), this value will be ignored. * **name** (str) - Name of this augmenter ### Example ```python import nlpaug.augmenter.char as nac aug = nac.KeyboardAug() ``` ``` -------------------------------- ### Apply VTLP Augmentation Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/vtlp.html Demonstrates how to apply VTLP augmentation to audio data using the VtlpAug augmenter. The `substitute` method handles the augmentation process, determining the augmentation range and warp factor. ```python import nlpaug.augmenter.audio as naa # Assuming 'audio_data' is a numpy array representing audio # and 'sampling_rate' is the audio's sampling rate aug = naa.VtlpAug(sampling_rate=sampling_rate) data = aug.augment(audio_data) ``` -------------------------------- ### Frequency Masking Augmentation Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/spectrogram/frequency_masking.html Applies frequency masking to spectrogram data. The augmentation masks 'f' consecutive mel frequency channels starting from 'f0'. The range of 'f' and 'f0' are determined by the augmenter's configuration and the input data's dimensions. The augmentation is applied within a specified time range determined by coverage. ```python import numpy as np from nlpaug.augmenter.spectrogram import SpectrogramAugmenter from nlpaug.util import Action, Logger import nlpaug.model.spectrogram as nms class FrequencyMaskingAug(SpectrogramAugmenter): def __init__(self, name='FrequencyMasking_Aug', zone=(0.2, 0.8), coverage=1., factor=(40, 80), verbose=0, silence=False, stateless=True): super().__init__(action=Action.SUBSTITUTE, zone=zone, coverage=coverage, factor=factor, verbose=verbose, name=name, silence=silence, stateless=stateless) if self.factor[0] < 0 and not self.silence: Logger.log().warning('Lower bound of factor is less than {}.'.format(0) + ' It should be non-negative value. Will use 0 as lower bound.') self.model = nms.FrequencyMasking() def substitute(self, data): v = data.shape[0] if v < self.factor[1] and not self.silence: Logger.log().warning('Upper bound of factor is larger than {}.'.format(v) + ' It should be smaller than number of frequency. Will use {} as upper bound'.format(v)) upper_bound = self.factor[1] if v > self.factor[1] else v f = self.get_random_factor(high=upper_bound, dtype='int') f0 = np.random.randint(v - f) time_start, time_end = self.get_augment_range_by_coverage(data) if not self.stateless: self.v, self.f, self.f0, self.time_start, self.time_end = v, f, f0, time_start, time_end return self.model.manipulate(data, f=f, f0=f0, time_start=time_start, time_end=time_end) ``` -------------------------------- ### AbstSummAug Initialization Source: https://nlpaug.readthedocs.io/en/latest/augmenter/sentence/abst_summ.html Initialize the AbstSummAug augmenter with various parameters to control the summarization model and augmentation process. ```APIDOC ## AbstSummAug Initialization ### Description Initializes the abstractive summarization augmenter. ### Parameters * **model_path** (str) - Model name or model path. Tested ‘facebook/bart-large-cnn’, t5-small’, ‘t5-base’ and ‘t5-large’. * **tokenizer_path** (str) - Tokenizer name or tokenizer path. * **min_length** (int) - The min length of output text. * **max_length** (int) - The max length of output text. * **batch_size** (int) - Batch size. * **temperature** (float) - The value used to module the next token probabilities. * **top_k** (int) - The number of highest probability vocabulary tokens to keep for top-k-filtering. * **top_p** (float) - If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation. * **name** (str) - Name of this augmenter. * **device** (str) - Default value is CPU. Possible values include ‘cuda’ and ‘cpu’. * **force_reload** (bool) - Force reload the contextual word embeddings model to memory when initialize the class. * **verbose** (int) - Verbosity level. * **use_custom_api** (bool) - Whether to use custom API. ### Request Example ```python import nlpaug.augmenter.sentence as nas aug = nas.AbstSummAug() ``` ``` -------------------------------- ### KeyboardAug Initialization Source: https://nlpaug.readthedocs.io/en/latest/augmenter/char/keyboard.html Initialize the KeyboardAug augmenter with default parameters. ```APIDOC ## KeyboardAug Initialization ### Description Initialize the KeyboardAug augmenter with default parameters. ### Method ```python KeyboardAug( name='Keyboard_Aug', aug_char_min=1, aug_char_max=10, aug_char_p=0.3, aug_word_p=0.3, aug_word_min=1, aug_word_max=10, stopwords=None, tokenizer=None, reverse_tokenizer=None, include_special_char=True, include_numeric=True, include_upper_case=True, lang='en', verbose=0, stopwords_regex=None, model_path=None, min_char=4 ) ``` ### Parameters * **aug_char_p** (float) - Percentage of character (per token) will be augmented. * **aug_char_min** (int) - Minimum number of character will be augmented. * **aug_char_max** (int) - Maximum number of character will be augmented. If None is passed, number of augmentation is calculated via aup_char_p. If calculated result from aug_char_p is smaller than aug_char_max, will use calculated result from aug_char_p. Otherwise, using aug_max. * **aug_word_p** (float) - Percentage of word will be augmented. * **aug_word_min** (int) - Minimum number of word will be augmented. * **aug_word_max** (int) - Maximum number of word will be augmented. If None is passed, number of augmentation is calculated via aup_word_p. If calculated result from aug_word_p is smaller than aug_word_max, will use calculated result from aug_word_p. Otherwise, using aug_max. * **stopwords** (list) - List of words which will be skipped from augment operation. * **stopwords_regex** (str) - Regular expression for matching words which will be skipped from augment operation. * **tokenizer** (func) - Customize tokenization process * **reverse_tokenizer** (func) - Customize reverse of tokenization process * **include_special_char** (bool) - Include special character * **include_upper_case** (bool) - If True, upper case character may be included in augmented data. * **include_numeric** (bool) - If True, numeric character may be included in augmented data. * **min_char** (int) - If word less than this value, do not draw word for augmentation * **model_path** (str) - Loading customize model from file system * **lang** (str) - Indicate built-in language model. Default value is ‘en’. Possible values are ‘en’, ‘th’ (Thai), ‘tr’(Turkish), ‘de’(German), ‘es’(Spanish), ‘fr’(French), ‘it’(Italian), ‘nl’(Dutch), ‘pl’(Polish), ‘uk’(Ukrainian), ‘he’(Hebrew). If custom model is used (passing model_path), this value will be ignored. * **name** (str) - Name of this augmenter ### Request Example ```python import nlpaug.augmenter.char as nac aug = nac.KeyboardAug() ``` ``` -------------------------------- ### Initialize ContextualWordEmbsForSentenceAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/sentence/context_word_embs_sentence.html Instantiate the augmenter with default or custom model parameters. Specify model path, type, and device for loading the language model. Control generation parameters like temperature, top_k, and top_p. ```python import nlpaug.augmenter.sentence as nas aug = nas.ContextualWordEmbsForSentenceAug() ``` -------------------------------- ### PitchAug Initialization Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/pitch.html Initializes the PitchAug augmenter. Configure parameters like sampling rate, augmentation zone, coverage, duration, and pitch factor. The augmenter is stateless by default. ```python from nlpaug.augmenter.audio import AudioAugmenter import nlpaug.model.audio as nma from nlpaug.util import Action, WarningMessage class PitchAug(AudioAugmenter): """ :param int sampling_rate: Sampling rate of input audio. :param tuple zone: Assign a zone for augmentation. Default value is (0.2, 0.8) which means that no any augmentation will be applied in first 20% and last 20% of whole audio. :param float coverage: Portion of augmentation. Value should be between 0 and 1. If `1` is assigned, augment operation will be applied to target audio segment. For example, the audio duration is 60 seconds while zone and coverage are (0.2, 0.8) and 0.7 respectively. 42 seconds ((0.8-0.2)*0.7*60) audio will be augmented. :param int duration: Duration of augmentation (in second). Default value is None. If value is provided. `coverage` value will be ignored. :param tuple factor: Input data pitch will be increased (decreased). Augmented value will be picked within the range of this tuple value. Pitch will be reduced if value is between 0 and 1. :param str name: Name of this augmenter >>> import nlpaug.augmenter.audio as naa >>> aug = naa.PitchAug(sampling_rate=44010) """ def __init__(self, sampling_rate, zone=(0.2, 0.8), coverage=1., duration=None, factor=(-10, 10), name='Pitch_Aug', verbose=0, stateless=True): super().__init__(action=Action.SUBSTITUTE, zone=zone, coverage=coverage, factor=factor, duration=duration, name=name, device='cpu', verbose=verbose, stateless=stateless) self.sampling_rate = sampling_rate self.model = nma.Pitch() def substitute(self, data): pitch_level = self.get_random_factor() start_pos, end_pos = self.get_augment_range_by_coverage(data) if not self.stateless: self.start_pos, self.end_pos, self.aug_factor = start_pos, end_pos, pitch_level return self.model.manipulate(data, start_pos, end_pos, pitch_level, self.sampling_rate) ``` -------------------------------- ### Initialize AbstSummAug with default settings Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/sentence/abst_summ.html Instantiate the AbstSummAug augmenter using default model ('t5-base') and generation parameters. This is suitable for general use cases where default summarization behavior is desired. ```python import nlpaug.augmenter.sentence as nas aug = nas.AbstSummAug() ``` -------------------------------- ### Initialize ShiftAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/shift.html Instantiate the ShiftAug augmenter for audio shifting. Requires sampling rate and optionally accepts duration and direction. ```python from nlpaug.augmenter.audio import AudioAugmenter import nlpaug.model.audio as nma from nlpaug.util import Action, WarningMessage class ShiftAug(AudioAugmenter): def __init__(self, sampling_rate, duration=3, direction='random', shift_direction='random', name='Shift_Aug', verbose=0, stateless=True): super().__init__(action=Action.SUBSTITUTE, name=name, duration=duration, device='cpu', verbose=verbose, stateless=stateless) self.sampling_rate = sampling_rate self.direction = direction self.shift_direction = shift_direction self.model = nma.Shift() self.model.validate(shift_direction) def _get_aug_shift(self): aug_shift = int(self.sampling_rate * self.duration) if self.direction == 'right': return -aug_shift elif self.direction == 'random': direction = self.sample(4)-1 if direction == 1: return -aug_shift return aug_shift def substitute(self, data): aug_shift = self._get_aug_shift() if not self.stateless: self.aug_factor = aug_shift return self.model.manipulate(data, aug_shift) ``` -------------------------------- ### Initialize LoudnessAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/loudness.html Initialize the LoudnessAug augmenter. Default values are used for zone and coverage. ```python import nlpaug.augmenter.audio as naa aug = naa.LoudnessAug() ``` -------------------------------- ### Initialize AntonymAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/word/antonym.html Instantiate the AntonymAug augmenter. Default language is English. Customize parameters like augmentation probability and maximum augmentation count as needed. ```python import nlpaug.augmenter.word as naw aug = naw.AntonymAug() ``` -------------------------------- ### Initialize SpellingAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/spelling.html Instantiate the SpellingAug augmenter. Specify the path to the spelling dictionary and optionally control augmentation probability and quantity. The augmenter uses a default dictionary if none is provided. ```python import nlpaug.augmenter.word as naw aug = naw.SpellingAug(dict_path='./spelling_en.txt') ``` -------------------------------- ### Initialize CropAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/crop.html Instantiate the CropAug augmenter with a specified sampling rate. This augmenter is used for applying cropping operations to audio. ```python import nlpaug.augmenter.audio as naa aug = naa.CropAug(sampling_rate=44010) ``` -------------------------------- ### Initialize Contextual Word Embeddings Sentence Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/sentence/context_word_embs_sentence.html Demonstrates how to initialize the Contextual Word Embeddings Sentence Augmenter with various parameters. This is useful for setting up the augmentation pipeline. ```python from nlpaug.augmenter.sentence import ContextWordEmbsSentence # Example using GPT-2 aug = ContextWordEmbsSentence(model_path='gpt2', action="insert") data = 'This is a sample sentence.' augmented_data = aug.augment(data) print(augmented_data) # Example using XLNet aug = ContextWordEmbsSentence(model_path='xlnet-base-cased', action="insert") data = 'This is a sample sentence.' augmented_data = aug.augment(data) print(augmented_data) ``` -------------------------------- ### Initialize FrequencyMaskingAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/spectrogram/frequency_masking.html Initialize the augmenter. Default values are provided for zone, coverage, and factor. Ensure nlpaug.augmenter.spectogram is imported as nas. ```python import nlpaug.augmenter.spectogram as nas aug = nas.FrequencyMaskingAug() ``` -------------------------------- ### Initialize Abstractive Summarization Model Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/sentence/abst_summ.html Initializes the abstractive summarization model with specified parameters. Configure model path, tokenizer path, device, and various generation parameters like min/max length, batch size, and sampling strategies (temperature, top_k, top_p). ```python return init_abst_summ_model(model_path, tokenizer_path, device, force_reload, min_length, max_length, batch_size, temperature, top_k, top_p, use_custom_api) ``` -------------------------------- ### Initialize KeyboardAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/char/keyboard.html Instantiate KeyboardAug to simulate typo errors. Configure augmentation probability, character/word limits, and character set inclusions. ```python import nlpaug.augmenter.char as nac aug = nac.KeyboardAug() ``` -------------------------------- ### SpeedAug Class Initialization Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/speed.html Initializes the SpeedAug augmenter with specified parameters for audio speed adjustment. ```APIDOC ## SpeedAug ### Description Augmenter that apply speed adjustment operation to audio. ### Parameters * **zone** (tuple) - Assign a zone for augmentation. Default value is (0.2, 0.8) which means that no any augmentation will be applied in first 20% and last 20% of whole audio. * **coverage** (float) - Portion of augmentation. Value should be between 0 and 1. If 1 is assigned, augment operation will be applied to target audio segment. For example, the audio duration is 60 seconds while zone and coverage are (0.2, 0.8) and 0.7 respectively. 42 seconds ((0.8-0.2)*0.7*60) audio will be augmented. * **factor** (tuple) - Input data speed will be increased (decreased). Augmented value will be picked within the range of this tuple value. Speed will be reduced if value is between 0 and 1. * **speed_range** (tuple) - Deprecated. Use factor indeed * **name** (str) - Name of this augmenter * **verbose** (int) - Verbosity level. Default is 0. * **stateless** (bool) - Whether the augmenter is stateless. Default is True. ### Example ```python import nlpaug.augmenter.audio as naa # Initialize augmenter aug = naa.SpeedAug(zone=(0.2, 0.8), coverage=0.7, factor=(0.5, 2.0)) ``` ``` -------------------------------- ### Initialize Word Embedding Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/word_embs.html Demonstrates how to initialize a word augmenter using pre-trained word embeddings. Specify the model path, type, and whether to force a reload. Optional parameters like top_k and skip_check can also be configured. ```python from nlpaug.augmenter.word import WordEmbsAug # Example using GloVe aug = WordEmbsAug( model_type='glove', model_path='glove.6B.100d.txt', action="substitute" ) ``` -------------------------------- ### Download GloVe Model Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/util/file/download.html Downloads a specified GloVe pre-trained model from Stanford's repository and unzips it. Ensure the model name is one of the supported options. ```python DownloadUtil.download_glove('glove.6B', '.') ``` -------------------------------- ### Initialize LoudnessAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/loudness.html Instantiate the LoudnessAug augmenter with custom parameters for zone, coverage, and factor. This augmenter adjusts the volume of audio segments. ```python import nlpaug.augmenter.audio as naa aug = naa.LoudnessAug() ``` -------------------------------- ### Download Word2Vec Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/util/file/download.html Downloads the Word2Vec C binary file ('GoogleNews-vectors-negative300.bin.gz') from Google Drive and unzips it. ```APIDOC ## DownloadUtil.download_word2vec ### Description Downloads the Word2Vec C binary file and unzips it. ### Method `staticmethod` ### Parameters * **dest_dir** (str) - Optional - Directory of saving file. Defaults to ".". ### Example ```python from nlpaug.util.file.download import DownloadUtil DownloadUtil.download_word2vec('.') ``` ``` -------------------------------- ### Synonym Model Initialization Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/synonym.html This class method provides a way to initialize synonym models, supporting both 'wordnet' and 'ppdb' sources. Ensure the correct `aug_src` is specified for your needs. Use `force_reload=True` to re-download model data if necessary. ```python @classmethod def get_model(cls, aug_src, lang, dict_path, force_reload): if aug_src == 'wordnet': return nmw.WordNet(lang=lang, is_synonym=True) elif aug_src == 'ppdb': return init_ppdb_model(dict_path=dict_path, force_reload=force_reload) raise ValueError('aug_src is not one of `wordnet` or `ppdb` while {} is passed.'.format(aug_src)) ``` -------------------------------- ### Initialize MaskAug Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/audio/mask.html Instantiate the MaskAug augmenter. Requires sampling_rate to be specified. Other parameters control the zone, coverage, duration, and whether to mask with noise. ```python import nlpaug.augmenter.audio as naa aug = naa.MaskAug(sampling_rate=44010) ``` -------------------------------- ### Initialize SplitAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/split.html Instantiate the SplitAug augmenter with custom parameters. This augmenter splits words into smaller parts. ```python import nlpaug.augmenter.word as naw aug = naw.SplitAug() ``` -------------------------------- ### Initialize TimeMaskingAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/spectrogram/time_masking.html Initialize the TimeMaskingAug augmenter. Default zone is (0.2, 0.8) and coverage is 1.0. Ensure nlpaug.augmenter.spectogram is imported as nas. ```python import nlpaug.augmenter.spectogram as nas aug = nas.TimeMaskingAug() ``` -------------------------------- ### SplitAug Initialization Source: https://nlpaug.readthedocs.io/en/latest/augmenter/word/split.html Initializes the SplitAug augmenter with customizable parameters. ```APIDOC ## SplitAug Initialization ### Description Initializes the SplitAug augmenter with customizable parameters. ### Parameters - **name** (str) - Name of this augmenter. Default is 'Split_Aug'. - **aug_p** (float) - Percentage of word will be augmented. Default is 0.3. - **aug_min** (int) - Minimum number of word will be augmented. Default is 1. - **aug_max** (int) - Maximum number of word will be augmented. If None is passed, number of augmentation is calculated via aup_p. If calculated result from aug_p is smaller than aug_max, will use calculated result from aug_p. Otherwise, using aug_max. - **min_char** (int) - If word less than this value, do not draw word for augmentation. Default is 4. - **stopwords** (list) - List of words which will be skipped from augment operation. - **stopwords_regex** (str) - Regular expression for matching words which will be skipped from augment operation. - **tokenizer** (func) - Customize tokenization process. - **reverse_tokenizer** (func) - Customize reverse of tokenization process. - **verbose** (int) - Verbosity level. Default is 0. ### Request Example ```python import nlpaug.augmenter.word as naw aug = naw.SplitAug() ``` ``` -------------------------------- ### Initialize SplitAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/word/split.html Instantiate the SplitAug augmenter with default parameters. This augmenter is used for applying word splitting to text. ```python import nlpaug.augmenter.word as naw aug = naw.SplitAug() ``` -------------------------------- ### Initialize RandomSentAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/sentence/random.html Initialize the augmenter with default settings. The mode parameter controls how sentences are shuffled (left, right, neighbor, or random). ```python import nlpaug.augmenter.sentence as nas aug = nas.RandomSentAug() ``` -------------------------------- ### VtlpAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/audio/vtlp.html Initialize the VtlpAug augmenter with specified parameters. ```APIDOC ## VtlpAug ### Description Initializes the VtlpAug augmenter for applying Vocal Tract Length Perturbation (VTLP) to audio data. ### Parameters #### Constructor Parameters - **sampling_rate** (int) - The sampling rate of the audio. - **zone** (tuple) - Assign a zone for augmentation. Default value is (0.2, 0.8) which means that no any augmentation will be applied in first 20% and last 20% of whole audio. - **coverage** (float) - Portion of augmentation. Value should be between 0 and 1. If 1 is assigned, augment operation will be applied to target audio segment. For example, the audio duration is 60 seconds while zone and coverage are (0.2, 0.8) and 0.7 respectively. 42 seconds ((0.8-0.2)*0.7*60) audio will be augmented. - **fhi** (int) - Boundary frequency. Default value is 4800. - **factor** (tuple) - Input data vocal will be increased (decreased). Augmented value will be picked within the range of this tuple value. Vocal will be reduced if value is between 0 and 1. - **name** (str) - Name of this augmenter. Default is 'Vtlp_Aug'. - **verbose** (int) - Verbosity level. Default is 0. - **stateless** (bool) - Whether the augmenter is stateless. Default is True. ### Request Example ```python import nlpaug.augmenter.audio as naa aug = naa.VtlpAug(sampling_rate=16000, zone=(0.2, 0.8), coverage=0.7, factor=(0.9, 1.1)) ``` ``` -------------------------------- ### Initialize SpellingAug Source: https://nlpaug.readthedocs.io/en/latest/augmenter/word/spelling.html Initialize the SpellingAug augmenter with a dictionary path for spelling errors. Ensure the dictionary file exists. ```python import nlpaug.augmenter.word as naw aug = naw.SpellingAug(dict_path='./spelling_en.txt') ``` -------------------------------- ### Download Back Translation Checkpoints Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/util/file/download.html Downloads the back-translation checkpoints from Google Cloud Storage and unzips them to the specified directory. ```python DownloadUtil.download_back_translation(dest_dir) ``` -------------------------------- ### Initialize RandomWordAug Augmenter Source: https://nlpaug.readthedocs.io/en/latest/augmenter/word/random.html Instantiate the RandomWordAug augmenter. Default action is 'delete'. ```python import nlpaug.augmenter.word as naw aug = naw.RandomWordAug() ``` -------------------------------- ### Initialize TF-IDF Augmenter Source: https://nlpaug.readthedocs.io/en/latest/_modules/nlpaug/augmenter/word/tfidf.html Instantiate the TfIdfAug augmenter. Specify the model path and action (insert or substitute). Other parameters control the augmentation intensity and behavior. ```python import nlpaug.augmenter.word as naw aug = naw.TfIdfAug(model_path='.') ```