makcedward/nlpaug

Data augmentation for NLP

What it solves

Training machine learning models often needs large amounts of data, but collecting and labeling that data is time-consuming and expensive. This library creates synthetic variations of existing data — text, audio, and spectrograms — so you can expand your training set without manual work. By adding realistic noise, substitutions, or transformations, it helps models become more robust and perform better on unseen inputs.

How it works

The core building block is an Augmenter, a component that applies a specific type of transformation to your data. For text, augmenters can substitute words with synonyms or antonyms, insert new words using language models like BERT or GPT-2, simulate keyboard or OCR errors, or apply random deletions and swaps. For audio, augmenters can change pitch, speed, volume, add noise, or mask sections. Spectrogram augmenters mask blocks along time or frequency dimensions.

You can also combine multiple augmenters into a Flow, which is a pipeline that applies them sequentially or randomly. The library is designed to be lightweight and easy to use — you can augment data in a few lines of code and plug it into common machine learning frameworks.

Who it's for

This tool is for machine learning practitioners and researchers who work with natural language processing (NLP), speech recognition, or audio analysis and want to increase the size and diversity of their datasets quickly. It's also useful for anyone who wants to test model robustness against common text or audio corruptions. Since it supports Python 3.12+, it fits modern development environments, and optional extras allow integration with transformers, NLTK, word embeddings, and audio libraries.

Highlights

  • Supports three data types: text, audio, and spectrogram.
  • Over 25 built-in augmenters covering character, word, sentence, and signal modifications.
  • Includes advanced methods based on pre-trained language models (BERT, RoBERTa, XLNet, GPT-2) and word embeddings (word2vec, GloVe, fastText).
  • Provides a Flow pipeline to chain multiple augmenters sequentially or randomly.
  • Installation via pip with optional extras for specific dependencies, and offline-first tests that don't require downloading models for the default suite.

Related

  • Project
  • Project
  • Project
  • Project
  • Project