Skip to content

fix(asr): exclude <unk> token from language tag extraction - #113

Open
utkarshpatwa393-sys wants to merge 1 commit into
NVIDIA:mainfrom
utkarshpatwa393-sys:fix/asr-exclude-unk-from-lang-tags
Open

utkarshpatwa393-sys wants to merge 1 commit into
NVIDIA:mainfrom
utkarshpatwa393-sys:fix/asr-exclude-unk-from-lang-tags

Conversation

@utkarshpatwa393-sys

Copy link
Copy Markdown

Summary

Fixes #92.

In src/asr/runner.cpp, extract_lang_tags uses the regex pattern:

<([A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,4})?)>

Because <unk> has 3 alphabetic characters, it matches this pattern and is inadvertently extracted as a language code ("unk"). When this happens:

  1. "unk" is added to detected_languages_, polluting language_codes, CLI outputs, and REST responses.
  2. In auto mode, build_result_ may attempt to select an ITN grammar using "unk" instead of the genuine detected language.
  3. The <unk> token is stripped from the text output as if it were a language tag.

Changes

  • Explicitly exclude "unk" (case-insensitive) during language tag collection in extract_lang_tags.
  • Remove only the genuinely detected language tags from text, leaving <unk> tokens intact in the transcript.

The language tag regex pattern <([A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,4})?)>
matches three-letter tokens, causing <unk> from the tokenizer vocabulary
to be treated as language code "unk". This pollutes detected_languages,
corrupts ITN grammar selection in auto mode, and inadvertently strips
unknown tokens from the output transcript.

Filter out "unk" during tag extraction and only erase recognized
language tags from the transcript text.

Fixes NVIDIA#92

Signed-off-by: Utkarsh Patwa <utkarshpatwa393@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 23, 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.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Language tags marked as unknown are no longer included in extracted language results. Other tags retain their original spelling, and repeated exact tags are removed.

extract_lang_tags now excludes unk codes from detected languages, regardless of letter case. It removes exact tags for retained language codes, including repeated tags, and continues to collapse and trim whitespace.

Changes: Language tag parsing

Layer / File(s) Summary
Filter language tags and clean transcript
src/asr/runner.cpp
The parser skips codes that lowercase to unk. It removes exact tags only for retained language codes, including repeated occurrences. Whitespace normalization remains unchanged.

Possibly related PRs

  • NVIDIA/NeMo-Speech.cpp#91: This PR reports detected languages per utterance and word using the same language-tag extraction path.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 36ce0

This change stops <unk> from being reported as a detected language, from selecting an ITN grammar in auto mode, and from being stripped out of transcripts. The scope is a single parsing function, and no concrete merge-blocking risk was found.

Architecture risk: Medium · up to 36ce0

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/asr/runner.cpp: extract_lang_tags now compares a lowercase copy of each code to "unk" and omits matching tags from the returned languages.
  • observed — Modified behavior in src/asr/runner.cpp: The function now removes exact tags only for codes retained in langs, including repeated occurrences, instead of deleting every regex match; whitespace normalization remains unchanged.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Issue #92 requires that <unk> not be accepted or reported as a detected language, not used to select the ITN grammar in auto mode, and not stripped from the transcript as a language tag. The diff …
Out of Scope Changes check Passed The whole-PR diff against the merge base changes only src/asr/runner.cpp, inside extract_lang_tags. Every hunk serves issue #92. The lowercase comparison and the unk skip implement the exclusion…
Full details: Linked Issues check

Explanation

Issue #92 requires that &lt;unk&gt; not be accepted or reported as a detected language, not used to select the ITN grammar in auto mode, and not stripped from the transcript as a language tag. The diff to src/asr/runner.cpp in extract_lang_tags covers each point. (1) A lowercased code equal to unk is skipped before it reaches langs, so unk is not added to detected languages. (2) build_result_ reads the detected languages, so it does not receive unk. (3) Text removal iterates only over langs and erases exact &lt;code&gt; strings, so &lt;unk&gt; stays in the transcript. If only &lt;unk&gt; matches, langs is empty and the text is not changed. The issue's preferred prompt-dictionary approach is not used. The issue explicitly allows the smaller by-name exclusion as an alternative, and the code implements that alternative. The diff does not add an &lt;cctype&gt; include for std::tolower. This was not verified against the full file, so it is a minor build-time uncertainty. No automated test was added, and the issue does not request one.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes only src/asr/runner.cpp, inside extract_lang_tags. Every hunk serves issue #92. The lowercase comparison and the unk skip implement the exclusion. The exact-tag removal loop replaces the regex removal so that &lt;unk&gt; is not stripped. The whitespace collapse and trim lines are unchanged. No unrelated behavior change appears in the diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e790e46 and 36ce0d8.

Files selected for processing: 1

  • src/asr/runner.cpp

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: Greptile Review
Additional context used

Path-based instructions: 1

Apply every section of REVIEW.md, in its priority order.

CodeRabbit configuration file

Files:

  • src/asr/runner.cpp

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

extract_lang_tags now excludes <unk> in any letter case from detected languages and removes only collected language tags.

  • ASR transcripts keep <unk> without reporting it as a language.

Reviews (1) · Last reviewed commit: "fix(asr): exclude <unk> token from langu..." · Reviewed by Greptile

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ASR language tag parser accepts <unk> as a language

1 participant