Data augmentation techniques for text data using back translation and synonym replacement
Project description
Introduction
This package provides data augmentation techniques for text data using back translation and synonym replacement. Data augmentation is a technique to increase the size of the training data by generating new samples from the existing ones. This can be helpful in improving the performance of machine learning models by making them more robust and generalizable.
Installation
You can install the package using pip
:
pip install TextBooster
Usage
The package provides two functions for data augmentation: back_Translation() and synonym_Replacement().
Back Translation:
This function performs back translation of the given text to a randomly chosen target language and then back to the source language. This can be useful in generating new samples with different sentence structures and word choices.
This function performs back translation of the given text to a randomly chosen target language and then back to the source language. This can be useful in generating new samples with different sentence structures and word choices.
from TextBooster import back_Translation
text = "The quick brown fox jumps over the lazy dog."
augmented_texts = back_Translation(text, nbre_samples=3)
print(augmented_texts)
Output:
['The quick brown fox jumps over the indolent dog.',
'The quick brown fox jumped over the lazy dog.',
'The quick brown fox jumps over the torpid dog.']
Synonym Replacement:
This function replaces each word in the given text with one of its synonyms, chosen randomly. This can be useful in generating new samples with different word choices.
from TextBooster import synonym_Replacement
text = "The quick brown fox jumps over the lazy dog."
augmented_texts = synonym_Replacement(text)
print(augmented_texts)
Output:
'The speedy brown slyboots jump over the slothful frank.'
Note that the function returns a single augmented sample. To generate multiple samples, you can call the function multiple times or specify the number of samples to generate using the nbre_samples parameter:
from textaugment import synonym_Replacement
text = "The quick brown fox jumps over the lazy dog."
augmented_texts = synonym_Replacement(text, nbre_samples=3)
print(augmented_texts)
Output:
['The speedy brown fox jumps over the lazy dog.',
'The quick brown fox jumps over the indolent dog.',
'The quick brown fox jumps over the slothful dog.']
Dependencies:
The package has the following dependencies:
-
deep_translator
-
nltk
-
spacy
-
textblob
You can install them using pip
:
pip install deep_translator nltk spacy textblob
Additionally, you need to download the following data files for nltk
and spacy
:
nltk.download("wordnet")
nltk.download("punkt")
nltk.download("omw-1.4")
python -m spacy download en
License:
This package is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file TextBooster-0.3.tar.gz
.
File metadata
- Download URL: TextBooster-0.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8581d374bedb13e3f976d2f2c9c40d4c7692e965cb10d77310bc7c3c257d09c2 |
|
MD5 | 4381ada24a0de5d0a9b86053238f7ae1 |
|
BLAKE2b-256 | 8e97e7f8757275ae17f922cb6a2d12e29b722d3f3eff196be63441565a301cfc |
File details
Details for the file TextBooster-0.3-py3-none-any.whl
.
File metadata
- Download URL: TextBooster-0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d61fa055f5abde688ca239dc574167bceb61a48e3fb17e5bcf1ca595f3919981 |
|
MD5 | a90b8d07d3b4079856fe0cf45417e912 |
|
BLAKE2b-256 | 0f6a7cc6e0af344fd4886ce09a8ea075ae8fc1f3ea4661572464e7ab09386f9b |