Skip to content

fix(tokenizer): ignore empty non-linguistic symbols to avoid a hang - #3852

Merged
LauraGPT merged 1 commit into
modelscope:mainfrom
MohammadHijjawi97:fix/char-tokenizer-empty-nlsym
Nov 7, 2026
Merged

LauraGPT merged 1 commit into
modelscope:mainfrom
MohammadHijjawi97:fix/char-tokenizer-empty-nlsym

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

Summary

CharTokenizer and PhonemeTokenizer read non_linguistic_symbols with set(line.rstrip() for line in f). A blank line in the symbol file (or an "" entry when a list is passed) adds the empty string to the set. In text2tokens, line.startswith("") is true at every position but consumes no input, so the while len(line) != 0 loop never ends; when symbols are kept it also keeps appending "" tokens until memory runs out.

This drops the empty string after the symbols are loaded, in both tokenizers.

Reproduction:

from funasr.tokenizer.char_tokenizer import CharTokenizer
CharTokenizer(non_linguistic_symbols=["", "<noise>"]).text2tokens("ab")

Before: never returns (killed by timeout 15, exit 124). The same happens with a symbol file such as "<noise>\n\n".
After: ['a', 'b']; "你<noise>好" gives ['你', '<noise>', '好'].

Type of change

  • Bug fix
  • Documentation
  • Example or demo
  • Runtime or deployment
  • Benchmark or evaluation
  • Model/training change

Validation

  • python -m pytest tests/test_char_tokenizer_non_linguistic_symbols.py: 3 passed (all 3 fail without the fix).
  • python -m compileall funasr examples tests (ran compileall on funasr/tokenizer and the new test file only)
  • Docs or links checked
  • Runtime/deployment command tested

User impact

Anyone training or fine-tuning with a non_linguistic_symbols file that ends with a blank line; data loading currently hangs without an error.

Notes for reviewers

The change is limited to dropping ""; all non-empty symbols behave as before.

CharTokenizer and PhonemeTokenizer load non_linguistic_symbols with
line.rstrip(), so a blank line in the symbol file (or an "" entry in a
list) adds the empty string to the set. line.startswith("") is true at
every position without consuming any input, so text2tokens never
terminates (and keeps appending "" tokens when symbols are kept).

Drop the empty string after the symbols are loaded and add a regression
test covering a file with a blank line and an iterable with "".
LauraGPT added a commit that referenced this pull request Nov 7, 2026
Preserve the original PR #3852 commit and add only missing trigger paths and regression selection.

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
LauraGPT added a commit that referenced this pull request Nov 7, 2026
Preserve the original contributor commit and add maintained regression coverage. No administrator bypass.

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
@LauraGPT
LauraGPT merged commit 5156f09 into modelscope:main Nov 7, 2026
LauraGPT added a commit that referenced this pull request Nov 8, 2026
Deliver empty-symbol tokenizer, padded variance normalization and mixed zero-fire CIF fixes (#3852, #3853, #3854). Checkpoints trained with mean and variance normalization need recognition-quality reevaluation.

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
@LauraGPT LauraGPT mentioned this pull request Nov 8, 2026
LauraGPT added a commit that referenced this pull request Nov 8, 2026
Deliver tested empty-symbol tokenizer, padded variance normalization and mixed zero-fire CIF fixes (#3852, #3853, #3854), with the variance-normalized checkpoint compatibility warning.

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
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