Skip to content

Commit

Permalink
Merge pull request espnet#4330 from pyf98/show_translation_result
Browse files Browse the repository at this point in the history
Update show_translation_result.sh to show all decoding results under the given exp directory
  • Loading branch information
sw005320 authored May 6, 2022
2 parents 4f41a1a + 6d06728 commit 793b999
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
23 changes: 13 additions & 10 deletions egs2/TEMPLATE/asr1/scripts/utils/show_translation_result.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
mindepth=0
maxdepth=3
maxdepth=1
case=tc

. utils/parse_options.sh
Expand Down Expand Up @@ -44,24 +44,27 @@ cat << EOF
EOF

# only show BLEU score for now
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
for type in ${metrics}; do
cat << EOF
### ${type^^}
|dataset|bleu_score|verbose_score|
|dataset|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}"

for result in "${expdir}"/*/*/score_"${type}"/result."${case}".txt; do
inference_tag=$(echo "${result}" | rev | cut -d/ -f4 | rev)
test_set=$(echo "${result}" | rev | cut -d/ -f3 | rev)
score=$(sed -n '5p' "${result}" | cut -d ' ' -f 3 | tr -d ',')
verbose=$(sed -n '7p' "${result}" | cut -d ' ' -f 3- | tr -d '",')
echo "|${inference_tag}/${test_set}|${score}|${verbose}|"
done
done
fi

done < <(find ${exp} -mindepth ${mindepth} -maxdepth ${maxdepth} -type d)
6 changes: 3 additions & 3 deletions egs2/TEMPLATE/mt1/mt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ if ! "${skip_eval}"; then
detokenizer.perl -l ${tgt_lang} -q < "${_scoredir}/hyp.trn" > "${_scoredir}/hyp.trn.detok"

if [ ${tgt_case} = "tc" ]; then
echo "Case sensitive BLEU result (single-reference)" >> ${_scoredir}/result.tc.txt
echo "Case sensitive BLEU result (single-reference)" > ${_scoredir}/result.tc.txt
sacrebleu "${_scoredir}/ref.trn.detok" \
-i "${_scoredir}/hyp.trn.detok" \
-m bleu chrf ter \
Expand All @@ -1227,7 +1227,7 @@ if ! "${skip_eval}"; then
# detokenize & remove punctuation except apostrophe
remove_punctuation.pl < "${_scoredir}/ref.trn.detok" > "${_scoredir}/ref.trn.detok.lc.rm"
remove_punctuation.pl < "${_scoredir}/hyp.trn.detok" > "${_scoredir}/hyp.trn.detok.lc.rm"
echo "Case insensitive BLEU result (single-reference)" >> ${_scoredir}/result.lc.txt
echo "Case insensitive BLEU result (single-reference)" > ${_scoredir}/result.lc.txt
sacrebleu -lc "${_scoredir}/ref.trn.detok.lc.rm" \
-i "${_scoredir}/hyp.trn.detok.lc.rm" \
-m bleu chrf ter \
Expand Down Expand Up @@ -1279,7 +1279,7 @@ if ! "${skip_eval}"; then

# Show results in Markdown syntax
scripts/utils/show_translation_result.sh --case $tgt_case "${mt_exp}" > "${mt_exp}"/RESULTS.md
cat "${cat_exp}"/RESULTS.md
cat "${mt_exp}"/RESULTS.md
fi
else
log "Skip the evaluation stages"
Expand Down
4 changes: 2 additions & 2 deletions egs2/iwslt14/mt1/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tgt_lang=en

train_set=train
train_dev=valid
test_set="test valid"
test_sets="test valid"

mt_config=conf/train_mt_transformer.yaml
inference_config=conf/decode_mt.yaml
Expand Down Expand Up @@ -45,7 +45,7 @@ tgt_case=tc
--inference_config "${inference_config}" \
--train_set "${train_set}" \
--valid_set "${train_dev}" \
--test_sets "${test_set}" \
--test_sets "${test_sets}" \
--src_bpe_train_text "data/${train_set}/text.${src_case}.${src_lang}" \
--tgt_bpe_train_text "data/${train_set}/text.${tgt_case}.${tgt_lang}" \
--lm_train_text "data/${train_set}/text.${tgt_case}.${tgt_lang}" "$@"

0 comments on commit 793b999

Please sign in to comment.