-
Notifications
You must be signed in to change notification settings - Fork 303
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 multidataset #1010
Merged
Merged
Add multidataset #1010
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
762b05f
Add Common Voice for multidataset
e75985d
Add prepare_multidataset.sh
dbf2e25
Add dataset mixing
28e4f38
Fix for black
3fff5dc
Fix for black
954e4d7
Update prepare_multidataset.sh
f98e121
Update prepare_multidataset.sh
ceef1cb
Update prepare_giga_speech.sh
0330cab
update comments
dddb9f7
Add split and shuffle mechanism
6646088
Add split and shuffle mechanism
80dd778
Merge branch 'k2-fsa:master' into multi
yfyeung a905dca
Add multidataset train
5af68c1
Fix for delete
a8bca53
Fix for modify
081d751
Add comments
69977a7
Change type for perturb_speed
f81d75f
Fix for style check
307eaa6
Small fix
eb4533f
Small fix
ebc6b97
Add filter
02d5231
Remove warning
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter | ||
from lhotse.recipes.utils import read_manifests_if_cached | ||
|
||
from icefall.utils import get_executor | ||
from icefall.utils import get_executor, str2bool | ||
|
||
# Torch's multithreaded behavior needs to be disabled or | ||
# it wastes a lot of CPU and slow things down. | ||
|
@@ -61,12 +61,20 @@ def get_args(): | |
help="""Dataset parts to compute fbank. If None, we will use all""", | ||
) | ||
|
||
parser.add_argument( | ||
"--perturb-speed", | ||
type=str2bool, | ||
default=True, | ||
help="""Perturb speed with factor 0.9 and 1.1 on train subset.""", | ||
) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def compute_fbank_librispeech( | ||
bpe_model: Optional[str] = None, | ||
dataset: Optional[str] = None, | ||
perturb_speed: Optional[bool] = True, | ||
): | ||
src_dir = Path("data/manifests") | ||
output_dir = Path("data/fbank") | ||
|
@@ -125,9 +133,13 @@ def compute_fbank_librispeech( | |
if "train" in partition: | ||
if bpe_model: | ||
cut_set = filter_cuts(cut_set, sp) | ||
cut_set = ( | ||
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1) | ||
) | ||
if perturb_speed: | ||
logging.info(f"Doing speed perturb") | ||
cut_set = ( | ||
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. Please add a log saying it is doing speed perturb. 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. ok |
||
cut_set | ||
+ cut_set.perturb_speed(0.9) | ||
+ cut_set.perturb_speed(1.1) | ||
) | ||
cut_set = cut_set.compute_and_store_features( | ||
extractor=extractor, | ||
storage_path=f"{output_dir}/{prefix}_feats_{partition}", | ||
|
@@ -145,4 +157,8 @@ def compute_fbank_librispeech( | |
logging.basicConfig(format=formatter, level=logging.INFO) | ||
args = get_args() | ||
logging.info(vars(args)) | ||
compute_fbank_librispeech(bpe_model=args.bpe_model, dataset=args.dataset) | ||
compute_fbank_librispeech( | ||
bpe_model=args.bpe_model, | ||
dataset=args.dataset, | ||
perturb_speed=args.perturb_speed, | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eou pipefail | ||
|
||
nj=16 | ||
stage=-1 | ||
stop_stage=100 | ||
|
||
# Split data/${lang}set to this number of pieces | ||
# This is to avoid OOM during feature extraction. | ||
num_splits=1000 | ||
|
||
# We assume dl_dir (download dir) contains the following | ||
# directories and files. If not, they will be downloaded | ||
# by this script automatically. | ||
# | ||
# - $dl_dir/$release/$lang | ||
# This directory contains the following files downloaded from | ||
# https://mozilla-common-voice-datasets.s3.dualstack.us-west-2.amazonaws.com/${release}/${release}-${lang}.tar.gz | ||
# | ||
# - clips | ||
# - dev.tsv | ||
# - invalidated.tsv | ||
# - other.tsv | ||
# - reported.tsv | ||
# - test.tsv | ||
# - train.tsv | ||
# - validated.tsv | ||
|
||
dl_dir=$PWD/download | ||
release=cv-corpus-13.0-2023-03-09 | ||
lang=en | ||
|
||
. shared/parse_options.sh || exit 1 | ||
|
||
# All files generated by this script are saved in "data/${lang}". | ||
# You can safely remove "data/${lang}" and rerun this script to regenerate it. | ||
mkdir -p data/${lang} | ||
|
||
log() { | ||
# This function is from espnet | ||
local fname=${BASH_SOURCE[1]##*/} | ||
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" | ||
} | ||
|
||
log "dl_dir: $dl_dir" | ||
|
||
if [ $stage -le 0 ] && [ $stop_stage -ge 0 ]; then | ||
log "Stage 0: Download data" | ||
|
||
# If you have pre-downloaded it to /path/to/$release, | ||
# you can create a symlink | ||
# | ||
# ln -sfv /path/to/$release $dl_dir/$release | ||
# | ||
if [ ! -d $dl_dir/$release/$lang/clips ]; then | ||
lhotse download commonvoice --languages $lang --release $release $dl_dir | ||
fi | ||
fi | ||
|
||
if [ $stage -le 1 ] && [ $stop_stage -ge 1 ]; then | ||
log "Stage 1: Prepare CommonVoice manifest" | ||
# We assume that you have downloaded the CommonVoice corpus | ||
# to $dl_dir/$release | ||
mkdir -p data/${lang}/manifests | ||
if [ ! -e data/${lang}/manifests/.cv-${lang}.done ]; then | ||
lhotse prepare commonvoice --language $lang -j $nj $dl_dir/$release data/${lang}/manifests | ||
touch data/${lang}/manifests/.cv-${lang}.done | ||
fi | ||
fi | ||
|
||
if [ $stage -le 2 ] && [ $stop_stage -ge 2 ]; then | ||
log "Stage 2: Preprocess CommonVoice manifest" | ||
if [ ! -e data/${lang}/fbank/.preprocess_complete ]; then | ||
./local/preprocess_commonvoice.py --language $lang | ||
touch data/${lang}/fbank/.preprocess_complete | ||
fi | ||
fi | ||
|
||
if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then | ||
log "Stage 3: Compute fbank for dev and test subsets of CommonVoice" | ||
mkdir -p data/${lang}/fbank | ||
if [ ! -e data/${lang}/fbank/.cv-${lang}_dev_test.done ]; then | ||
./local/compute_fbank_commonvoice_dev_test.py --language $lang | ||
touch data/${lang}/fbank/.cv-${lang}_dev_test.done | ||
fi | ||
fi | ||
|
||
if [ $stage -le 4 ] && [ $stop_stage -ge 4 ]; then | ||
log "Stage 4: Split train subset into ${num_splits} pieces" | ||
split_dir=data/${lang}/fbank/cv-${lang}_train_split_${num_splits} | ||
if [ ! -e $split_dir/.cv-${lang}_train_split.done ]; then | ||
lhotse split $num_splits ./data/${lang}/fbank/cv-${lang}_cuts_train_raw.jsonl.gz $split_dir | ||
touch $split_dir/.cv-${lang}_train_split.done | ||
fi | ||
fi | ||
|
||
if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then | ||
log "Stage 5: Compute features for train subset of CommonVoice" | ||
if [ ! -e data/${lang}/fbank/.cv-${lang}_train.done ]; then | ||
./local/compute_fbank_commonvoice_splits.py \ | ||
--num-workers $nj \ | ||
--batch-duration 600 \ | ||
--start 0 \ | ||
--num-splits $num_splits \ | ||
--language $lang | ||
touch data/${lang}/fbank/.cv-${lang}_train.done | ||
fi | ||
fi | ||
|
||
if [ $stage -le 6 ] && [ $stop_stage -ge 6 ]; then | ||
log "Stage 6: Combine features for train" | ||
if [ ! -f data/${lang}/fbank/cv-${lang}_cuts_train.jsonl.gz ]; then | ||
pieces=$(find data/${lang}/fbank/cv-${lang}_train_split_${num_splits} -name "cv-${lang}_cuts_train.*.jsonl.gz") | ||
lhotse combine $pieces data/${lang}/fbank/cv-${lang}_cuts_train.jsonl.gz | ||
fi | ||
fi |
This file contains 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
Oops, something went wrong.
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.
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.
Please use str2bool.
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.
ok