Skip to main content

Monsters for your language games.

Project description

     .─') _                                       .─') _                  
    (  OO) )                                     ( OO ) )            
  ░██████  ░██ ░██   ░██               ░██       ░██ ░██                                 
 ░██   ░██ ░██       ░██               ░██       ░██                                     
░██        ░██ ░██░████████  ░███████ ░████████  ░██ ░██░████████   ░████████ ░███████  
░██  █████ ░██ ░██   ░██    ░██('─.░██ ░██    ░██ ░██ ░██░██    ░██ ░██.─')░██ ░██        
░██     ██ ░██ ░██   ░██    ░██( OO ) ╱░██    ░██ ░██ ░██░██    ░██ ░██(OO)░██ ░███████  
  ░██  ░███ ░██ ░██   ░██   ░██    ░██ ░██    ░██ ░██ ░██░██    ░██ ░██  o░███      ░██ 
  ░█████░█ ░██ ░██   ░████   ░███████  ░██    ░██ ░██ ░██░██    ░██  ░█████░██ ░███████  
                                                                    ░██            
                                                                ░███████             

                        Every language game breeds monsters.

Glitchlings are utilities for corrupting the text inputs to your language models in deterministic, linguistically principled ways.
Each embodies a different way that documents can be compromised in the wild.

If reinforcement learning environments are games, then Glitchlings are enemies to breathe new life into old challenges.

They do this by breaking surface patterns in the input while keeping the target output intact.

Some Glitchlings are petty nuisances. Some Glitchlings are eldritch horrors.
Together, they create truly nightmarish scenarios for your language models.

After all, what good is general intelligence if it can't handle a little chaos?

-The Curator

Quickstart

pip install -U glitchlings

Glitchlings requires Python 3.10 or newer.

from glitchlings import Gaggle, SAMPLE_TEXT, Typogre, Mim1c, Reduple, Rushmore

gaggle = Gaggle([
    Typogre(rate=0.03),
    Mim1c(rate=0.02),
    Reduple(seed=404),
    Rushmore(rate=0.02),
])

print(gaggle(SAMPLE_TEXT))

Onҽ m‎ھ‎rning, wһen Gregor Samƽa woke from trouble𝐝 𝑑reams, he found himself transformed in his bed into a horrible vermin‎٠‎ He l lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightlh domed and divided by arches ino stiff sections. The bedding was adly able to cover it and and seemed ready to slide off any moment. His many legxs, pitifully thin compared with the size of the the rest of him, waved about helplessly ashe looked looked.

Consult the Glitchlings Usage Guide for end-to-end instructions spanning the Python API, CLI, HuggingFace and Prime Intellect integrations, and the autodetected Rust pipeline (enabled whenever the extension is present).

Motivation

If your model performs well on a particular task, but not when Glitchlings are present, it's a sign that it hasn't actually generalized to the problem.

Conversely, training a model to perform well in the presence of the types of perturbations introduced by Glitchlings should help it generalize better.

Your First Battle

Summon your chosen Glitchling (or a few, if ya nasty) and call it on your text or slot it into Dataset.map(...), supplying a seed if desired. Glitchlings are standard Python classes, so you can instantiate them with whatever parameters fit your scenario:

from glitchlings import Gaggle, Typogre, Mim1c

custom_typogre = Typogre(rate=0.1)
selective_mimic = Mim1c(rate=0.05, classes=["LATIN", "GREEK"])

gaggle = Gaggle([custom_typogre, selective_mimic], seed=99)
print(gaggle("Summoned heroes do not fear the glitch."))

Calling a Glitchling on a str transparently calls .corrupt(str, ...) -> str. This means that as long as your glitchlings get along logically, they play nicely with one another.

When summoned as or gathered into a Gaggle, the Glitchlings will automatically order themselves into attack waves, based on the scope of the change they make:

  1. Document
  2. Paragraph
  3. Sentence
  4. Word
  5. Character

They're horrible little gremlins, but they're not unreasonable.

Command-Line Interface (CLI)

Keyboard warriors can challenge them directly via the glitchlings command:

# Discover which glitchlings are currently on the loose.
glitchlings --list

# Run Typogre against the contents of a file and inspect the diff.
glitchlings -g typogre --file documents/report.txt --diff

# Configure glitchlings inline by passing keyword arguments.
glitchlings -g "Typogre(rate=0.05)" "Ghouls just wanna have fun"

# Pipe text straight into the CLI for an on-the-fly corruption.
echo "Beware LLM-written flavor-text" | glitchlings -g mim1c

Use --help for a complete breakdown of available options, including support for parameterised glitchlings via -g "Name(arg=value, ...)" to mirror the Python API.

Development

Follow the development setup guide for editable installs, automated tests, and tips on enabling the Rust pipeline while you hack on new glitchlings.

Starter 'lings

For maintainability reasons, all Glitchling have consented to be given nicknames once they're in your care. See the Monster Manual for a complete bestiary.

Typogre

What a nice word, would be a shame if something happened to it.

Fatfinger. Typogre introduces character-level errors (duplicating, dropping, adding, or swapping) based on the layout of a keyboard (QWERTY by default, with Dvorak and Colemak variants built-in).

Args

  • rate (float): The maximum number of edits to make as a percentage of the length (default: 0.02, 2%).
  • keyboard (str): Keyboard layout key-neighbor map to use (default: "CURATOR_QWERTY"; also accepts "QWERTY", "DVORAK", "COLEMAK", and "AZERTY").
  • seed (int): The random seed for reproducibility (default: 151).

Mim1c

Wait, was that...?

Confusion. Mim1c replaces non-space characters with Unicode Confusables, characters that are distinct but would not usually confuse a human reader.

Args

  • rate (float): The maximum proportion of characters to replace (default: 0.02, 2%).
  • classes (list[str] | "all"): Restrict replacements to these Unicode script classes (default: ["LATIN", "GREEK", "CYRILLIC"]).
  • banned_characters (Collection[str]): Characters that must never appear as replacements (default: none).
  • seed (int): The random seed for reproducibility (default: 151).

Scannequin

How can a computer need reading glasses?

OCR Artifacts. Scannequin mimics optical character recognition errors by swapping visually similar character sequences (like rn↔m, cl↔d, O↔0, l/I/1).

Args

  • rate (float): The maximum proportion of eligible confusion spans to replace (default: 0.02, 2%).
  • seed (int): The random seed for reproducibility (default: 151).

Zeedub

A whispering glyph parasite that lives in the interstices of codepoints, marking territory with invisible traces.

Invisible Ink. Zeedub slips zero-width codepoints between non-space character pairs, forcing models to reason about text whose visible form masks hidden glyphs.

Args

  • rate (float): Expected number of zero-width insertions as a proportion of eligible bigrams (default: 0.02, 2%).
  • characters (Sequence[str]): Optional override for the pool of zero-width strings to inject (default: curated invisibles such as U+200B, U+200C, U+200D, U+FEFF, U+2060).
  • seed (int): The random seed for reproducibility (default: 151).

Jargoyle

Uh oh. The worst person you know just bought a thesaurus.

Sesquipedalianism. Jargoyle, the insufferable Glitchling, replaces words from selected parts of speech with synonyms at random, without regard for connotational or denotational differences.

Args

  • rate (float): The maximum proportion of words to replace (default: 0.1, 10%).
  • part_of_speech: The WordNet part(s) of speech to target (default: nouns). Accepts wn.NOUN, wn.VERB, wn.ADJ, wn.ADV, any iterable of those tags, or the string "any" to include them all.
  • seed (int): The random seed for reproducibility (default: 151).

Reduple

Did you say that or did I?

Broken Record. Reduple stutters through text by randomly reduplicating words. Like a nervous speaker, it creates natural repetitions that test a model's ability to handle redundancy without losing the thread.

Args

  • rate (float): The maximum proportion of words to reduplicate (default: 0.05, 5%).
  • seed (int): The random seed for reproducibility (default: 151).

Rushmore

I accidentally an entire word.

Hasty Omission. The evil (?) twin of reduple, Rushmore moves with such frantic speed that it causes words to simply vanish from existence as it passes.

Args

  • rate (float): The maximum proportion of words to delete (default: 0.01, 1%).
  • seed (int): The random seed for reproducibility (default: 151).

Redactyl

Oops, that was my black highlighter.

FOIA Reply. Redactyl obscures random words in your document like an NSA analyst with a bad sense of humor.

Args

  • replacement_char (str): The character to use for redaction (default: █).
  • rate (float): The maximum proportion of words to redact (default: 0.05, 5%).
  • merge_adjacent (bool): Whether to redact the space between adjacent redacted words (default: False).
  • seed (int): The random seed for reproducibility (default: 151).

Field Report: Uncontained Specimens

Containment procedures pending

  • ekkokin substitutes words with homophones (phonetic equivalents).
  • nylingual backtranslates portions of text.
  • glothopper introduces code-switching effects, blending languages or dialects.
  • palimpsest rewrites, but leaves accidental traces of the past.
  • vesuvius is an apocryphal Glitchling with ties to [Nosy, aren't we? -The Curator]

Apocrypha

Cave paintings and oral tradition contain many depictions of strange, otherworldly Glitchlings.
These Apocryphal Glitchling are said to possess unique abilities or behaviors.
If you encounter one of these elusive beings, please document your findings and share them with The Curator.

Ensuring Reproducible Corruption

Every Glitchling should own its own independent random.Random instance. That means:

  • No random.seed(...) calls touch Python's global RNG.
  • Supplying a seed when you construct a Glitchling (or when you summon(...)) makes its behavior reproducible.
  • Re-running a Gaggle with the same master seed and the same input text (and same external data!) yields identical corruption output.
  • Corruption functions are written to accept an rng parameter internally so that all randomness is centralized and testable.

At Wits' End?

If you're trying to add a new glitchling and can't seem to make it deterministic, here are some places to look for determinism-breaking code:

  1. Search for any direct calls to random.choice, random.shuffle, or set(...) ordering without going through the provided rng.
  2. Ensure you sort collections before shuffling or sampling.
  3. Make sure indices are chosen from a stable reference (e.g., original text) when applying length‑changing edits.
  4. Make sure there are enough sort keys to maintain stability.

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

glitchlings-0.2.6.tar.gz (81.8 kB view details)

Uploaded Source

Built Distributions

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

glitchlings-0.2.6-cp312-cp312-win_amd64.whl (799.7 kB view details)

Uploaded CPython 3.12Windows x86-64

glitchlings-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

glitchlings-0.2.6-cp312-cp312-macosx_11_0_universal2.whl (907.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

glitchlings-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

glitchlings-0.2.6-cp311-cp311-macosx_11_0_universal2.whl (909.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ universal2 (ARM64, x86-64)

glitchlings-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

glitchlings-0.2.6-cp310-cp310-macosx_11_0_universal2.whl (909.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file glitchlings-0.2.6.tar.gz.

File metadata

  • Download URL: glitchlings-0.2.6.tar.gz
  • Upload date:
  • Size: 81.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glitchlings-0.2.6.tar.gz
Algorithm Hash digest
SHA256 a139c60ded3f225ab8f43231d80fecea2975b67989cbbc8c71eb263597ebd0e7
MD5 0b24eb02ed1527af14638cf59729c00a
BLAKE2b-256 15c209db0506bf92418ad2d3a7ca866079f038c2af0ec10817b23567308b2080

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6.tar.gz:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: glitchlings-0.2.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 799.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glitchlings-0.2.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 64bc3b38219b580bcf25f7e0dee6b635dd90bcf6972fef5f35d33e6dc1f0796d
MD5 309ae2c69a02994b3b4ecfdfa3bcb1cb
BLAKE2b-256 8831d9cac50c243b6b18a20f802bbb4c535f435e1b6ed7e50da7db45effdbad6

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 37197b45eb22304fe0f2c32ae581f2e1026bd1a9bcfca8777744251ce0c487ac
MD5 e4b88a4c57ac389594fdd727e235a413
BLAKE2b-256 5570e86de854c6242d4ab77286031e36b8660dfc2029f01ac69e1e4ab1314480

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 df304440dcda6ed38b0ef227f0e1b89d079bdb0abe27801cbe90503f9603db6a
MD5 701757c9fdc7a650613e793d77bbcacf
BLAKE2b-256 fe3245ea64121b0811b5eb7c97f33ce98efc47a345e274cfd3e4192317493f39

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp312-cp312-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 24d0b1232134bfd51510a5dbec732116094174168cf40a00c8f51d4faca0f3e5
MD5 60a2572a55e28043b113bac33b2a49f5
BLAKE2b-256 08731942986e7f7ed4dc2b27a6b2c57acb8af8fe5c5b4093b7d303bea4f5f12b

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp311-cp311-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 8ac35b116840c0cb5c4192ffd5d6eee93869fdb2b16a477cfa9f27b035079225
MD5 6c9f2bde0b06fcadc40c5b12fb60880e
BLAKE2b-256 5220f12b69694e066d7518b8d50d91bf79707524abd44dd95e00f03bf8f07144

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp311-cp311-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8bd95ce45e334841e0cb56a276fce5f3bb4b52edc6528b4d53b2b82224d95c98
MD5 3ae8d4cbfae3319363b13b8fb0788d31
BLAKE2b-256 52de15bd39f4267081cd7975906cb67da9a00bd01e2fea7a94298d166ee6525c

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.2.6-cp310-cp310-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.2.6-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 165eae76a6b1037fd2639e8bb90825a74f40a1020232d77579eb983c2eeed949
MD5 14d7ee1e6f796b667e3a23961fd67d5f
BLAKE2b-256 0845f6b9ffe410e214438c6dfa22fadf361a6cdb6aba4e5e990ee1adb12789eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.2.6-cp310-cp310-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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