Skip to content

Commit

Permalink
Merge pull request espnet#4149 from brianyan918/fix_st_bug
Browse files Browse the repository at this point in the history
fix bug in mt/st templates for having separate token lists
  • Loading branch information
sw005320 authored Apr 12, 2022
2 parents ff7c051 + eefbe01 commit 952a70a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
67 changes: 67 additions & 0 deletions egs2/TEMPLATE/asr1/scripts/utils/show_translation_result.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
mindepth=0
maxdepth=3
case=tc

. utils/parse_options.sh

if [ $# -gt 1 ]; then
echo "Usage: $0 --mindepth 0 --maxdepth 1 [exp]" 1>&2
echo ""
echo "Show the system environments and the evaluation results in Markdown format."
echo 'The default of <exp> is "exp/".'
exit 1
fi

[ -f ./path.sh ] && . ./path.sh
set -euo pipefail
if [ $# -eq 1 ]; then
exp=$1
else
exp=exp
fi


cat << EOF
<!-- Generated by $0 -->
# RESULTS
## Environments
- date: \`$(LC_ALL=C date)\`
EOF

python3 << EOF
import sys, espnet, torch
pyversion = sys.version.replace('\n', ' ')
print(f"""- python version: \`{pyversion}\`
- espnet version: \`espnet {espnet.__version__}\`
- pytorch version: \`pytorch {torch.__version__}\`""")
EOF

cat << EOF
- Git hash: \`$(git rev-parse HEAD)\`
- Commit date: \`$(git log -1 --format='%cd')\`
EOF

metrics="bleu"

while IFS= read -r expdir; do
if ls "${expdir}"/*/*/score_*/result.${case}.txt &> /dev/null; then
echo "## $(basename ${expdir})"
for type in $metrics; do
cat << EOF
### ${type^^}
|dataset|bleu_score|verbose_score|
|---|---|---|
EOF
data=$(echo "${expdir}"/*/*/score_*/result.${case}.txt | cut -d '/' -f4)
bleu=$(sed -n '5p' "${expdir}"/*/*/score_*/result.${case}.txt | cut -d ' ' -f 3 | tr -d ',')
verbose=$(sed -n '7p' "${expdir}"/*/*/score_*/result.${case}.txt | cut -d ' ' -f 3- | tr -d '",')
echo "${data}|${bleu}|${verbose}"

done
fi

done < <(find ${exp} -mindepth ${mindepth} -maxdepth ${maxdepth} -type d)
2 changes: 1 addition & 1 deletion egs2/TEMPLATE/mt1/mt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ if "${token_joint}"; then
src_bpetoken_list="${tgt_bpetoken_list}"
src_chartoken_list="${tgt_chartoken_list}"
else
src_bpedir="${token_listdir}/src_bpe_${tgt_bpemode}${tgt_nbpe}"
src_bpedir="${token_listdir}/src_bpe_${src_bpemode}${src_nbpe}"
src_bpeprefix="${src_bpedir}"/bpe
src_bpemodel="${src_bpeprefix}".model
src_bpetoken_list="${src_bpedir}"/tokens.txt
Expand Down
2 changes: 1 addition & 1 deletion egs2/TEMPLATE/st1/st.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ if "${token_joint}"; then
src_bpetoken_list="${tgt_bpetoken_list}"
src_chartoken_list="${tgt_chartoken_list}"
else
src_bpedir="${token_listdir}/src_bpe_${tgt_bpemode}${tgt_nbpe}"
src_bpedir="${token_listdir}/src_bpe_${src_bpemode}${src_nbpe}"
src_bpeprefix="${src_bpedir}"/bpe
src_bpemodel="${src_bpeprefix}".model
src_bpetoken_list="${src_bpedir}"/tokens.txt
Expand Down
8 changes: 6 additions & 2 deletions espnet2/st/espnet_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def __init__(
# note that eos is the same as sos (equivalent ID)
self.sos = vocab_size - 1
self.eos = vocab_size - 1
self.src_sos = src_vocab_size - 1
self.src_eos = src_vocab_size - 1
self.vocab_size = vocab_size
self.src_vocab_size = src_vocab_size
self.ignore_id = ignore_id
Expand Down Expand Up @@ -409,7 +411,9 @@ def _calc_asr_att_loss(
ys_pad: torch.Tensor,
ys_pad_lens: torch.Tensor,
):
ys_in_pad, ys_out_pad = add_sos_eos(ys_pad, self.sos, self.eos, self.ignore_id)
ys_in_pad, ys_out_pad = add_sos_eos(
ys_pad, self.src_sos, self.src_eos, self.ignore_id
)
ys_in_lens = ys_pad_lens + 1

# 1. Forward decoder
Expand All @@ -420,7 +424,7 @@ def _calc_asr_att_loss(
# 2. Compute attention loss
loss_att = self.criterion_asr(decoder_out, ys_out_pad)
acc_att = th_accuracy(
decoder_out.view(-1, self.vocab_size),
decoder_out.view(-1, self.src_vocab_size),
ys_out_pad,
ignore_label=self.ignore_id,
)
Expand Down

0 comments on commit 952a70a

Please sign in to comment.