A high-throughput, domain-specific text preprocessing cascading pipeline filter to rank core sentences in texts and filter away boilerplate.
Project description
DSTPR: Domain-specific Text Pre-processing and Ranking
A high-throughput text preprocessing pipeline designed to filter, segment, and rank core sentences from noisy, plaintext documents.
This package strips away boilerplate, disclaimers, and application instructions before moving this data onto to heavier processing pipelines.
Pipeline Architecture
Instead of running heavy transformer models over every sentence in a document, DSTPR pipes documents through progressively stricter layers:
- Heuristic Cleansing & Tokenization: Uses
PySBD(Python Sentence Boundary Disambiguation) paired with regular expressions to fix punctuation caused by flattening, then filters out sentences containing stop phrases. - Semantic Section Routing: Utilizes a lightweight encoder (Default:
all-MiniLM-L6-v2) to dynamically find structural transitions (i.e., headers) in input texts. - Hybrid Ranking: Scores remaining sentences using a combination of Semantics (cosine similarity to anchors) and Lexical Syntax (regex- and POS-supported detection).
- Parallel Execution Engine: Wraps the entire pipeline inside efficient datasets to allow for batch processing at scale, with CPU or GPU.
Installation
To install the package, simply run
pip install dstpr
Usage
High-Throughput Batch Processing
This is the recommended approach for large-scale data pipelines.
from dstpr import ParallelPreprocessingPipeline, JOB_POSTING_PROFILE
pipeline = ParallelPreprocessingPipeline(profile=JOB_POSTING_PROFILE, batch_size=64)
raw_documents = [
"DOC 1",
"DOC 2",
"..."
]
cleaned_documents = pipeline.process(raw_documents, num_workers=8, threshold=0.25)
Advanced Usage
If you want to integrate specific pipeline layers directly into an existing workflow, or tweak the internal parameters, you can import individual modules manually:
from dstpr.cleaners import clean_and_split_chunks
from dstpr.segmenters import SemanticSectionRouter
from dstpr.rankers import HybridTaskRanker
from sentence_transformers import Transformer, SentenceTransformer
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
text = "Job posting text goes here!"
# Clean and segment sentences
sentences = clean_and_split_chunks(text)
# Route by context
router = SemanticSectionRouter(model=embedding_model)
buckets = router.route_sentences(sentences)
target_sentences = buckets['CORE'] + buckets['REQUIREMENTS']
# Grade and sort text features
ranker = HybridRanker(model=shared_model)
final = ranker.rank_and_filter(target_sentences, bi_cutoff_pct=0.25, final_threshold=0.40)
Parameter Tuning
To adjust the trade-off between strict filtering and execution speed, consider tweaking these variables in ParallelPreprocessingPipeline:
threshold(Default:0.4): Controls how aggressively sentences are discarded. Raising this value toward0.6, for example, ensures only stronger matching sentences are passed through. Lowering it toward0.3, on the other hand, acts as a wider net.batch_size(Default:256): This depends on your hardware! Adjust for best performance.
Creating Custom Domain Profiles (via the provided wizard)
A DomainProfile is required to use DSTPR (see the usage example). Out of the box, dstpr ships with pre-configured configurations for job postings (JOB_POSTINGS_PROFILE). However, you can easily generate an domain-specific pipeline for any specific domain using our built-in interactive configuration wizard.
To spin up the profile creation walkthrough, simply open your terminal and run:
task-profile-wizard
All profiles generated via the terminal wizard are automatically validated and written out as JSON to a local cache: ~/.config/dstpr/profiles/
Project details
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 dstpr-0.1.2.tar.gz.
File metadata
- Download URL: dstpr-0.1.2.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53bdfbcecbc055049fd74f7278e7d380ce2a929cfca44439ae6f1975207c9f7d
|
|
| MD5 |
d1c6495f6b4ca4fad13039f0aca2aad1
|
|
| BLAKE2b-256 |
9a502537c3306c7d3bfefe79093c8975733fb6f6717f1406a001c8b74394914d
|
File details
Details for the file dstpr-0.1.2-py3-none-any.whl.
File metadata
- Download URL: dstpr-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60a0250d8d3c246f74ce347948f587cd2a4798c19f1f65277e4127a8600a84a9
|
|
| MD5 |
4202d847f214684096502711ea022808
|
|
| BLAKE2b-256 |
af075660f3fe9fa12a2c4b480eb5ee7f4e0a12f5f7fab00517e5600b0fdac574
|