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

Online Code Switching Dataset for ASR #6579

Merged
merged 23 commits into from
Jun 27, 2023
Merged

Conversation

trias702
Copy link
Collaborator

@trias702 trias702 commented May 5, 2023

What does this PR do ?

Adds an IterableDataset class which generates on-the-fly code switched utterances for ASR

Collection: ASR

Changelog

  • nemo/collections/asr/data/audio_to_text.py: added language support to the BPE classes to support code-switching

  • nemo/collections/asr/data/audio_to_text_dataset.py: added the core create_cs_dataset function and various instantiation logic

  • nemo/collections/common/data/__init__.py: exposed new CodeSwitchedDataset class

  • nemo/collections/common/data/dataset.py: contains new CodeSwitchedDataset class

  • nemo/collections/common/parts/preprocessing/collections.py: added discrete language support of the TokeniserWrapper via a hasattr check

  • nemo/collections/asr/models/*: changed all of the models to check for IterableDataset instead of reading the is_tarred config item, as I think this makes it more robust

Usage

There are many different permutations to using this new dataset, but a basic example shows how to add it to an existing training config yaml. To understand what each parameter does, please look at the class doc for the CodeSwitchedDataset class in nemo.collections.common.data.dataset.

++model.train_ds.manifest_filepath=[/path/to/en/tarred_manifest.json,/path/to/de/tarred_manifest.json,/path/to/ja/tarred_manifest.json]
++model.train_ds.tarred_audio_filepaths=['/path/to/en/tars/audio__OP_0..511_CL_.tar','/path/to/de/tars/audio__OP_0..1023_CL_.tar', '/path/to/ja/tars/audio__OP_0..2047_CL_.tar']
++model.train_ds.is_code_switched=true
++model.train_ds.is_tarred=true
++model.train_ds.shuffle=true
++model.train_ds.code_switched.min_duration=12
++model.train_ds.code_switched.max_duration=20
++model.train_ds.code_switched.min_monolingual=0.3
++model.train_ds.code_switched.probs=[0.25, 0.5, 0.25]
++model.train_ds.code_switched.force_monochannel=true
++model.train_ds.code_switched.sampling_scales=[0.75, 1, 0.25]
++model.validation_ds.manifest_filepath=[[/path/to/en/non-tarred/manifest.json, /path/to/de/non-tarred/manifest.json, /path/to/ja/non-tarred/manifest.json]]
++model.validation_ds.is_code_switched=true
++model.validation_ds.is_tarred=false \
++model.validation_ds.code_switched.min_duration=6
++model.validation_ds.code_switched.max_duration=20
++model.validation_ds.code_switched.min_monolingual=0.3
++model.validation_ds.code_switched.probs=[0.33, 0.34, 0.33]
++model.validation_ds.code_switched.force_monochannel=true
++model.validation_ds.code_switched.sampling_scales=1
~model.tokenizer
++model.tokenizer.type=agg
++model.tokenizer.langs.en.dir=/path/to/en/tokeniser
++model.tokenizer.langs.en.type=bpe
++model.tokenizer.langs.de.dir=/path/to/de/tokeniser
++model.tokenizer.langs.de.type=bpe
++model.tokenizer.langs.ja.dir=/path/to/ja/tokeniser
++model.tokenizer.langs.ja.type=bpe

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@github-actions
Copy link
Contributor

github-actions bot commented Jun 3, 2023

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Jun 3, 2023
@trias702 trias702 removed the stale label Jun 8, 2023
@trias702
Copy link
Collaborator Author

trias702 commented Jun 8, 2023

Can someone please review this PR for merging? We really need this functionality for Riva work.

@KunalDhawan
Copy link
Collaborator

Great work @trias702! Added a few minor comments but overall the implementation looks good. @bmwshop for final review.

Copy link
Collaborator

@titu1994 titu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the pr needs some documentation (inline as well as in NeMo Docs) and checks.
Core logic of dataset, ill leave to others to review

nemo/collections/asr/data/audio_to_text_dataset.py Outdated Show resolved Hide resolved
nemo/collections/common/data/dataset.py Show resolved Hide resolved
nemo/collections/common/data/dataset.py Show resolved Hide resolved
nemo/collections/common/data/dataset.py Show resolved Hide resolved
nemo/collections/common/data/dataset.py Show resolved Hide resolved
# import here to avoid circular import error
from nemo.collections.asr.parts.preprocessing import AudioSegment

mb = io.BytesIO()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be super slow right? Better to just not allow augmentation here then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is the part where we apply the augmentor to the final, synthetic utterance only, and why we always pass Augmentor=None to the individual language sub-datasets. We want all the individual samples from the individual mono-languages to be clean, and then we build the clean synthetic, and then we hit that final synthetic with the augmentation.

As for the logic, it's all in-memory operations with io.BytesIO, nothing is actually being written to disk. I have done several training runs with online CS and augmentation, and it doesn't slow it down by much at all, still very much usable.

There's sadly no way around it, we need to do augmentation on the final, full synthetic sample because many augmentations depend on features of the full waveform to work correctly (for example the new NormPerturbation).

for dataset_idx, (tarred_audio_filepath, manifest_filepath) in enumerate(
zip(tarred_audio_filepaths, manifest_filepaths)
):
lang = config['code_switch_languages'][dataset_idx]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the a manifest contains LID information and we pass LIDs here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a problem, because LIDs in the manifest always take precedence, you can see that here:

The new language parameter is only used as a fallback IFF using AggTokeniser and the manifest has no LID in the manifest.

@trias702 trias702 requested a review from bmwshop June 13, 2023 22:41
@KunalDhawan KunalDhawan self-requested a review June 26, 2023 23:34
KunalDhawan
KunalDhawan previously approved these changes Jun 26, 2023
Copy link
Collaborator

@KunalDhawan KunalDhawan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @trias702, LGTM!

@trias702 trias702 merged commit 92c4a2a into NVIDIA:main Jun 27, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants