Skip to content

Commit

Permalink
Merge pull request espnet#4300 from ftshijt/master
Browse files Browse the repository at this point in the history
CoVOST2 recipes
  • Loading branch information
sw005320 authored Apr 22, 2022
2 parents 3d84d3c + 0eaf243 commit f6a2522
Show file tree
Hide file tree
Showing 70 changed files with 1,203 additions and 12 deletions.
25 changes: 13 additions & 12 deletions egs2/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions egs2/covost2/asr1/asr.sh
110 changes: 110 additions & 0 deletions egs2/covost2/asr1/cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ====== About run.pl, queue.pl, slurm.pl, and ssh.pl ======
# Usage: <cmd>.pl [options] JOB=1:<nj> <log> <command...>
# e.g.
# run.pl --mem 4G JOB=1:10 echo.JOB.log echo JOB
#
# Options:
# --time <time>: Limit the maximum time to execute.
# --mem <mem>: Limit the maximum memory usage.
# -–max-jobs-run <njob>: Limit the number parallel jobs. This is ignored for non-array jobs.
# --num-threads <ngpu>: Specify the number of CPU core.
# --gpu <ngpu>: Specify the number of GPU devices.
# --config: Change the configuration file from default.
#
# "JOB=1:10" is used for "array jobs" and it can control the number of parallel jobs.
# The left string of "=", i.e. "JOB", is replaced by <N>(Nth job) in the command and the log file name,
# e.g. "echo JOB" is changed to "echo 3" for the 3rd job and "echo 8" for 8th job respectively.
# Note that the number must start with a positive number, so you can't use "JOB=0:10" for example.
#
# run.pl, queue.pl, slurm.pl, and ssh.pl have unified interface, not depending on its backend.
# These options are mapping to specific options for each backend and
# it is configured by "conf/queue.conf" and "conf/slurm.conf" by default.
# If jobs failed, your configuration might be wrong for your environment.
#
#
# The official documentation for run.pl, queue.pl, slurm.pl, and ssh.pl:
# "Parallelization in Kaldi": http://kaldi-asr.org/doc/queue.html
# =========================================================~


# Select the backend used by run.sh from "local", "stdout", "sge", "slurm", or "ssh"
cmd_backend='local'

# Local machine, without any Job scheduling system
if [ "${cmd_backend}" = local ]; then

# The other usage
export train_cmd="run.pl"
# Used for "*_train.py": "--gpu" is appended optionally by run.sh
export cuda_cmd="run.pl"
# Used for "*_recog.py"
export decode_cmd="run.pl"

# Local machine logging to stdout and log file, without any Job scheduling system
elif [ "${cmd_backend}" = stdout ]; then

# The other usage
export train_cmd="stdout.pl"
# Used for "*_train.py": "--gpu" is appended optionally by run.sh
export cuda_cmd="stdout.pl"
# Used for "*_recog.py"
export decode_cmd="stdout.pl"


# "qsub" (Sun Grid Engine, or derivation of it)
elif [ "${cmd_backend}" = sge ]; then
# The default setting is written in conf/queue.conf.
# You must change "-q g.q" for the "queue" for your environment.
# To know the "queue" names, type "qhost -q"
# Note that to use "--gpu *", you have to setup "complex_value" for the system scheduler.

export train_cmd="queue.pl"
export cuda_cmd="queue.pl"
export decode_cmd="queue.pl"


# "qsub" (Torque/PBS.)
elif [ "${cmd_backend}" = pbs ]; then
# The default setting is written in conf/pbs.conf.

export train_cmd="pbs.pl"
export cuda_cmd="pbs.pl"
export decode_cmd="pbs.pl"


# "sbatch" (Slurm)
elif [ "${cmd_backend}" = slurm ]; then
# The default setting is written in conf/slurm.conf.
# You must change "-p cpu" and "-p gpu" for the "partition" for your environment.
# To know the "partion" names, type "sinfo".
# You can use "--gpu * " by default for slurm and it is interpreted as "--gres gpu:*"
# The devices are allocated exclusively using "${CUDA_VISIBLE_DEVICES}".

export train_cmd="slurm.pl"
export cuda_cmd="slurm.pl"
export decode_cmd="slurm.pl"

elif [ "${cmd_backend}" = ssh ]; then
# You have to create ".queue/machines" to specify the host to execute jobs.
# e.g. .queue/machines
# host1
# host2
# host3
# Assuming you can login them without any password, i.e. You have to set ssh keys.

export train_cmd="ssh.pl"
export cuda_cmd="ssh.pl"
export decode_cmd="ssh.pl"

# This is an example of specifying several unique options in the JHU CLSP cluster setup.
# Users can modify/add their own command options according to their cluster environments.
elif [ "${cmd_backend}" = jhu ]; then

export train_cmd="queue.pl --mem 2G"
export cuda_cmd="queue-freegpu.pl --mem 2G --gpu 1 --config conf/queue.conf"
export decode_cmd="queue.pl --mem 4G"

else
echo "$0: Error: Unknown cmd_backend=${cmd_backend}" 1>&2
return 1
fi
1 change: 1 addition & 0 deletions egs2/covost2/asr1/conf/decode_asr.yaml
2 changes: 2 additions & 0 deletions egs2/covost2/asr1/conf/fbank.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sample-frequency=16000
--num-mel-bins=80
11 changes: 11 additions & 0 deletions egs2/covost2/asr1/conf/pbs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default configuration
command qsub -V -v PATH -S /bin/bash
option name=* -N $0
option mem=* -l mem=$0
option mem=0 # Do not add anything to qsub_opts
option num_threads=* -l ncpus=$0
option num_threads=1 # Do not add anything to qsub_opts
option num_nodes=* -l nodes=$0:ppn=1
default gpu=0
option gpu=0
option gpu=* -l ngpus=$0
1 change: 1 addition & 0 deletions egs2/covost2/asr1/conf/pitch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sample-frequency=16000
12 changes: 12 additions & 0 deletions egs2/covost2/asr1/conf/queue.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Default configuration
command qsub -v PATH -cwd -S /bin/bash -j y -l arch=*64*
option name=* -N $0
option mem=* -l mem_free=$0,ram_free=$0
option mem=0 # Do not add anything to qsub_opts
option num_threads=* -pe smp $0
option num_threads=1 # Do not add anything to qsub_opts
option max_jobs_run=* -tc $0
option num_nodes=* -pe mpi $0 # You must set this PE as allocation_rule=1
default gpu=0
option gpu=0
option gpu=* -l gpu=$0 -q g.q
14 changes: 14 additions & 0 deletions egs2/covost2/asr1/conf/slurm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default configuration
command sbatch --export=PATH
option name=* --job-name $0
option time=* --time $0
option mem=* --mem-per-cpu $0
option mem=0
option num_threads=* --cpus-per-task $0
option num_threads=1 --cpus-per-task 1
option num_nodes=* --nodes $0
default gpu=0
option gpu=0 -p cpu
option gpu=* -p gpu --gres=gpu:$0 -c $0 # Recommend allocating more CPU than, or equal to the number of GPU
# note: the --max-jobs-run option is supported as a special case
# by slurm.pl and you don't have to handle it in the config file.
1 change: 1 addition & 0 deletions egs2/covost2/asr1/conf/train_asr.yaml
14 changes: 14 additions & 0 deletions egs2/covost2/asr1/conf/train_lm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
lm_conf:
nlayers: 2
unit: 650
optim: sgd # or adam
batch_type: folded
batch_size: 64 # batch size in LM training
max_epoch: 20 # if the data size is large, we can reduce this
patience: 3

best_model_criterion:
- - valid
- loss
- min
keep_nbest_models: 1
7 changes: 7 additions & 0 deletions egs2/covost2/asr1/conf/tuning/decode_transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
batch_size: 1
beam_size: 10
penalty: 0.0
maxlenratio: 0.0
minlenratio: 0.0
ctc_weight: 0.5
lm_weight: 0.3
52 changes: 52 additions & 0 deletions egs2/covost2/asr1/conf/tuning/train_asr_transformer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# network architecture
# encoder related
encoder: transformer
encoder_conf:
input_layer: "conv2d"
num_blocks: 12
linear_units: 2048
dropout_rate: 0.1
output_size: 256 # dimension of attention
attention_heads: 4
attention_dropout_rate: 0.0

# decoder related
# decoder related
decoder: transformer
decoder_conf:
input_layer: "embed"
num_blocks: 6
linear_units: 2048
dropout_rate: 0.1

# hybrid CTC/attention
model_conf:
ctc_weight: 0.3
lsm_weight: 0.1
length_normalized_loss: false

# minibatch related
batch_type: folded
batch_size: 32

# optimization related
optim: adam
accum_grad: 2
grad_clip: 5
patience: 0
max_epoch: 100
optim_conf:
lr: 1.0
scheduler: noamlr
scheduler_conf:
warmup_steps: 25000

# others:
best_model_criterion:
- - valid
- acc
- max
keep_nbest_models: 10

init: xavier_uniform # Our empirical studies shows that this initialization
# is very important to low-resource ASR training
1 change: 1 addition & 0 deletions egs2/covost2/asr1/db.sh
84 changes: 84 additions & 0 deletions egs2/covost2/asr1/local/data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

# Copyright 2021 Carnegie Mellon University (Jiatong Shi)
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

. ./path.sh || exit 1;
. ./cmd.sh || exit 1;
. ./db.sh || exit 1;

# general configuration
stage=0 # start from 0 if you need to start from data preparation
stop_stage=100
SECONDS=0
src_lang=es
tgt_lang=en

. utils/parse_options.sh || exit 1;


log() {
local fname=${BASH_SOURCE[1]##*/}
echo -e "$(date '+%Y-%m-%dT%H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
}

if [ -z "${COVOST2}" ]; then
log "Fill the value of 'COVOST2' of db.sh"
exit 1
fi
mkdir -p ${COVOST2}

if [ -z "${COMMONVOICE}" ]; then
log "Fill the value of 'COMMONVOICE' of db.sh"
exit 1
fi
mkdir -p ${COMMONVOICE}

# Set bash to 'debug' mode, it will exit on :
# -e 'error', -u 'undefined variable', -o ... 'error in pipeline', -x 'print commands',
set -e
set -u
set -o pipefail



if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
log "stage 0: Data Downloading"

# base url for downloads.
data_url=https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-4-2019-12-10/${src_lang}.tar.gz

# Download CommonVoice
mkdir -p ${COMMONVOICE}/${src_lang}
local/download_and_untar_commonvoice.sh ${COMMONVOICE}/${src_lang} ${data_url} ${src_lang}.tar.gz

# Download translation
if [[ ${src_lang} != en ]]; then
wget --no-check-certificate https://dl.fbaipublicfiles.com/covost/covost_v2.${src_lang}_${tgt_lang}.tsv.tar.gz \
-P ${COVOST2}
tar -xzf ${COVOST2}/covost_v2.${src_lang}_${tgt_lang}.tsv.tar.gz -C ${COVOST2}
fi
wget --no-check-certificate https://dl.fbaipublicfiles.com/covost/covost2.zip \
-P ${COVOST2}
unzip ${COVOST2}/covost2.zip -d ${COVOST2}
# NOTE: some non-English target languages lack translation from English
fi

if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
log "stage 1: Data Preparation"
# use underscore-separated names in data directories.
local/data_prep_commonvoice.pl "${COMMONVOICE}/${src_lang}" validated data/validated.${src_lang}

# text preprocessing (tokenization, case, punctuation marks etc.)
local/data_prep_covost2.sh ${COVOST2} ${src_lang} ${tgt_lang} || exit 1;
# NOTE: train/dev/test splits are different from original CommonVoice
fi

if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
log "stage 2: ASR Adaptation"
for x in train dev test; do
cp data/${x}.${src_lang}-${tgt_lang}/text.lc.rm.${src_lang} data/${x}.${src_lang}-${tgt_lang}/text
done
fi

log "Successfully finished. [elapsed=${SECONDS}s]"
1 change: 1 addition & 0 deletions egs2/covost2/asr1/local/data_prep_commonvoice.pl
1 change: 1 addition & 0 deletions egs2/covost2/asr1/local/data_prep_covost2.sh
1 change: 1 addition & 0 deletions egs2/covost2/asr1/local/download_and_untar_commonvoice.sh
Empty file added egs2/covost2/asr1/local/path.sh
Empty file.
1 change: 1 addition & 0 deletions egs2/covost2/asr1/local/process_tsv.py
1 change: 1 addition & 0 deletions egs2/covost2/asr1/path.sh
1 change: 1 addition & 0 deletions egs2/covost2/asr1/pyscripts
Loading

0 comments on commit f6a2522

Please sign in to comment.