Skip to content
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

Add hybrid model support to transcribe_speech_parallel.py #6906

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/asr/transcribe_speech_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
predict_ds.batch_size=16 \
output_path=/tmp/

Example for Hybrid-CTC/RNNT models with non-tarred datasets:

python transcribe_speech_parallel.py \
model=stt_en_fastconformer_hybrid_large \
decoder_type=ctc \
predict_ds.manifest_filepath=/dataset/manifest_file.json \
predict_ds.batch_size=16 \
output_path=/tmp/

Example for tarred datasets:

python transcribe_speech_parallel.py \
Expand Down Expand Up @@ -73,7 +82,7 @@
from nemo.collections.asr.data.audio_to_text_dataset import ASRPredictionWriter
from nemo.collections.asr.metrics.rnnt_wer import RNNTDecodingConfig
from nemo.collections.asr.metrics.wer import word_error_rate
from nemo.collections.asr.models import ASRModel
from nemo.collections.asr.models import ASRModel, EncDecHybridRNNTCTCModel
from nemo.collections.asr.models.configs.asr_models_config import ASRDatasetConfig
from nemo.core.config import TrainerConfig, hydra_runner
from nemo.utils import logging
Expand All @@ -92,6 +101,10 @@ class ParallelTranscriptionConfig:

# decoding strategy for RNNT models
rnnt_decoding: RNNTDecodingConfig = RNNTDecodingConfig()

# decoder for hybrid models, must be one of 'ctc', 'rnnt' if not None
decoder_type: Optional[str] = None

trainer: TrainerConfig = TrainerConfig(devices=-1, accelerator="gpu", strategy="ddp")


Expand Down Expand Up @@ -137,6 +150,9 @@ def main(cfg: ParallelTranscriptionConfig):
)
model = ASRModel.from_pretrained(model_name=cfg.model, map_location="cpu")

if isinstance(model, EncDecHybridRNNTCTCModel) and cfg.decoder_type is not None:
model.change_decoding_strategy(decoder_type=cfg.decoder_type)

trainer = ptl.Trainer(**cfg.trainer)

cfg.predict_ds.return_sample_id = True
Expand Down
1 change: 1 addition & 0 deletions nemo/collections/asr/data/audio_to_text_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ def write_on_batch_end(
item = {}
sample = self.dataset.get_manifest_sample(sample_id)
item["audio_filepath"] = sample.audio_file
item["offset"] = sample.offset
item["duration"] = sample.duration
item["text"] = sample.text_raw
item["pred_text"] = transcribed_text
Expand Down
Loading