A package to intentionally introduce human-like errors into text.
Project description
autoINcorrect 🤖💥
"A spell-checker-in-reverse"
Ever stared at your phone, absolutely convinced you typed "meeting," only for it to send "meating"? We've all been victims of autocorrect. But it got me thinking: what if we turned the tables?
This is the autoINcorrect system. It's a "spell-checker-in-reverse" that, instead of fixing mistakes, artfully creates them.
The Idea
This isn't just random chaos. It's a sophisticated system built on a simple, but (if I do say so myself) pretty smart idea: what if, to test how good a "fixer" is, we first built the perfect "breaker"?
By simulating how humans make real, plausible errors, we can build the ultimate stress-test for any real autocorrect model out there. It's an entire NLP pipeline, built in reverse.
This system understands:
Physical Errors: Simulating "fat-finger" slips from an actual keyboard layout.
Cognitive Errors: Simulating "brain-fart" moments like homophone swaps (your vs. you're).
Semantic Errors: Simulating "near-miss" malapropisms like banking -> banker using NLP (NLTK) and word embeddings (GloVe).
Formatting Errors: Simulating real-world punctuation mistakes and random case-flipping.
📦 First-Time Setup
Before you run the script, you'll need the necessary NLP models. Your pipeline.py file includes a helper function to do this automatically.
The first time you import or run the package, it will:
Check for the necessary nltk data (WordNet, Punkt, Tagger).
Download any missing nltk packages.
The first time you use the "Malapropism" module, it will download the glove-wiki-gigaword-100 model (this may take a minute).
🚀 Quick Start & Usage
This package is designed to be simple to use and easy to chain. The main wrapper function is auto_incorrect().
--- Import the main functions ---
from autoINcorrect import auto_incorrect, word_error, corrupt_format
my_text = "I am running a test on my banking application for its creative standards. It's a beautiful day to see if your function works correctly."
--- Option 1: Run the full chain with one function ---
(This uses all default settings)
print("--- Full Corruption (Default) ---")
This is the main wrapper function you'll usually use
corrupted_text = auto_incorrect(my_text) print(corrupted_text)
--- Option 2: Manually chain functions for more control ---
print("\n--- Manual Chaining (Custom Settings) ---")
1. Apply word-based errors
(Let's make errors common, with 70% typos and 30% smart errors)
custom_distribution = { 'fat_finger': 0.7, 'brain_fart': 0.3, 'malapropism': 0.0 } text_with_word_errors = word_error( my_text, error_rate=0.3, # Corrupt 30% of words distribution=custom_distribution )
2. Apply punctuation and case errors to that result
(Let's be aggressive: remove all punctuation and flip 80% of caps)
final_corrupted_text = corrupt_format( text_with_word_errors, add_rate=0.0, replace_rate=0.0, remove_rate=1.0, # 100% chance to remove punctuation case_corruption_prob=0.8 # 80% chance to flip a CAPITAL )
print(f"\nOriginal:\n{my_text}\n") print(f"Corrupted:\n{final_corrupted_text}")
🛠️ Key Modules
Your package is split into two main corruption functions, which are combined in the auto_incorrect() wrapper.
- word_error()
This function handles all word-based corruption. It contains three sub-modules:
⌨️ "Fat Finger" Module: Simulates physical keyboard mistakes.
adjacent_swap: standard -> stamdard (m near n)
transpose: standard -> standrad
delete_char: standard -> standad
insert_char: standard -> standfard
🧠 "Brain Fart" Module: Simulates cognitive "word choice" mistakes.
replace_homophone: your -> you're
replace_morphological: decision -> decide (uses NLTK/WordNet)
🎭 "Malapropism" Module: The smartest module. Creates "near-miss" semantic errors.
replace_semantic_neighbor: banking -> banker (uses GloVe embeddings to find related words with the same root).
- corrupt_format()
This function handles all punctuation and case-based corruption.
Punctuation: Randomly adds (word,), removes (word. -> word), or replaces (word? -> word;) punctuation marks.
Case: Randomly flips CAPITAL letters to lowercase based on a probability.
📦 Installation
pip install autoINcorrect
📜 License
This project is licensed under the MIT License.
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 autoincorrect-0.0.2.tar.gz.
File metadata
- Download URL: autoincorrect-0.0.2.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97a957a7c8e8b13f4d81da61858244ff7e647a4ab18f158447dc78d5721b5cfc
|
|
| MD5 |
00f1a8a8ca69c2f0ef8d34401bbac9ed
|
|
| BLAKE2b-256 |
72ba16181f95ee5bacdf616ac6e5cd00163ae6c5ca51eeb349bfc5ab3764a79c
|
File details
Details for the file autoincorrect-0.0.2-py3-none-any.whl.
File metadata
- Download URL: autoincorrect-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8294979fdfeaf01372d3c95152ec132751c398137432ef01dcb8adc05d1f1f9f
|
|
| MD5 |
910f8008f6bbf55a58d81e27a340d9ef
|
|
| BLAKE2b-256 |
0db99d84fbb6acaffa0311e6b78e9b8d44ffcb02ac9966ef9ae3767b354768a7
|