Skip to main content

textnoisr: Adding random noise to a dataset

build-doc code-style nightly-test unit-test

textnoisr is a python package that allows to add random noise to a text dataset, and to control very accurately the quality of the result.

You can install it using pip:

pip install textnoisr

For a reproducible install with the exact dependency versions textnoisr was tested with, use the constraints.txt attached to each GitHub release:

pip install textnoisr==X.Y.Z -c https://github.com/preligens-lab/textnoisr/releases/download/vX.Y.Z/constraints.txt

To contribute, install uv and run uv sync, then e.g. uv run pytest.

Here is an example if your dataset consists on the first few lines of the Zen of python:

Raw text

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
...

Noisy text

TheO Zen of Python, by Tim Pfter

BzeautiUful is ebtter than ugly.
Eqxplicin is better than imlicit.
Simple is beateUr than comdplex.
Complex is better than comwlicated.
Flat is bejAter than neseed.
...

Four types of "actions" are implemented:

  • insert a random character, e.g. STEAM → STREAM,
  • delete a random character, e.g. STEAM → TEAM,
  • substitute a random character, e.g. STEAM → STEAL.
  • swap two consecutive characters, e.g. STEAM → STEMA

The general philosophy of the package is that only one single parameter is needed to control the noise level. This "noise level" is applied character-wise, and corresponds roughly to the probability for a character to be impacted.

More precisely, this noise level is calibrated so that the Character Error Rate of a noised dataset converges to this value as the amount of text increases.

Why a whole package for such a simple task?

In the case of inserting, deleting and substituting characters at random with a probability $p$, the Character Error Rate is only the average number of those operations, so it will converge to the input value $p$ due to the Law of Large Numbers.

However, the case of swapping consecutive characters is not trivial at all for two reasons:

  • First, swapping two characters is not an "atomic operation" with respect to the Character Error Rate metric.

  • Second, we do not want to swap repeatedly the same character over and over again if the probability to apply the swap action is high:
    STEAM → TSEAM
    TSEAM → TESAM
    TESAM → TEASM
    TEASM → TEAMS
    This would be equivalent to STEAM → TEAMS, so this cannot be considered "swapping consecutive characters". To avoid this behavior, we must avoid swapping a character if it has just been swapped. This breaks the independency between one character and the following one, and makes the Law of Large Numbers not applicable.

We use Markov Chains to model the swapping of characters. This allows us to compute and correct the corresponding bias in order to make itstraightforward for the user to get the desired Character Error Rate, as if the Law of Large Number could beapplied!

All the details of this unbiasing are here. The goal of this package is for the user to be confident on the result without worrying about the implementation details.


The documentation follows this plan:

  • You may want to follow a quick tutorial to learn the basics of the package,
  • The Results page illustrates how no calibration is needed in order to add noise to a corpus with a target Character Error Rate.
  • The How this works section explains the mechanisms, and some design choices of this package. We have been extra careful to explain how some statistical bias have been avoided, for the package to be both user-friendly and correct. A dedicated page deeps dive in the case of the swap action.
  • The API Reference details all the technical descriptions needed.

There is also a Medium article about this project.

Metadata

Release files for textnoisr 1.2.0

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

Source distribution (sdist)

Source distribution for textnoisr 1.2.0
File Size Uploaded Provenance Actions
textnoisr-1.2.0.tar.gz 9.8 kB With provenance Details for textnoisr-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 20.0 kB

Release files / textnoisr-1.2.0.tar.gz

Download URL textnoisr-1.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a9529a14712535d7ee0326ac2907d8d0dab06c3e8a2844960a6d76d81bcdb41a
BLAKE2b-256 checksum
How to use checksums
a56a5ca21532ee7da23eb7089dc7de4d20bb92568d36d5dad19d18f1b3e029f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / textnoisr-1.2.0-py3-none-any.whl

Download URL textnoisr-1.2.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23f16cdc56d330e1bb7b9f49caebc773196ab9088d83651f0f4909963c24bc91
BLAKE2b-256 checksum
How to use checksums
8c8e467d5ea11ec90fc7067eb8d9ee6c997eec73c136355d5979513dc9641fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for textnoisr 1.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for textnoisr-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

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