summaryrefslogtreecommitdiff
path: root/dtrain/dtest.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2011-09-04 23:40:44 +0200
committerPatrick Simianer <p@simianer.de>2011-09-23 19:13:58 +0200
commit809361a8e182c5e47ffe569db7671bc8c7224867 (patch)
treeb0c34f494be231962fdf7ec70eb739af64be0004 /dtrain/dtest.cc
parentaa5f96417ff81408b15b54aab35a3c16b845adf8 (diff)
minor updates, fixes, kbest filtering switch
Diffstat (limited to 'dtrain/dtest.cc')
-rw-r--r--dtrain/dtest.cc47
1 files changed, 19 insertions, 28 deletions
diff --git a/dtrain/dtest.cc b/dtrain/dtest.cc
index 7674a3ca..36c880a3 100644
--- a/dtrain/dtest.cc
+++ b/dtrain/dtest.cc
@@ -11,13 +11,11 @@ bool
init(int argc, char** argv, po::variables_map* conf)
{
int N;
- bool q;
- po::options_description opts( "Options" );
+ po::options_description opts( "Command Line Options" );
opts.add_options()
( "decoder-config,c", po::value<string>(), "configuration file for cdec" )
( "weights,w", po::value<string>(), "weights file" )
- ( "ngrams,n", po::value<int>(&N)->default_value(DTRAIN_DEFAULT_N), "N for Ngrams (default 5)" )
- ( "quiet,q", po::value<bool>(&q)->default_value(true), "do not output translations" );
+ ( "ngrams,n", po::value<int>(&N)->default_value(DTRAIN_DEFAULT_N), "N for Ngrams (default 5)" );
po::options_description cmdline_options;
cmdline_options.add(opts);
po::store( parse_command_line(argc, argv, cmdline_options), *conf );
@@ -37,57 +35,50 @@ init(int argc, char** argv, po::variables_map* conf)
int
main(int argc, char** argv)
{
- SetSilent(true);
+ SetSilent( true );
po::variables_map conf;
- if (!init(argc, argv, &conf)) return 1;
+ if ( !init(argc, argv, &conf) ) return 1;
register_feature_functions();
size_t k = 1;
- ReadFile ini_rf(conf["decoder-config"].as<string>());
- Decoder decoder(ini_rf.stream());
- KBestGetter observer(k);
+ ReadFile ini_rf( conf["decoder-config"].as<string>() );
+ Decoder decoder( ini_rf.stream() );
+ KBestGetter observer( k, "no" );
size_t N = conf["ngrams"].as<int>();
- bool quiet = conf["quiet"].as<bool>();
Weights weights;
- weights.InitFromFile(conf["weights"].as<string>());
+ if ( conf.count("weights") ) weights.InitFromFile( conf["weights"].as<string>() );
vector<double> w;
- weights.InitVector(&w);
- decoder.SetWeights(w);
+ weights.InitVector( &w );
+ decoder.SetWeights( w );
- vector<string> strs, ref_strs;
+ vector<string> in_split, ref_strs;
vector<WordID> ref_ids;
string in, psg;
size_t sn = 0;
double overall = 0.0;
double overall1 = 0.0;
double overall2 = 0.0;
- cerr << "(A dot represents " << DTRAIN_DOTOUT << " lines of input.)" << endl;
while( getline(cin, in) ) {
- if ( (sn+1) % DTRAIN_DOTOUT == 0 ) {
- cerr << ".";
- if ( (sn+1) % (20*DTRAIN_DOTOUT) == 0 ) cerr << " " << sn+1 << endl;
- }
- //if ( sn > 5000 ) break;
- strs.clear();
- boost::split( strs, in, boost::is_any_of("\t") );
+ in_split.clear();
+ boost::split( in_split, in, boost::is_any_of("\t") );
// grammar
- psg = boost::replace_all_copy( strs[2], " __NEXT_RULE__ ", "\n" ); psg += "\n";
- decoder.SetSentenceGrammar( psg );
- decoder.Decode( strs[0], &observer );
+ psg = boost::replace_all_copy( in_split[3], " __NEXT__RULE__ ", "\n" ); psg += "\n";
+ decoder.SetSentenceGrammarFromString( psg );
+ decoder.Decode( in_split[1], &observer );
KBestList* kb = observer.GetKBest();
// reference
ref_strs.clear(); ref_ids.clear();
- boost::split( ref_strs, strs[1], boost::is_any_of(" ") );
+ boost::split( ref_strs, in_split[2], boost::is_any_of(" ") );
register_and_convert( ref_strs, ref_ids );
// scoring kbest
double score = 0.0;
double score1 = 0.0;
double score2 = 0.0;
- NgramCounts counts = make_ngram_counts( ref_ids, kb->sents[0], 4 );
+ NgramCounts counts = make_ngram_counts( ref_ids, kb->sents[0], N );
score = smooth_bleu( counts, ref_ids.size(), kb->sents[0].size(), N );
score1 = stupid_bleu( counts, ref_ids.size(), kb->sents[0].size(), N );
score2 = bleu( counts, ref_ids.size(), kb->sents[0].size(), N );
- if ( ! quiet ) cout << TD::GetString( kb->sents[0] ) << endl;
+ cout << TD::GetString( kb->sents[0] ) << endl;
overall += score;
overall1 += score1;
overall2 += score2;