A universal text cleaning and dataset preparation library for any language or script.
Project description
polyglean
A universal text cleaning and dataset preparation library for any language or script.
Built for TTS (text-to-speech) voice data pipelines but useful for any NLP corpus work.
Handles Latin, Arabic, Devanagari, CJK, and any Unicode-based script correctly.
Installation
pip install polyglean
Quick start
import polyglean
config = {
"base_dir": "/path/to/your/data/",
"output_dir": "/path/to/output/",
"source_config": [
("bbc_news.xlsx", "sentence", "bbc"),
("bible.xlsx", "text", "bible"),
],
"separate_files": [],
"extra_cleaners": [],
"word_count_min": 5,
"word_count_max": 20,
"output_tts": "my_language_tts.xlsx",
"output_other": "my_language_other.xlsx",
}
polyglean.run_language("my_language", config)
Two output files are created:
my_language_tts.xlsx— sentences within the word count window (TTS-ready)my_language_other.xlsx— sentences outside the window (for further splitting)
CLI usage
Register your language config, then use the command-line tools:
# Run the full cleaning pipeline
polyglean-clean --lang yoruba
# Process multiple languages
polyglean-clean --lang yoruba hausa igbo
# Split long sentences into TTS-ready chunks
polyglean-split --lang yoruba
Supported file formats
| Type key | Format | Extra options |
|---|---|---|
excel (default) |
.xlsx / .xls |
col (column name) |
csv |
.csv |
col, sep, encoding |
parquet |
.parquet |
col |
json_list |
JSON array of objects | col (field to extract) |
json_articles_body |
JSON with articles[].body |
— |
txt |
Plain text, one sentence/line | — |
source_config = [
# Excel (shorthand tuple)
("corpus.xlsx", "sentence", "corpus"),
# CSV with tab separator
{"path": "data.tsv", "col": "text", "label": "web", "type": "csv", "sep": "\t"},
# Parquet
{"path": "data.parquet", "col": "sentence", "label": "hf", "type": "parquet"},
# JSON array
{"path": "stories.json", "col": "story_text", "label": "stories", "type": "json_list"},
# Plain text
{"path": "sentences.txt", "label": "misc", "type": "txt"},
]
What the cleaning pipeline does
Applied to every sentence, in order:
- Unicode NFC normalization — prevents false duplicates from diacritic encoding differences
- Control character removal — strips non-printable characters
- Newline flattening — collapses multi-line text to a single line
- Bracket content removal — removes
[footnote],[210], etc. - Digit removal — removes numerals (TTS-specific; see below to opt out)
- Whitespace collapsing — normalizes spacing
Then:
- All-caps rows are dropped (headers, acronym-only rows)
- Empty sentences are dropped
- Duplicates are removed (first occurrence kept)
Adding language-specific cleaners
import re
config["extra_cleaners"] = [
# Strip a prefix specific to your dataset
lambda text: re.sub(r"^Chapter\s+\d+:\s*", "", text),
# Remove URLs from web-scraped sources
from polyglean.cleaners import remove_urls
remove_urls,
]
Keeping digits (non-TTS use)
from polyglean.cleaners import BASE_CLEANERS, remove_digits
config["extra_cleaners"] = []
# Pass a custom cleaner list that excludes remove_digits:
CLEANERS_NO_DIGITS = [fn for fn in BASE_CLEANERS if fn is not remove_digits]
Using the step-by-step API
from polyglean.loaders import load_sources
from polyglean.pipeline import clean_data, split_and_save, split_other_sentences
df = load_sources(config["base_dir"], config["source_config"])
df = clean_data(df, config.get("extra_cleaners", []))
split_and_save(df, config)
# Later — chunk the long sentences
split_other_sentences("my_language", config)
License
MIT © Rasheedat Sikiru
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 polyglean-0.1.0.tar.gz.
File metadata
- Download URL: polyglean-0.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58f8b116ef42b8b77d22c92ce08d337f4b983b26bb2759f09ef3d85d035ea0ec
|
|
| MD5 |
0140bcd69d91287d8122ff2a81c25978
|
|
| BLAKE2b-256 |
f61d71d14815d4169c164e7eeb3ff8809a3e260dae16cc1930c19d22efbe1541
|
File details
Details for the file polyglean-0.1.0-py3-none-any.whl.
File metadata
- Download URL: polyglean-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b1e1f9c214c8e48ddc65652d13ade1e860fe058c4a24a96a709f4afde8be753
|
|
| MD5 |
f89be0b87dcdea3c43f0c5c1cbd35d9a
|
|
| BLAKE2b-256 |
40bfdb23e30f6942969e150fd9aea872f43757c6a636091c6b6ffa7bb6426297
|