Skip to main content

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:

  1. Unicode NFC normalization — prevents false duplicates from diacritic encoding differences
  2. Control character removal — strips non-printable characters
  3. Newline flattening — collapses multi-line text to a single line
  4. Bracket content removal — removes [footnote], [210], etc.
  5. Digit removal — removes numerals (TTS-specific; see below to opt out)
  6. 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

Metadata

Release files for polyglean 0.1.1

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

Source distribution (sdist)

Source distribution for polyglean 0.1.1
File Size Uploaded Provenance Actions
polyglean-0.1.1.tar.gz 13.7 kB Without provenance Details for polyglean-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 28.5 kB

Release files / polyglean-0.1.1.tar.gz

Download URL polyglean-0.1.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6532ae3af7e30c77b444d0da868dd9b531ba0b245c2fe52090228f0c644f34a1
BLAKE2b-256 checksum
How to use checksums
11f9b3b07059c932d2bb7582d290013c374f9e9f9cf1f0fb9353e122341a5d3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / polyglean-0.1.1-py3-none-any.whl

Download URL polyglean-0.1.1-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d95c52b5a70fcd3e43fa162ae841f95d3bad8e2357600d24e20848c212a294f8
BLAKE2b-256 checksum
How to use checksums
fafec3e7724a211eb374cb7a46e09113a9ac7ee9128302970bc85e4ec000c292
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for polyglean 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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