-
Notifications
You must be signed in to change notification settings - Fork 1
Add NeMo Conformer RNNT support for character-level tokenizers #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4-nemo-conformer-tdt-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,49 @@ export function buildTransducerDetailedOutputs(tokenizer, token_ids, token_times | |
|
|
||
| finalizeAndPushWord(words, current); | ||
|
|
||
| // Fallback for character-level tokenizers (e.g., Danish RNNT) where individual | ||
| // tokens lack ▁/Ġ word-start markers. Decode the full sequence to get the text | ||
| // with proper spaces, then use those spaces to detect word boundaries. | ||
| if (words.length <= 1 && tokens.length > 1) { | ||
| const fullDecoded = tokenizer | ||
| .decode(token_ids, { skip_special_tokens: true, clean_up_tokenization_spaces: false }) | ||
| .trimStart(); | ||
|
|
||
| words.length = 0; | ||
| current = null; | ||
| let pos = 0; | ||
|
|
||
| for (let j = 0; j < tokens.length; j++) { | ||
| let foundSpace = false; | ||
| while (pos < fullDecoded.length && /\s/.test(fullDecoded[pos])) { | ||
| foundSpace = true; | ||
| pos++; | ||
| } | ||
|
|
||
| const startsNewWord = j === 0 || foundSpace; | ||
| tokens[j].is_word_start = startsNewWord; | ||
| pos = Math.min(pos + tokens[j].token.length, fullDecoded.length); | ||
|
|
||
| if (!current || startsNewWord) { | ||
| finalizeAndPushWord(words, current); | ||
| current = { | ||
| text: tokens[j].token, | ||
| start: tokens[j].start_time, | ||
| end: tokens[j].end_time, | ||
| confs: tokens[j].confidence != null ? [tokens[j].confidence] : [], | ||
| }; | ||
| } else { | ||
| current.text += tokens[j].token; | ||
| current.end = tokens[j].end_time; | ||
| if (tokens[j].confidence != null) { | ||
| current.confs.push(tokens[j].confidence); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| finalizeAndPushWord(words, current); | ||
| } | ||
|
Comment on lines
+173
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new fallback block introduces significant code duplication. The logic for building words by creating or extending the To improve maintainability and avoid redundancy, I recommend refactoring this duplicated logic into a separate helper function. This function could take the |
||
|
|
||
| const word_confidences = words.some((x) => x.confidence != null) ? words.map((x) => x.confidence ?? null) : null; | ||
| let word_avg = null; | ||
| if (word_confidences) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Dependency on dev version
Updating
onnxruntime-nodefrom stable1.24.2to1.25.0-dev.20260228-6e72d31970introduces a pre-release/dev version dependency. This could:Consider pinning to a stable release version instead.