Skip to main content

Purism: Automatic data filtering library specialized in Korean data purification

Purify system

View in Korean

Summary

This repository is an automatic data filtering library specialized in Korean data purification.

How to use

Installation

Installation using pip

pip install purism

Quickstart

C4 dataset has "Clean" in its name, but it is NOT clean at all (especially the Korean subset). This is a code that performs additional filtering on the C4 dataset using this library.

from datasets import load_dataset
from collections import Counter
from tqdm.auto import tqdm
from purism import PurifyConfig, UnicodeCleaner, UICleaner, TextCleaner, LengthFilter, HarmfulWordsFilter, SpamWordsFilter, SignAbuseFilter, PIIFilter, LanguageFilter, DedupFilter

take_count = 40000
batch_size = 64

print("=" * 100)
ds = load_dataset(
    "allenai/c4",
    "ko",
    split="train",
    streaming=True
).take(take_count)

ds_sample = []

for text in tqdm(ds, desc="Extracting texts", total=take_count):
    ds_sample.append(text["text"])

normalizers = [
    UnicodeCleaner("NFC"),
    UICleaner(),
    TextCleaner()
]

multi_filters = [
    LengthFilter(),
    HarmfulWordsFilter(),
    SpamWordsFilter(),
    SignAbuseFilter(),
    PIIFilter()
]

batch_filters = [
    LanguageFilter(),
    DedupFilter()
]

counter = Counter()
filtered_all = 0
n_passed = 0
passed = []
n_filtered = 0
filtered = []
reason = []
purifier = PurifyConfig(normalizers, multi_filters, batch_filters, batch_size)

print("=" * 100)
result = purifier.parallel_purify(ds_sample, -1)

for text in result:
    if text["passed"]:
        counter["Passed"] += 1
        if n_passed < 10:
            passed.append(text["text"])
            n_passed += 1
    else:
        filtered_all += 1
        counter[text["filtered_by"]] += 1
        if n_filtered < 10:
            filtered.append(text["text"])
            reason.append(text["filtered_by"])
            n_filtered += 1

print("=" * 100)
print("Purification complete!")
print("=" * 100)
print("<|Filtering statistics|>")
print(" ")
print(f"Passed: {counter["Passed"]:,} ({counter["Passed"] / take_count * 100:.3f}%)")
print(f"LengthFilter: {counter["LengthFilter"]:,} ({counter["LengthFilter"] / take_count * 100:.3f}%)")
print(f"HarmfulWordsFilter: {counter["HarmfulWordsFilter"]:,} ({counter["HarmfulWordsFilter"] / take_count * 100:.3f}%)")
print(f"SpamWordsFilter: {counter["SpamWordsFilter"]:,} ({counter["SpamWordsFilter"] / take_count * 100:.3f}%)")
print(f"SignAbuseFilter: {counter["SignAbuseFilter"]:,} ({counter["SignAbuseFilter"] / take_count * 100:.3f}%)")
print(f"PIIFilter: {counter["PIIFilter"]:,} ({counter["PIIFilter"] / take_count * 100:.3f}%)")
print(f"LanguageFilter: {counter["LanguageFilter"]:,} ({counter["LanguageFilter"] / take_count * 100:.3f}%)")
print(f"DedupFilter: {counter["DedupFilter"]:,} ({counter["DedupFilter"] / take_count * 100:.3f}%)")
print(f"Total number of filtered texts: {filtered_all:,} ({filtered_all / take_count * 100:.3f}%)")
print("=" * 100)
print("<|Passed Samples|>")
print(" ")

for i, text in enumerate(passed):
    print("=" * 100)
    print(f"Sample {i + 1}")
    print(f"{text[i]}")

print("=" * 100)
print("<|Filtered Samples|>")
print(" ")

for i, text in enumerate(filtered):
    print("=" * 100)
    print(f"Sample {i + 1} (Filtered by {reason[i]})")
    print(f"{text[i]}")

print("=" * 100)

If you look at the results after running this code, you can see that there are many filtered texts.

API

More features can be found on this page.

Limitations

  • This library can accurately filter only Korean text. Modification of the source code is required to use other languages.
  • This library is not always accurate. It can filter out non-harmful text, but may fail to filter out some harmful text.

Metadata

Release files for purism 2.1.0

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

Source distribution (sdist)

Source distribution for purism 2.1.0
File Size Uploaded Provenance Actions
purism-2.1.0.tar.gz 10.7 kB Without provenance Details for purism-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 22.5 kB

Release files / purism-2.1.0.tar.gz

Download URL purism-2.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5a84b19b44155c3104112b983a2b1ced7d75058698a2e190afee0266e945aa14
BLAKE2b-256 checksum
How to use checksums
d9f0495c5e63ddd7902f2a85a4d7d4db0ea53484ed6217f96b03cdaf0496b7e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / purism-2.1.0-py3-none-any.whl

Download URL purism-2.1.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dfe4ccf84fab53cb9a21bfead2e17fdc5b8a76fba341e5e80329564af141c59
BLAKE2b-256 checksum
How to use checksums
a21d3122ada23a02ee053c47f646764b5c5c3cd5c4651bc204494089e8a848ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for purism 2.1.0

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.

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