Commit 982612c5 authored by Ho Yin Chan's avatar Ho Yin Chan
Browse files

trunk/egs/hkust: add alternative chinese character scoring scripts

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@2746 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent ab0e5be4
This diff is collapsed.
#!/usr/bin/perl
# Copyright Hong Kong University of Science and Technology (Author: Ricky Chan) 2013.
#
# A script to convert Kaldi Chinese word transcription to Chinese character transcription using a word2char mapping (e.g. a word2char_map likes "195k_chinese_word2char_map")
# This is helpful for Chinese character word error rate scoring
if($#ARGV+1 != 2) {
print "usage: perl hkust_word2char_tran.pl chinese_word2char_map tran_file \n";
exit;
}
$word2charfile=$ARGV[0];
$tranfile=$ARGV[1];
%word2charlist=();
open(INFILE, $word2charfile) || die("Can't open chinese word to char map: ".$word2charfile."\n");
while(<INFILE>){
chomp;
@line=split(/\s+/);
$a=$line[0];
$b="";
for($i=1; $i<scalar(@line); $i++) {
$b=$b . " " . $line[$i];
}
$word2charlist{$a}=$b;
}
close(INFILE);
open(INFILE, $tranfile) || die("Can't open transcription file ".$tranfile."\n");
while(<INFILE>) {
chomp;
@line = split(/\s+/);
## utt_id
print $line[0];
## utt_character_word
for($i=1; $i<scalar(@line); $i++) {
if(!exists($word2charlist{$line[$i]})) {
print " ".$line[$i];
}
else {
print $word2charlist{$line[$i]};
}
}
print "\n";
}
close(INFILE);
#!/bin/bash
# Copyright Johns Hopkins University (Author: Daniel Povey) 2012-2013.
# Hong Kong University of Science and Technology (Ricky Chan) 2013. Apache 2.0.
orig_args=
for x in "$@"; do orig_args="$orig_args '$x'"; done
# begin configuration section. we include all the options that score_sclite.sh or
# score_basic.sh might need, or parse_options.sh will die.
cmd=run.pl
stage=0
min_lmwt=5
max_lmwt=20
#end configuration section.
[ -f ./path.sh ] && . ./path.sh
. parse_options.sh || exit 1;
if [ $# -ne 3 ]; then
echo "Usage: local/score.sh [options] <data-dir> <lang-dir|graph-dir> <decode-dir>" && exit;
echo " Options:"
echo " --cmd (run.pl|queue.pl...) # specify how to run the sub-processes."
echo " --stage (0|1|2) # start scoring script from part-way through."
echo " --min_lmwt <int> # minumum LM-weight for lattice rescoring "
echo " --max_lmwt <int> # maximum LM-weight for lattice rescoring "
exit 1;
fi
data=$1
if [ -f $data/stm ]; then # use sclite scoring.
echo "$data/stm exists: using local/score_sclite.sh"
eval local/score_sclite.sh $orig_args
else
echo "$data/stm does not exist: using local/ext/score_basic_ext.sh"
eval local/ext/score_basic_ext.sh $orig_args
fi
#!/bin/bash
# Copyright Johns Hopkins University (Author: Daniel Povey) 2012-2013.
# Hong Kong University of Science and Technology (Ricky Chan). Apache 2.0.
# begin configuration section.
cmd=run.pl
min_lmwt=9
max_lmwt=20
#end configuration section.
[ -f ./path.sh ] && . ./path.sh
. parse_options.sh || exit 1;
if [ $# -ne 3 ]; then
echo "Usage: local/score_basic.sh [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
echo " Options:"
echo " --cmd (run.pl|queue.pl...) # specify how to run the sub-processes."
echo " --min_lmwt <int> # minumum LM-weight for lattice rescoring "
echo " --max_lmwt <int> # maximum LM-weight for lattice rescoring "
exit 1;
fi
data=$1
lang=$2 # Note: may be graph directory not lang directory, but has the necessary stuff copied.
dir=$3
model=$dir/../final.mdl # assume model one level up from decoding dir.
hubscr=$KALDI_ROOT/tools/sctk-2.4.0/bin/hubscr.pl
[ ! -f $hubscr ] && echo "Cannot find scoring program at $hubscr" && exit 1;
hubdir=`dirname $hubscr`
for f in $data/text $lang/words.txt $dir/lat.1.gz; do
[ ! -f $f ] && echo "$0: expecting file $f to exist" && exit 1;
done
name=`basename $data`; # e.g. eval2000
mkdir -p $dir/scoring/log
function filter_text {
perl -e 'foreach $w (@ARGV) { $bad{$w} = 1; }
while(<STDIN>) { @A = split(" ", $_); $id = shift @A; print "$id ";
foreach $a (@A) { if (!defined $bad{$a}) { print "$a "; }} print "\n"; }' \
'[NOISE]' '[LAUGHTER]' '[VOCALIZED-NOISE]' '<UNK>' '%HESITATION' 'FOREIGNGMM' 'NOISEGMM' 'UNKNOWNGMM' '<s>' '</s>'
}
$cmd LMWT=$min_lmwt:$max_lmwt $dir/scoring/log/best_path.LMWT.log \
lattice-best-path --lm-scale=LMWT --word-symbol-table=$lang/words.txt \
"ark:gunzip -c $dir/lat.*.gz|" ark,t:$dir/scoring/LMWT.tra || exit 1;
for lmwt in `seq $min_lmwt $max_lmwt`; do
utils/int2sym.pl -f 2- $lang/words.txt <$dir/scoring/$lmwt.tra | \
filter_text > $dir/scoring/$lmwt.txt || exit 1;
done
filter_text <$data/text >$dir/scoring/text.filt
unset LC_ALL
#for Chinese character error rate
perl local/ext/hkust_word2ch_tran.pl local/ext/195k_chinese_word2char_map $dir/scoring/text.filt > $dir/scoring/cchar.filt
for lmwt in `seq $min_lmwt $max_lmwt`; do
perl local/ext/hkust_word2ch_tran.pl local/ext/195k_chinese_word2char_map $dir/scoring/$lmwt.txt > $dir/scoring/${lmwt}.cchar
done
export LC_ALL=C
$cmd LMWT=$min_lmwt:$max_lmwt $dir/scoring/log/score.LMWT.log \
compute-wer --text --mode=present \
ark:$dir/scoring/text.filt ark:$dir/scoring/LMWT.txt ">&" $dir/wer_LMWT || exit 1;
$cmd LMWT=$min_lmwt:$max_lmwt $dir/scoring/log/score.LMWT.cer.log \
compute-wer --text --mode=present \
ark:$dir/scoring/cchar.filt ark:$dir/scoring/LMWT.cchar ">&" $dir/cer_LMWT || exit 1;
exit 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment