Abstract
Text augmentation—the process of generating new text samples by applying transformations to existing samples—is a vital tool for both training (Wei & Zou, 2019) and evaluating (Ribeiro et al., 2020) natural language processing (NLP) models. Despite its utility, existing libraries are often limited in functionality, typically catering to simple text classification or specific use cases like robustness estimation (Goel et al., 2021). We present Augmenty, a Python library designed for the structured augmentation of text and its associated metadata. By integrating with the spaCy ecosystem (Honnibal et al., 2020), Augmenty provides a wide range of augmenters that can be combined into complex pipelines while maintaining the integrity of linguistic annotations such as named entity recognition (NER) tags and dependency parses.
Introduction
In computer vision, data augmentation is a standard practice where simple geometric transformations preserve the underlying class label. In Natural Language Processing (NLP), however, the process is significantly more complex. Most existing tools perform "string-level" augmentation, which often breaks the alignment between text and its metadata. For example, if a sentence contains a person's name tagged with specific character offsets, replacing that name with a shorter or longer one invalidates those offsets. This "misalignment" problem has largely confined NLP augmentation to simple text classification tasks. Augmenty addresses this gap by providing a framework where text and its linguistic annotations are transformed in tandem, enabling augmentation for structured prediction tasks like NER, part-of-speech (POS) tagging, and coreference resolution.
Methodology
Augmenty is built to work natively with spaCy, leveraging its Doc object to manage text and annotations. Unlike raw strings, Doc objects store text alongside comprehensive linguistic annotations. By operating directly on these objects, Augmenty can update underlying data structures—such as entity spans and dependency trees—simultaneously during augmentation.
Augmentation Hierarchy
The library provides a granular set of tools categorized by the scope of the transformation:
- Token-level: Includes character-level noise, such as keyboard-specific typos (e.g., based on Danish or French AZERTY layouts), and word-level swaps.
- Span-level: Targets specific entities or phrases, allowing for the replacement of names or technical terms while preserving their labels.
- Sentence-level: Facilitates the manipulation of entire sentences within a document.
Integration and Customization
Augmenty supports external integrations, including NLTK for WordNet-based synonym replacement and static word vectors (e.g., GloVe) for finding semantically similar word replacements. Users can chain these augmenters into complex pipelines, setting specific probabilities for each transformation to generate highly diverse synthetic datasets. Furthermore, the library provides "primitives" that allow developers to build custom, domain-specific augmenters—such as "pseudo-historical" spelling variations—while the framework handles the synchronization of spaCy annotations.
Applications and Results
While Augmenty is a software-focused contribution, its utility has been demonstrated in several research projects:
- DaCy: A state-of-the-art Danish NLP pipeline used Augmenty to evaluate model robustness and identify performance degradation under noise.
- Bias Detection: Researchers used the library to detect intersectional biases in Danish NER systems by systematically swapping names associated with different demographic groups.
- ScandEval: Augmenty serves as a core component in this benchmark for Scandinavian natural language processing.
The library successfully maintains alignment for NER, POS tagging, and dependency parsing—tasks that were previously difficult to augment reliably. Its compatibility with any model or task supported by spaCy makes it a general-purpose tool for the NLP community.
Discussion and Limitations
A significant insight from this work is the dual role of augmentation: it is as much a diagnostic tool for evaluation as it is a method for data expansion. By perturbing text in a controlled, structured manner, researchers can uncover hidden biases or brittleness in their models.
However, Augmenty's primary strength—its integration with spaCy—is also a limitation, as it requires users to adopt spaCy's data structures. Additionally, while the library supports word vectors and WordNet, it does not yet deeply integrate Large Language Models (LLMs) for generative paraphrasing or back-translation, which represents a potential area for future development.
Conclusion
Augmenty provides a robust framework for structured text augmentation, filling a critical gap in the NLP ecosystem. By ensuring the integrity of linguistic annotations during transformation, it enables more sophisticated training and evaluation strategies for a wide range of NLP tasks.
Summary updated