Skip to content

fix(text): drop empty repeated-paragraph documents - #2444

Merged
sarahyurick merged 3 commits into
NVIDIA-NeMo:mainfrom
1fanwang:1fannnw/repeated-paragraphs-empty
Oct 7, 2026
Merged

sarahyurick merged 3 commits into
NVIDIA-NeMo:mainfrom
1fanwang:1fannnw/repeated-paragraphs-empty

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Description

Empty documents can pass through a standalone repeated-paragraph filter as if they were valid text. That differs from the neighboring repetition filters, which treat empty or undersized inputs as documents to drop.

This changes RepeatedParagraphsFilter so empty text scores below the keep threshold. Non-empty paragraph scoring still uses the existing unique-paragraph ratio.

Closes #2443

Usage

No usage change. Existing ScoreFilter(RepeatedParagraphsFilter()) pipelines now drop empty documents instead of retaining them.

Checklist

  • I am familiar with the Contributing Guide.
  • New or Existing tests cover these changes.
  • The documentation is up to date with these changes.

Testing Done

Raw logs

Red, before the fix:

docker run --rm -v "$PWD":/workspace -w /workspace -e UV_PROJECT_ENVIRONMENT=.venv-linux -e UV_CACHE_DIR=.uv-cache python:3.12-slim bash -lc 'apt-get update -qq && apt-get install -y -qq g++ >/dev/null && python -m pip install --quiet uv && uv sync --extra text_cpu --quiet && PATH=/workspace/.venv-linux/bin:$PATH .venv-linux/bin/python -m pytest -m "not gpu" tests/stages/text/modules/test_filters.py::TestHeuristicFilters::test_repeatedparagraphs'
collected 1 item

tests/stages/text/modules/test_filters.py F                              [100%]

=================================== FAILURES ===================================
_________________ TestHeuristicFilters.test_repeatedparagraphs _________________

E       AssertionError: Expected DocumentBatch(dataset_name='test_1', data=             text
E         0  totally unique, _stage_perf=[], _metadata={}, task_id='', _source_id='') but got DocumentBatch(dataset_name='test_1', data=             text
E         0                
E         1  totally unique, _stage_perf=[], _metadata={}, task_id='', _source_id='')
E       assert False

=========================== short test summary info ============================
FAILED tests/stages/text/modules/test_filters.py::TestHeuristicFilters::test_repeatedparagraphs
======================== 1 failed, 2 warnings in 25.22s ========================

Green, after the fix:

docker run --rm -v "$PWD":/workspace -w /workspace -e UV_PROJECT_ENVIRONMENT=.venv-linux -e UV_CACHE_DIR=.uv-cache python:3.12-slim bash -lc 'apt-get update -qq && apt-get install -y -qq g++ >/dev/null && python -m pip install --quiet uv && uv sync --extra text_cpu --quiet && PATH=/workspace/.venv-linux/bin:$PATH .venv-linux/bin/python -m pytest -m "not gpu" tests/stages/text/modules/test_filters.py; code=$?; chown -R 501:20 .venv-linux .uv-cache 2>/dev/null || true; exit $code'
collected 75 items

tests/stages/text/modules/test_filters.py .............................. [ 40%]
........s....................................                            [100%]

================== 74 passed, 1 skipped, 6 warnings in 26.28s ==================

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang requested a review from a team as a code owner September 25, 2026 06:19
@1fanwang
1fanwang requested review from VibhuJawa and removed request for a team September 25, 2026 06:19
@copy-pr-bot

copy-pr-bot Bot commented Sep 25, 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 Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds empty-document handling to text repetition filters.

The PR appears safe to merge; no actionable new issue was identified.

Summary

The PR makes four repetition filters score empty or whitespace-only text as zero and adds tests confirming those documents are dropped. Non-empty scoring remains unchanged.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into 1fannnw/repeate..."

@shaurya416

Copy link
Copy Markdown

Thanks for picking this up. I ran RepeatedParagraphsFilter from main (23f1fa2) and from this PR head (34e5227), extracting the class text verbatim into plain Python (no repository modules imported; stand-ins for DocumentFilter and get_paragraphs, which is document.split("\n\n")):

text main score / keep this PR score / keep
"" 1.0 / True 0.0 / False
" " 1.0 / True 0.0 / False
"\n\n" 0.5 / False 0.0 / False
three unique paragraphs (control) 1.0 / True 1.0 / True
"half.\n\nhalf." (control) 0.5 / False 0.5 / False
ten identical paragraphs (control) 0.1 / False 0.1 / False
one paragraph (control) 1.0 / True 1.0 / True

So the empty case from #2443 is fixed, whitespace-only text is handled the same way, and non-empty scoring is unchanged. I did not run the repository's test suite.

One thing outside this change: the other filters mentioned in #2443 that divide by an empty count (RepeatedParagraphsByCharFilter, RepeatedLinesFilter, RepeatedLinesByCharFilter) are not touched here, so an empty document can still raise ZeroDivisionError in those.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Sep 25, 2026

@sarahyurick sarahyurick 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.

Hi @1fanwang thanks for opening! Can you please check the other filters in https://github.com/NVIDIA-NeMo/Curator/blob/main/nemo_curator/stages/text/filters/heuristic/repetition/repetition.py and make sure that they all have similar behavior?

Maybe even better would be to drop empty records in https://github.com/NVIDIA-NeMo/Curator/blob/main/nemo_curator/stages/text/filters/score_filter.py instead?

Ensure RepeatedLinesFilter, RepeatedLinesByCharFilter, RepeatedParagraphsFilter,
and RepeatedParagraphsByCharFilter safely return 0.0 on empty and whitespace-only
inputs, guarding against ZeroDivisionError and dropping empty documents.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang

Copy link
Copy Markdown
Contributor Author

Thanks @sarahyurick and @shaurya416. Updated in ac94abf.

  • Extended empty and whitespace guards to RepeatedLinesFilter, RepeatedLinesByCharFilter, and RepeatedParagraphsByCharFilter so they return 0.0 (dropping empty documents) and avoid ZeroDivisionError.
  • Added unit tests covering empty and whitespace-only text across all four filters.

Regarding score_filter.py: handling this in score_document keeps filters safe when called standalone or via Score (which computes scores without dropping rows), while avoiding text-emptiness assumptions in generic ScoreFilter.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Sep 30, 2026
@1fanwang
1fanwang requested a review from sarahyurick October 4, 2026 06:57
@sarahyurick

Copy link
Copy Markdown
Contributor

/ok to test eaf65da

@sarahyurick sarahyurick 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.

LGTM thanks @1fanwang !

@sarahyurick
sarahyurick enabled auto-merge (squash) October 6, 2026 23:40
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 7, 2026
@sarahyurick
sarahyurick merged commit edb653b into NVIDIA-NeMo:main Oct 7, 2026
69 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 7, 2026

This branch was previously deployed

3 inactive deployments
nemo-ci — eaf65da2 Deployed Oct 7, 2026 by copy-pr-bot[bot] via L0_Unit_Test_GPU-audio_qwen_asr #5741
public — eaf65da2 Deployed Oct 6, 2026 by copy-pr-bot[bot] via release / finalize / notify #1277
test — eaf65da2 Deployed Oct 6, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #5741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RepeatedParagraphsFilter scores an empty document 1.0 (maximum non-repetitive) and keeps it, unlike its sibling filters in the same file

4 participants