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
from glitchlings import Gaggle, SAMPLE_TEXT, Typogre, Mim1c, Reduple, Rushmore
gaggle = Gaggle([
Typogre(max_change_rate=0.03),
Mim1c(replacement_rate=0.02),
Reduple(seed=404),
Rushmore(max_deletion_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.
Usage
Glitchlings slot into evaluation pipelines just as easily as they corrupt stray strings.
- Direct invocation – Instantiate a glitchling (or
Gaggle) and call it on strings, iterables, or datasets. Keep the seed stable to make every run deterministic. - Dataset corruption – Use a
Gaggle's.corrupt_datasethelper to perturb a Hugging Facedatasets.Datasetand return a corrupted copy for training or evaluation.
Prime Intellect environments
After pip install -e .[prime], the glitchlings.dlc.prime.load_environment helper mirrors verifiers.load_environment for Prime Intellect scenarios while optionally applying glitchlings before returning the environment:
from glitchlings import Mim1c, Typogre
from glitchlings.dlc.prime import load_environment
env = load_environment(
"osoleve/syllabify-en",
glitchlings=[Mim1c(replacement_rate=0.01), Typogre(max_change_rate=0.02)],
seed=404,
)
Skip the glitchlings argument to receive an untouched verifier dataset.
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(max_change_rate=0.1)
selective_mimic = Mim1c(replacement_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:
- Document
- Paragraph
- Sentence
- Word
- 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
# 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.
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
max_change_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
replacement_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"]).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
error_rate (float): The maximum proportion of eligible confusion spans to replace (default: 0.02, 2%).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
replacement_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). Acceptswn.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
reduplication_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
max_deletion_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: █).redaction_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
ekkokinsubstitutes words with homophones (phonetic equivalents).nylingualbacktranslates portions of text.glothopperintroduces code-switching effects, blending languages or dialects.palimpsestrewrites, but leaves accidental traces of the past.vesuviusis an apocryphalGlitchlingwith 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
seedwhen you construct aGlitchling(or when yousummon(...)) makes its behavior reproducible. - Re-running a
Gagglewith the same master seed and the same input text (and same external data!) yields identical corruption output. - Corruption functions are written to accept an
rngparameter 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:
- Search for any direct calls to
random.choice,random.shuffle, orset(...)ordering without going through the providedrng. - Ensure you sort collections before shuffling or sampling.
- Make sure indices are chosen from a stable reference (e.g., original text) when applying length‑changing edits.
- Make sure there are enough sort keys to maintain stability.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file glitchlings-0.1.4.tar.gz.
File metadata
- Download URL: glitchlings-0.1.4.tar.gz
- Upload date:
- Size: 48.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b218b2b37ebf8c0394caca141616cbd6435f8a9f02c0a7902a12d367d06e1b77
|
|
| MD5 |
b0986781a0a03fc2bf08fdc1e041944b
|
|
| BLAKE2b-256 |
e5d1176d331f6ae4bb23d3fc9d8d5f930870b24ca66e3f7989699aa7a0d51a13
|
File details
Details for the file glitchlings-0.1.4-py3-none-any.whl.
File metadata
- Download URL: glitchlings-0.1.4-py3-none-any.whl
- Upload date:
- Size: 34.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92898bf7c2e79ce7b3e8645ed9929caca7748a061d243d5d2d3b95684a82d480
|
|
| MD5 |
30a3a47412eb0876be9f3a299f1a07d6
|
|
| BLAKE2b-256 |
75d801b84f1b6d48c8d8b524c03bc07574aad579f2e042685ad6feb2777ad342
|