Skip to content

fix(text): compute histogram filter ratio over stripped text - #2511

Open
udsy19 wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
udsy19:fix/histogram-filter-strip-ratio
Open

udsy19 wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
udsy19:fix/histogram-filter-strip-ratio

Conversation

@udsy19

@udsy19 udsy19 commented Oct 17, 2026

Copy link
Copy Markdown

What

HistogramFilter.score_document counts in-histogram characters over text.strip() but divides by len(text) — the un-stripped length:

cnt = len([c for c in text.strip() if c in self._histogram])
return 1 if cnt / len(text) > self._threshold else 0

Numerator and denominator range over different character sets. Leading/trailing whitespace inflates the denominator, lowering the ratio and flipping an otherwise-kept document to rejected. Whitespace-only/empty input additionally raises ZeroDivisionError.

With histogram {a, b, c} and threshold 0.8, "abc" scores 1.0 (kept) while " abc " scores 0.43 (dropped) — identical content, opposite verdicts. Legitimate text is silently discarded from curated datasets.

Fix

Compute the ratio over the same stripped text used for the numerator, and return 0 for empty/whitespace-only input:

stripped = text.strip()
if not stripped:
    return 0
cnt = len([c for c in stripped if c in self._histogram])
return 1 if cnt / len(stripped) > self._threshold else 0

Tests

Adds tests/stages/text/filters/histogram/test_histogram_filter.py covering whitespace-invariance, the empty/whitespace-only guard, and a below-threshold rejection. Verified fail-on-revert: with the source reverted the whitespace document flips to rejected and empty input raises ZeroDivisionError; with the fix all pass.

HistogramFilter.score_document counted in-histogram characters over
text.strip() but divided by len(text), the un-stripped length. Leading
or trailing whitespace inflated the denominator, lowering the ratio and
flipping otherwise-kept documents to rejected. Whitespace-only or empty
input also raised ZeroDivisionError.

Compute the ratio over the stripped text used for the numerator, and
return 0 for empty/whitespace-only input.

Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
@udsy19
udsy19 requested a review from a team as a code owner October 17, 2026 23:14
@udsy19
udsy19 requested review from suiyoubi and removed request for a team October 17, 2026 23:14
@copy-pr-bot

copy-pr-bot Bot commented Oct 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

HistogramFilter.score_document now counts characters and computes their ratio over the same stripped text.

  • Histogram filtering ignores whitespace around text content.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/histogram-f..." · Reviewed by Greptile

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Oct 20, 2026
@sarahyurick

Copy link
Copy Markdown
Contributor

/ok to test a5df36a

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Oct 23, 2026

This branch had an error being deployed

1 failed and 2 active deployments
nemo-ci — a5df36af Deployed Oct 24, 2026 by copy-pr-bot[bot] via Unit_Test_pipelines_CPU #5930
test — a5df36af Deployed Oct 23, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #5930
public — a5df36af Deployed Oct 23, 2026 by copy-pr-bot[bot] via release / finalize / notify #1451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants