Abstract
Data augmentation is a cornerstone of robust machine learning in computer vision and speech recognition, yet its application in Natural Language Processing (NLP) has been hindered by the complexity of maintaining linguistic annotations. This paper introduces Augmenty, a Python library built on the spaCy framework designed for "structured" text augmentation. Unlike traditional string-based methods, Augmenty ensures that modifications to text—such as synonym replacement or character-level perturbations—remain perfectly aligned with underlying annotations like Named Entity Recognition (NER) tags and dependency parses. By treating text as a structured object, Augmenty enables more reliable training and sophisticated robustness evaluation for a wide range of NLP tasks.
Introduction
While data augmentation is a standard practice for expanding datasets and improving model generalization, its implementation in NLP has historically been limited to "pure string" manipulation. For example, replacing a name in a sentence to test for gender bias often breaks the character offsets required for NER or shifts the indices for Part-of-Speech (POS) tagging. This misalignment forces researchers to either stick to simple text classification tasks or develop complex, brittle scripts to manually update annotations.
Augmenty addresses this gap by integrating directly with the spaCy ecosystem, providing a pipeline-based approach to generating robust training data. It moves beyond simple string swapping to a framework where text and its metadata are inseparable, allowing for augmentation that is both linguistically informed and computationally efficient.
Methodology: Structured Augmentation
The core innovation of Augmenty lies in its use of the spaCy Doc object. In standard NLP workflows, a Doc object contains not just the raw text, but a wealth of metadata including token boundaries, tags, and entities.
The Doc-to-Doc Approach
Instead of taking a string and returning a string, Augmenty's augmenters take a Doc object as input and return a modified Doc object. This ensures that if a word is inserted, deleted, or substituted, the library automatically recalculates the offsets for all existing annotations. This "structured" approach allows researchers to apply augmentations to complex tasks like dependency parsing or span-based entity recognition without losing data integrity.
Multi-Level Augmenters and Pipelines
Augmenty provides a hierarchical suite of augmenters:
- Token-level: Primitives for word replacement, deletion, or character-level noise (e.g., simulating keyboard typos based on specific layouts).
- Span-level: Targeted modifications for specific entities or phrases.
- Sentence-level: Operations that affect the structure of the entire sentence.
Following spaCy’s design philosophy, Augmenty allows users to chain these augmenters into a single pipeline. Users can specify the probability of each transformation, providing fine-grained control over the diversity of the generated data.
Extensibility and Integration
The library is designed to be highly extensible. It includes primitives that allow for the easy creation of custom augmenters and integrates with external resources such as NLTK for WordNet-based synonym replacement and GloVe static word vectors for similarity-based substitutions. This flexibility makes it a versatile tool for both general-purpose augmentation and domain-specific challenges.
Applications and Evaluation
Augmenty is not only a tool for expanding training sets but also a powerful framework for model evaluation. By systematically perturbing text, researchers can identify specific model vulnerabilities.
- Robustness Testing: The library has been used to evaluate the DaCy pipeline (a state-of-the-art Danish NLP model), testing how well it handles typos and spelling variations.
- Bias Detection: Researchers have utilized Augmenty to detect intersectional biases in Danish NER systems by swapping names and demographic indicators while keeping the rest of the sentence structure intact.
- Synthetic Historical Data: The tool can generate datasets that mimic historical spelling variations, aiding in the development of models for low-resource or non-standard linguistic data.
Discussion and Limitations
Augmenty provides a functional solution to the limitations of previous tools like textgenie or textaugment by prioritizing annotation alignment. Its primary strength is its seamless integration into existing spaCy workflows, which removes the "pre-processing tax" typically associated with data augmentation.
However, the library's effectiveness is inherently tied to the spaCy ecosystem. Researchers using other frameworks, such as raw Hugging Face Transformers, must adapt their data into spaCy formats to utilize Augmenty. Furthermore, while the library handles the structural alignment of annotations, the semantic validity of the resulting text—ensuring a sentence still makes sense after a transformation—remains dependent on the quality of the specific augmenter and the external linguistic resources used.
Conclusion
Augmenty represents a significant step forward for structured NLP augmentation. By treating annotations as first-class citizens, it enables researchers to move beyond simple classification and apply robust augmentation techniques to the full spectrum of structured prediction tasks. As NLP continues to move toward more nuanced evaluation and bias mitigation, tools like Augmenty will be essential for building models that are not just accurate, but truly robust.
Summary updated