Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

perf: avoid spaCy statistical pipeline for word tokenization#4408

Open
KRRT7 wants to merge 7 commits into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
KRRT7:perf-tokenizer-onlyKRRT7/unstructured:perf-tokenizer-onlyCopy head branch name to clipboard
Open

perf: avoid spaCy statistical pipeline for word tokenization#4408
KRRT7 wants to merge 7 commits into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
KRRT7:perf-tokenizer-onlyKRRT7/unstructured:perf-tokenizer-onlyCopy head branch name to clipboard

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Use spaCy's tokenizer-only make_doc() path in word_tokenize() instead of running the complete statistical pipeline.

Word tokenization only consumes token.text, so running the tagger and dependency parser adds substantial work without affecting the result.

This PR also:

  • Preserves the existing oversized-input truncation behavior.
  • Adds regression tests comparing tokenizer-only output with the full pipeline.
  • Adds a representative multi-format benchmark with exact output-parity checks.

Performance

Benchmarked on an 8-vCPU AMD EPYC host with 15 GiB RAM and Python 3.12.

The benchmark covers large TXT, HTML, DOCX, and PPTX documents through their format-specific partitioners. The spaCy model is warmed before measurement, while token, sentence, and POS result caches are cleared before every measured iteration. This measures the algorithmic improvement rather than repeated-document cache hits.

Each result is the median of three iterations.

Document upstream/main This PR Improvement
1,225-page War and Peace TXT 57.393s 49.215s 14.2%
230-page 10-K HTML 1.129s 1.044s 7.5%
872-page handbook DOCX 23.553s 20.628s 12.4%
369-page science presentation PPTX 3.726s 2.350s 36.9%
Aggregate median 85.801s 73.238s 14.6% / 1.17x

Output parity was exact for every document, covering:

  • 11,751 TXT elements
  • 314 HTML elements
  • 4,759 DOCX elements
  • 5,116 PPTX elements

The benchmark verifies every element's concrete type and text using a stable SHA-256 fingerprint.

Benchmark reproduction

# On upstream/main
uv run --no-sync python scripts/performance/benchmark_text_partition.py \
  /tmp/main.json

# On this branch
uv run --no-sync python scripts/performance/benchmark_text_partition.py \
  /tmp/candidate.json --compare /tmp/main.json

The benchmark defaults to three iterations over the representative four-document matrix. Custom workloads can be supplied by repeating --input:

uv run --no-sync python scripts/performance/benchmark_text_partition.py \
  /tmp/custom.json \
  --input example-docs/example-10k-230p.html \
  --input example-docs/handbook-872p.docx

Testing

  • 121 focused NLP, text-classification, and benchmark tests pass.
  • Token parity is covered for punctuation, contractions, URLs, Unicode, emoji, tabs, and newlines.
  • Oversized-input truncation is covered.
  • A regression test ensures word_tokenize() never invokes the statistical pipeline.
  • Benchmark tests cover multi-document execution, cache clearing, stable fingerprints, exact comparison, and output-regression rejection.
  • Ruff lint and formatting checks pass.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Shadow auto-approve: would auto-approve. This change replaces the full statistical pipeline with the tokenizer-only path in word_tokenize(), preserving behavior while improving performance. The diff shows the bounded refactoring with output-parity tests and a no-invocation regression test, making it clearly beneficial.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

Comment thread scripts/performance/benchmark_text_partition.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Shadow auto-approve: would not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Shadow auto-approve: would auto-approve. This PR replaces the full spaCy pipeline with the tokenizer-only path in word_tokenize(), which is clearly bounded and beneficial. The diff shows all other callers retain the pipeline, truncation logic is preserved, and new regression tests confirm output parity.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Shadow auto-approve: would auto-approve. Focused performance optimization replacing full spaCy pipeline with tokenizer-only path, preserving output behavior. Verified by exact parity tests and benchmarks. No new capabilities, no changes to public contracts, auth, data handling, or operational tradeoffs.

Re-trigger cubic

@KRRT7

KRRT7 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@cragwolfe looks like the transient issue was hiding a bug.

@KRRT7
KRRT7 requested a review from cragwolfe July 23, 2026 00:32
@cragwolfe
cragwolfe enabled auto-merge July 23, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.