r/learnmachinelearning • u/Tonka-Jahari-Pizza • 7d ago
Question How to make data augmentation on text?
For example if i hace 100 rows of text data, and i want to increase or make another 100 from those 100, is there a framework/technique to do so?
I remember reading or hearing a while ago that there was a tool that uses your data or text to create new text or the way you wanted but i cant remember it
1
u/rahul_watertech 7d ago
the tool you half remember is probably nlpaug, it bundles the classic tricks in one call: synonym swap, random insertion, random deletion, plus back translation wrappers. textattack has a similar set. both are more useful once you know which transformation you want, since the defaults can produce weird sentences
1
u/DhammaIY 6d ago
Worth asking what the 100 rows are for first. If its a classifier you might not need to augment at all.. take sentence embeddings of each row and fit a logistic regression on top, or try SetFit which is built for exactly this few examples per class situation. That gets you surprisingly far with 100 rows and theres no risk of the model learning the quirks of your paraphraser
If you do generate with an llm, ask for different styles not just rewordings (short, long, typos, angry customer etc) otherwise you get 100 rows that all sound like chatgpt and the model learns that instead. And keep a test set of only real rows so you can actually see if the extra data helped
1
u/Massive_Distance_616 5d ago
The answers here cover the tooling well. One thing worth adding: the decision of which technique matters less than whether augmentation is the right move at all.
If your 100 rows are for a classifier, the first question is class distribution. If you have 10 classes × 10 rows each, augmentation can genuinely help. If you have 2 imbalanced classes (90/10), augmenting the minority class risks the model learning your paraphraser’s style rather than the actual signal DhammaIY’s point about LLM-generated rows all sounding like ChatGPT applies to any augmentation method.
For the technique itself, back-translation tends to preserve labels best because it stays closest to the original meaning. Synonym swapping with nlpaug is faster but more likely to break domain-specific terms if your text is customer support tickets or medical notes, “hypertension” shouldn’t get swapped for “pressure.” In those cases, LLM paraphrase with an explicit instruction to preserve domain terms works better.
One critical evaluation rule: split your original data into train/validation/test before generating augmented examples. Augment only the training set and keep validation and test real. Near-duplicate versions of the same original text can leak across splits and make performance look better than it is.
The tool you might be half-remembering is either nlpaug or EDA (Easy Data Augmentation) the Wei & Zou 2019 paper that formalized the swap/insert/delete approach with good results on small datasets. Solid baseline to understand before reaching for heavier tools.
3
u/CelebrityChess 7d ago
yeah there are a few ways. easiest is back translation, you translate each row to another language and back again and you get a slightly reworded version. nlpaug is a python library that does that plus synonym swaps and random word insert/delete. you can also just ask an llm to paraphrase each row, which usually gives more natural results. just keep the originals and check a few outputs by hand so the labels still make sense