fix(nemo): extract Hypothesis.text for TDT/RNNT ASR models#10012
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates transcript extraction logic in the NeMo backend to correctly handle different model output types (CTC strings vs. RNNT/TDT Hypothesis objects).
Changes:
- Adds type-aware handling for
results[0]to extract text from eitherstror an object with a.textattribute. - Improves inline documentation clarifying expected return types from different model families.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+108
to
+111
| elif hasattr(result, 'text'): | ||
| text = result.text if result.text else "" | ||
| else: | ||
| text = str(result) if result else "" |
Comment on lines
+110
to
+111
| else: | ||
| text = str(result) if result else "" |
CTC models (e.g. Whisper) return List[str] from transcribe(), but TDT/RNNT models (e.g. parakeet-tdt-0.6b-v3) return List[Hypothesis] where the decoded text lives in the Hypothesis.text attribute. Previously, results[0] was assigned directly to the protobuf string field, causing silent empty output for non-CTC models. Now checks the return type and extracts .text from Hypothesis objects, with a safe fallback via getattr().
Use single getattr() call instead of hasattr() + double access, and return empty string for unknown types instead of str(result) to avoid leaking internal repr to clients.
da11db9 to
2e07e48
Compare
mudler
approved these changes
May 26, 2026
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NeMo Parakeet TDT models (e.g.
parakeet-tdt-0.6b-v3) deployed via thenemobackend always produce empty transcription output.Root Cause
NeMo's
transcribe()returns different types depending on the model architecture:List[str]— works fineList[Hypothesis]— the decoded text lives in theHypothesis.textattributeThe backend code at
backend/python/nemo/backend.pyline 105 did:This assigned the entire
Hypothesisdataclass to the protobufstringfield. When protobuf tried to serialize it, it either raised aTypeError(caught by the except block → returns empty) or silently converted to an empty string. Either way, the transcript was always blank.Fix
Check the return type and extract
.textfromHypothesisobjects when present:This is backward-compatible — CTC models still return strings and take the first branch.
Testing
Verified by reading the NeMo source code:
nemo/collections/asr/parts/submodules/rnnt_decoding.py→rnnt_decoder_predictions_tensor()always returnsList[Hypothesis]even whenreturn_hypotheses=Falsenemo/collections/asr/models/rnnt_models.py→_transcribe_output_processing()passes this through unchanged