Skip to main content

Build Status Codacy Badge

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.

Starter Guides

Flow

Pipeline Description
Sequential Apply list of augmentation functions sequentially
Sometimes Apply some augmentation functions randomly

Textual Augmenter

Target Augmenter Action Description
Character RandomAug insert Insert character randomly
substitute Substitute character randomly
swap Swap character randomly
delete Delete character randomly
OcrAug substitute Simulate OCR engine error
KeyboardAug substitute Simulate keyboard distance error
Word RandomWordAug swap Swap word randomly
delete Delete word randomly
SpellingAug substitute Substitute word according to spelling mistake dictionary
WordNetAug substitute Substitute word according to WordNet's synonym
WordEmbsAug insert Insert word randomly from word2vec, GloVe or fasttext dictionary
substitute Substitute word based on word2vec, GloVe or fasttext embeddings
TfIdfAug insert Insert word randomly trained TF-IDF model
substitute Substitute word based on TF-IDF score
ContextualWordEmbsAug insert Insert word based by feeding surroundings word to BERT and XLNet language model
substitute Substitute word based by feeding surroundings word to BERT and XLNet language model
Sentence ContextualWordEmbsForSentenceAug insert Insert sentence according to GPT2 or XLNet prediction

Signal Augmenter

Target Augmenter Action Description
Audio NoiseAug substitute Inject noise
PitchAug substitute Adjust audio's pitch
ShiftAug substitute Shift time dimension forward/ backward
SpeedAug substitute Adjust audio's speed
CropAug delete Delete audio's segment
LoudnessAug substitute Adjust audio's volume
MaskAug substitute Mask audio's segment
Spectrogram FrequencyMaskingAug substitute Set block of values to zero according to frequency dimension
TimeMaskingAug substitute Set block of values to zero according to time dimension

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

If you use ContextualWordEmbsAug, install the following dependencies as well

pip install torch>=1.1.0 pytorch_pretrained_bert>=1.1.0

If you use WordNetAug, install the following dependencies as well

pip install nltk

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 any one of audio augmenter, install the following dependencies as well

pip install librosa

Recent Changes

0.0.8 Sep 4, 2019

  • BertAug is replaced by ContextualWordEmbsAug
  • Support GPU (for ContextualWordEmbsAug only) #26
  • Upgraded pytorch_transformer to 1.1.0 version #33
  • ContextualWordEmbsAug suuports both BERT and XLNet model
  • Removed librosa dependency
  • Add ContextualWordEmbsForSentenceAug for generating next sentence
  • Fix sampling issue #38

See changelog for more details.

Source

The library contains the usage of the following pre-trained model:

The library also captured data from internet for building augmenter/ test case. See data source for more details.

Research Reference

Some of the above augmenters are inspired by the following research papers. However, it does not always follow original implementation due to different reasons. If original implementation is needed, please refer to original source code.

Metadata

Release files for nlpaug 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nlpaug 0.0.8
File Size Uploaded
nlpaug-0.0.8.tar.gz 33.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nlpaug 0.0.8
File Interpreter ABI Platform
nlpaug-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 111.0 kB

Release files / nlpaug-0.0.8.tar.gz

Download URL nlpaug-0.0.8.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2c8b29d2d94096bd6f02193faaa7a56583a150daf45c34e711ca59a42fe49285
BLAKE2b-256 checksum
How to use checksums
fa89e5351b709d7e0f819519b9582bbabd6e5959c3f80a8ad80ace98ec144e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.4

Release files / nlpaug-0.0.8-py3-none-any.whl

Download URL nlpaug-0.0.8-py3-none-any.whl
Size 77.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
666f779f3114bcd306f455e22382b3490680667202192e93dc51e18ec76abcd5
BLAKE2b-256 checksum
How to use checksums
ab81d6447847b37315314e9f6fb592743d599a6479446cd481167b19d7000e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.4

Release history Release notifications | RSS feed

1.1.11

1 release file

1.1.10

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.0.20

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.9

2 release files

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page