Skip to content

fix(text): count hash characters, not runs, in SymbolsToWordsFilter - #2519

Open
usmanmateen wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
usmanmateen:fix/symbols-to-words-hash-runs
Open

usmanmateen wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
usmanmateen:fix/symbols-to-words-hash-runs

Conversation

@usmanmateen

Copy link
Copy Markdown
Contributor

Description

Closes #2517.

SymbolsToWordsFilter computed a word's symbol ratio as len(regex_hash.findall(word)) / len(word), with regex_hash = re.compile("#+"). That counts runs of #, not # characters, so "##" scored 0.5 and "###" 0.33, and neither counted as a symbol word. It now counts the # characters (word.count("#")), so a word is a symbol word when more than half of its characters are #, as the comment says.

Text main This PR
"### ### ### ###" 0.0 (kept) 1.0 (removed)
"## Installation\nRun the script" 0.0 (kept) 0.2 (removed)
"# one two three four five" 0.167 (removed) 0.167 (removed)
"Use #hashtags in a sentence" 0.0 (kept) 0.0 (kept)

Only words with two or more # in a row score differently. Words with a single #, such as #hashtags or C#, score as before, and so do ellipses. regex_hash is no longer used in string.py, so the import is dropped; it stays in constants.py.

The PR has two commits: the regression test, which fails on main, and the fix.

Usage

from nemo_curator.stages.text.filters.heuristic.string import SymbolsToWordsFilter

SymbolsToWordsFilter().score_document("### ### ### ###")
# main: 0.0, this PR: 1.0

Checklist

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

Tests: test_symbolswords_hash_runs fails on main and passes with the change. pytest tests/stages/text/modules/test_filters.py tests/stages/text/modules/test_modifiers.py: 210 passed, 1 skipped (the existing MeCab skip). ruff check and ruff format --check (0.14.10) pass on the changed files.

"##" and "###" are made only of hash symbols, like "#", but the filter
scores "### ### ### ###" as 0 and keeps it, while "# one two three four
five" scores 0.17 and is removed.

Signed-off-by: usmanmateen <74776275+usmanmateen@users.noreply.github.com>
The symbol ratio of a word divided the number of regex_hash ("#+")
matches by the word length, so "##" scored 0.5 and "###" 0.33, and
neither counted as a symbol word. Count the "#" characters instead, so a
word is a symbol word when more than half of its characters are "#", as
the comment says. Hashtags such as "#hashtags" are unaffected.

Signed-off-by: usmanmateen <74776275+usmanmateen@users.noreply.github.com>
@usmanmateen
usmanmateen requested a review from a team as a code owner October 20, 2026 07:38
@usmanmateen
usmanmateen requested review from praateekmahajan and removed request for a team October 20, 2026 07:38
@copy-pr-bot

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

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

SymbolsToWordsFilter now counts individual # characters instead of consecutive runs.

  • Hash-heavy words now count each mark in symbol scores.

Reviews (1) · Last reviewed commit: "fix(text): count hash characters, not ru..." · Reviewed by Greptile

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

Copy link
Copy Markdown
Contributor Author

@praateekmahajan could you review this when you get a chance? It's a small fix to how SymbolsToWordsFilter counts hash characters.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Nov 18, 2026

This branch has not been deployed

No deployments
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.

SymbolsToWordsFilter counts runs of '#', not '#' characters, so '##' and '###' aren't symbol words

2 participants