Natural language processing augmentation library for deep neural networks
Project description
nlpaug
This python library helps you with augmenting nlp for your machine learning projects. Visit this introduction to understand about Data Augmentation in NLP. Augmenter
is the basic element of augmentation while Flow
is a pipeline to orchestra multi augmenter together.
Features
- Generate synthetic data for improving model performance without manual effort
- Simple, easy-to-use and lightweight library. Augment data in 3 lines of code
- Plug and play to any neural network frameworks (e.g. PyTorch, TensorFlow)
- Support textual and audio input
Textual Data Augmentation Example
Acoustic Data Augmentation Example
Section | Description |
---|---|
Quick Demo | How to use this library |
Augmenter | Introduce all available augmentation methods |
Installation | How to install this library |
Recent Changes | Latest enhancement |
Extension Reading | More real life examples or researchs |
Reference | Refernce of external resources such as data or model |
Quick Demo
- Example of Augmentation for Textual Inputs
- Example of Augmentation for Multilingual Textual Inputs
- Example of Augmentation for Spectrogram Inputs
- Example of Augmentation for Audio Inputs
- Example of Orchestra Multiple Augmenters
- Example of Showing Augmentation History
- How to train TF-IDF model
- How to create custom augmentation
- API Documentation
Augmenter
Augmenter | Target | Augmenter | Action | Description |
---|---|---|---|---|
Textual | Character | KeyboardAug | substitute | Simulate keyboard distance error |
Textual | OcrAug | substitute | Simulate OCR engine error | |
Textual | RandomAug | insert, substitute, swap, delete | Apply augmentation randomly | |
Textual | Word | AntonymAug | substitute | Substitute opposite meaning word according to WordNet antonym |
Textual | ContextualWordEmbsAug | insert, substitute | Feeding surroundings word to BERT, DistilBERT, RoBERTa or XLNet language model to find out the most suitlabe word for augmentation | |
Textual | RandomWordAug | swap, crop, delete | Apply augmentation randomly | |
Textual | SpellingAug | substitute | Substitute word according to spelling mistake dictionary | |
Textual | SplitAug | split | Split one word to two words randomly | |
Textual | SynonymAug | substitute | Substitute similar word according to WordNet/ PPDB synonym | |
Textual | TfIdfAug | insert, substitute | Use TF-IDF to find out how word should be augmented | |
Textual | WordEmbsAug | insert, substitute | Leverage word2vec, GloVe or fasttext embeddings to apply augmentation | |
Textual | BackTranslationAug | substitute | Leverage two translation models for augmentation | |
Textual | Sentence | ContextualWordEmbsForSentenceAug | insert | Insert sentence according to XLNet, GPT2 or DistilGPT2 prediction |
Signal | Audio | CropAug | delete | Delete audio's segment |
Signal | LoudnessAug | substitute | Adjust audio's volume | |
Signal | MaskAug | substitute | Mask audio's segment | |
Signal | NoiseAug | substitute | Inject noise | |
Signal | PitchAug | substitute | Adjust audio's pitch | |
Signal | ShiftAug | substitute | Shift time dimension forward/ backward | |
Signal | SpeedAug | substitute | Adjust audio's speed | |
Signal | VtlpAug | substitute | Change vocal tract | |
Signal | Spectrogram | FrequencyMaskingAug | substitute | Set block of values to zero according to frequency dimension |
Signal | TimeMaskingAug | substitute | Set block of values to zero according to time dimension |
Flow
Augmenter | Augmenter | Description |
---|---|---|
Pipeline | Sequential | Apply list of augmentation functions sequentially |
Pipeline | Sometimes | Apply some augmentation functions randomly |
Installation
The library supports python 3.5+ in linux and window platform.
To install the library:
pip install nlpaug numpy matplotlib python-dotenv
or install the latest version (include BETA features) from github directly
pip install git+https://github.com/makcedward/nlpaug.git numpy matplotlib python-dotenv
If you use ContextualWordEmbsAug or ContextualWordEmbsForSentenceAug, install the following dependencies as well
pip install torch>=1.6.0 transformers>=3.0.2
If you use BackTranslationAug, install the following dependencies as well
pip install torch>=1.6.0 fairseq>=0.9.0
If you use AntonymAug, SynonymAug, install the following dependencies as well
pip install nltk>=3.4.5
If you use WordEmbsAug (word2vec, glove or fasttext), downloading pre-trained model first
from nlpaug.util.file.download import DownloadUtil
DownloadUtil.download_word2vec(dest_dir='.') # Download word2vec model
DownloadUtil.download_glove(model_name='glove.6B', dest_dir='.') # Download GloVe model
DownloadUtil.download_fasttext(model_name='wiki-news-300d-1M', dest_dir='.') # Download fasttext model
If you use SynonymAug (PPDB), downloading file from the following URI. You may not able to run the augmenter if you get PPDB file from other website
http://paraphrase.org/#/download
If you use any one of audio augmenter, install the following dependencies as well
pip install librosa>=0.7.1
Recent Changes
**0.0.14dev Aug, 2020
- Support crop action in RandomWordAug #126
- Fix #130
- Fix #132
- Fix #134
- Upgraded and verified torch (1.6.0) and transformers (3.0.2) libraies
- Add new Back Translation Augmenter #75 #102 #131
See changelog for more details.
Extension Reading
- Data Augmentation library for Text
- Does your NLP model able to prevent adversarial attack?
- How does Data Noising Help to Improve your NLP Model?
- Data Augmentation library for Speech Recognition
- Data Augmentation library for Audio
- Unsupervied Data Augmentation
- A Visual Survey of Data Augmentation in NLP
Reference
This library uses data (e.g. capturing from internet), research (e.g. following augmenter idea), model (e.g. using pre-trained model) See data source for more details.
Citing
@misc{ma2019nlpaug,
title={NLP Augmentation},
author={Edward Ma},
howpublished={https://github.com/makcedward/nlpaug},
year={2019}
}
Contributions (Supporting Other Languages)
- sakares: Add Thai support to KeyboardAug
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 nlpaug-0.0.15.tar.gz
.
File metadata
- Download URL: nlpaug-0.0.15.tar.gz
- Upload date:
- Size: 78.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71e150811915d0b1caeb8cd74021d20168262ce38c6c72d99d9cd39d6b16ae6e |
|
MD5 | d07b4e8a47e8018cc410ff41f87b4cd0 |
|
BLAKE2b-256 | 7c9601ddc2743b96c5e53710d6b582a00baf53eefd125e62c475952f4481a85a |
File details
Details for the file nlpaug-0.0.15-py3-none-any.whl
.
File metadata
- Download URL: nlpaug-0.0.15-py3-none-any.whl
- Upload date:
- Size: 143.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d72f689ecdf58aa411ffaca468fbe78303012ace00a8d4b5bfc59cd7d69649c |
|
MD5 | af3c3eee44cb10b820a27e6f0b87fee7 |
|
BLAKE2b-256 | 29960ddde5f476df7db64344aa13f46693dbc6d7dcaeb4578a2f8efa5c6845ba |