Skip to main content

Perturber models for neural data augmentation.

Project description

Perturbers

This codebase is built upon the great work of Qian et. al. (2022). Using this library, you can easily integrate neural augmentation models with your NLP pipelines or train new perturber models from scratch.

Installation

perturbers is available on PyPI and can be installed using pip:

pip install perturbers

Usage

Using a perturber is as simple as creating a new instance of the Perturber class and calling the generate method with the sentence you want to perturb along with the target word and the attribute you want to change:

from perturbers import Perturber

perturber = Perturber()
unperturbed = "Jack was passionate about rock climbing and his love for the sport was infectious to all men around him."
perturber.generate(unperturbed, "Jack", "female")
# "Jane was passionate about rock climbing and her love for the sport was infectious to all men around her."

You can also perturb a sentence without specifying a target word or attribute:

perturber("Jack was passionate.", retry_unchanged=True)
# "Jackie was passionate."

Training a new perturber model

To train a new perturber model, take a look at the train_perturber.py script. This script will train a new perturber model using the PANDA dataset. Currently the scripts only support training BART models, but any encoder-decoder model can be used.

Perturber models are evaluated based on the following metrics:

  • bleu4: The 4-gram BLEU score of the perturbed sentence compared to the original sentence
  • perplexity: The perplexity of the perturbed sentence
  • perplexity_perturbed: The perplexity of only the perturbed tokens from the perturbed sentence

Pre-trained models

In addition to the codebase, we also provide pre-trained perturber models in a variety of sizes:

Base model Parameters Perplexity Perplexity (perturbed idx)* BLEU4
perturber-small bart-small 70M 1.076 4.079 0.822
perturber-base bart-base 139M 1.058 2.769 0.794
perturber (original) bart-large 406M 1.06** N/A 0.88**

*Measures perplexity only of perturbed tokens, as the majority of tokens remains unchanged leading to Perplexity scores approaching 1

**The perplexity and BLEU4 scores are those reported in the original paper and not measured via this codebase.

Roadmap

  • Add default perturber model
  • Pretrain small and medium perturber models
  • Train model to identify target words and attributes
  • Add training of unconditional perturber models (i.e. only get a sentence, no target word/attribute)
  • Add self-training by pretraining perturber base model (e.g. BART) on self-perturbed data

Other features could include

  • Data cleaning of PANDA (remove non-target perturbations)
  • Multilingual perturbation

Read more

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perturbers-0.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perturbers-0.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file perturbers-0.0.0.tar.gz.

File metadata

  • Download URL: perturbers-0.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for perturbers-0.0.0.tar.gz
Algorithm Hash digest
SHA256 341e7c87ba0fa5fa6e35ebef0c222170434ad143a25832dd1c6b550ee97190ac
MD5 d6d298f530d4cf50b80119212fd1cd6f
BLAKE2b-256 097049c36063b33038b7d99ce3e9306c238b577834bf137e76252ed5c369d47a

See more details on using hashes here.

File details

Details for the file perturbers-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: perturbers-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for perturbers-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6e885ac92b815dfada7f16f5a3d4ba2c17fd97162b51f4d814c492d17e93642
MD5 5c5b0c73ea8d61988fe6ba858e4ae947
BLAKE2b-256 53ec0127f608be1de78d451d35f6584c4e06f21b02339f1667bee6d577f89d56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page