Skip to main content

Generata - Generate Data

A Python package for Artificial Error Generation!

work-in-progress

About

Approach:

Data Description:

Abstracts and Titles are extracted from PubMed. NLTK Sentence Tokenizer (PunktSentenceTokenizer) is used to create sentences. Some post-processing is done on top of sentence tokenization.

No. of samples: 100,000 No. of sentences from abstracts: ~89,000 No. of titles: ~11,000

Model Analysis Dataset: The Corpus of Linguistic Acceptability (CoLA) in its full form consists of 10657 sentences from 23 linguistics publications, expertly annotated for acceptability (grammaticality) by their original authors. The public version provided here contains 9594 sentences belonging to training and development sets, and excludes 1063 sentences belonging to a held out test set. Contact alexwarstadt [at] gmail [dot] com with any questions or issues. Read the paper or check out the source code for baselines.

Paper

Read the paper at https://arxiv.org/abs/1805.12471

https://nyu-mll.github.io/CoLA/

Dependencies:

  • Python (3.8+)

Install nlpaeg on your system using:

pip install nlpaeg

Usage:

Importing the library:

import nlpaeg
from nlpaeg import error_generator as eg

Instantiate the class:

g = eg.ErrorGenerator()

Initialize the parameters:

params = {

       }

Set config params

# instantiate the class
g = eg.ErrorGenerator()

# data directory
data_dir = os.path.join(os.getcwd(), "data")

# filename sentences without errors
train_data = "nlpaeg_pubmed_data_min.csv"
train_data_file_path = os.path.join(data_dir, train_data)

# read as dataframe
#df = pd.read_csv(train_data_file_path, sep="\t", header=None)
#df.columns = ["source", "valid", "note", "sentence"]

# set source data
g.source_data = pd.read_csv(train_data_file_path)

# set sentence column name
# default: sentences
g.sentence_column = "sentences"

# define n-gram order
# 4 => quadgrams, trigrams, bigrams and unigrams
# 3 => trigrams, bigrams and unigrams
# 2 => bigrams and unigrams
# default is 3; max is 5
g.ngram_order = 4

# name of columns -> predefined
# max upto 5 -grams
g.ngram_cols = {
1: "unigrams", 2: "bigrams", 3: "trigrams", 
4: "quadgrams", 5: "pentgrams"
}

# total samples
g.total_samples = len(g.source_data)

# selecting a proportion of most common n-grams
# if there are 1000 sentences and 2000 unigrams
# then we select only 30% of total unigrams
# how many ngrams to consider
# using most frequent ones
# total unigrams -> 2000; take top 600
g.n_ngrams = {
1: int(g.total_samples * 0.3),
2: int(g.total_samples * 0.2),
3: int(g.total_samples * 0.15),
4: int(g.total_samples * 0.1),
5: int(g.total_samples * 0.05),
}


# define proportion of ngram matches to modify
# for example, if there were 10 sentences in total
# changes to unigrams -> 10
# changes to bigrams -> 7
# changes to trigrams -> 3
# we'll need to use all three trigrams, most of bigrams
# and half of unigrams
# for sampling ngram changes
g.ngram_weights = {
0: 1,    # 100% of no grams
1: 0.4, # 40% of unigram changes
2: 0.6, # 60% of bigram changes
3: 0.8, # 80% of trigram changes
4: 0.95, # 95% of quadgram changes
5: 1    # 100% of pentgram changes
}



# probability distribution of artificial errors
# keys -> type of errors
# values -> distribution %
g.error_distribution = {
"dictionary_replacement_verb_form_change": 0.1,
"dictionary_replacement_word_order_change": 0.1,
"verb_form_change_order_change": 0.1,
"insert_determiner": 0.1,
"punctuation_braces": 0.05,
"punctuations": 0.05,
"duplication": 0.1,
"split_words": 0.1,
"remove_words": 0.05,


}






Create your dataframe:


# call the method to create error data
aeg_df = g.get_aeg_data()

aeg_df.to_csv('sampled_replacements_1.csv', index=None)

Metadata

Release files for nlpaeg 0.1.1

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

Source distribution (sdist)

Source distribution for nlpaeg 0.1.1
File Size Uploaded Provenance Actions
nlpaeg-0.1.1.tar.gz 9.5 kB Without provenance Details for nlpaeg-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 6.2 MB

Release files / nlpaeg-0.1.1.tar.gz

Download URL nlpaeg-0.1.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
73067df4131608b0d5cd7a19b00e1aedf5f2cddf942928cc3f1bd39b4c998f1a
BLAKE2b-256 checksum
How to use checksums
b4887b8ce274eb29b18d3d54799c44db992c5bf23aea27e30c808d90f80cf7e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Release files / nlpaeg-0.1.1-py3-none-any.whl

Download URL nlpaeg-0.1.1-py3-none-any.whl
Size 6.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0fab4076d7a1d0d567d188c605db3394baba8c46ccbacc1e743cb42f0c1f62c4
BLAKE2b-256 checksum
How to use checksums
a87b2d820424f9225f682c1c3ffe4158021b2eff46bb3c26abc053842d9a4b19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

Security for nlpaeg 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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