From a1ff38d3427cf0892c3ea174da6939c8aea908bc Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 19 Mar 2014 21:02:51 -0400 Subject: fix comment --- training/mira/kbest_cut_mira.cc | 61 ++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'training') diff --git a/training/mira/kbest_cut_mira.cc b/training/mira/kbest_cut_mira.cc index 1a6415be..56206593 100644 --- a/training/mira/kbest_cut_mira.cc +++ b/training/mira/kbest_cut_mira.cc @@ -340,23 +340,22 @@ struct BasicObserver: public DecoderObserver { }; struct TrainingObserver : public DecoderObserver { - TrainingObserver(const int k, const DocScorer& d, vector* o, vector* cbs) : ds(d), oracles(*o), corpus_bleu_sent_stats(*cbs), kbest_size(k) { - - - if(!pseudo_doc && !sent_approx) - if(cur_pass > 0) //calculate corpus bleu score from previous iterations 1-best for BLEU gain - { - ScoreP acc; - for (int ii = 0; ii < corpus_bleu_sent_stats.size(); ii++) { - if (!acc) { acc = corpus_bleu_sent_stats[ii]->GetZero(); } - acc->PlusEquals(*corpus_bleu_sent_stats[ii]); - - } - corpus_bleu_stats = acc; - corpus_bleu_score = acc->ComputeScore(); + TrainingObserver(const int k, + const DocScorer& d, + vector* o, + vector* cbs) : ds(d), oracles(*o), corpus_bleu_sent_stats(*cbs), kbest_size(k) { + if(!pseudo_doc && !sent_approx) { + if(cur_pass > 0) { //calculate corpus bleu score from previous iterations 1-best for BLEU gain + ScoreP acc; + for (int ii = 0; ii < corpus_bleu_sent_stats.size(); ii++) { + if (!acc) { acc = corpus_bleu_sent_stats[ii]->GetZero(); } + acc->PlusEquals(*corpus_bleu_sent_stats[ii]); + } + corpus_bleu_stats = acc; + corpus_bleu_score = acc->ComputeScore(); } - -} + } + } const DocScorer& ds; vector& corpus_bleu_sent_stats; vector& oracles; @@ -460,7 +459,6 @@ struct TrainingObserver : public DecoderObserver { } else //use sentence-level smoothing ( used when cur_pass=0 if not pseudo_doc) { - sentscore = mt_metric_scale * (ds[sent_id]->ScoreCandidate(d->yield)->ComputeScore()); } @@ -574,19 +572,15 @@ void ReadTrainingCorpus(const string& fname, vector* c) { } } -void ReadPastTranslationForScore(const int cur_pass, vector* c, DocScorer& ds, const string& od) -{ - cerr << "Reading BLEU gain file "; +void ReadPastTranslationForScore(const int cur_pass, vector* c, DocScorer& ds, const string& od) { + cerr << "Reading previous score file "; string fname; - if(cur_pass == 0) - { - fname = od + "/run.raw.init"; - } - else - { - int last_pass = cur_pass - 1; - fname = od + "/run.raw." + boost::lexical_cast(last_pass) + ".B"; - } + if (cur_pass == 0) { + fname = od + "/run.raw.init"; + } else { + int last_pass = cur_pass - 1; + fname = od + "/run.raw." + boost::lexical_cast(last_pass) + ".B"; + } cerr << fname << "\n"; ReadFile rf(fname); istream& in = *rf.stream(); @@ -603,7 +597,6 @@ void ReadPastTranslationForScore(const int cur_pass, vector* c, DocScore if (!acc) { acc = sentscore->GetZero(); } acc->PlusEquals(*sentscore); ++lc; - } assert(lc > 0); @@ -611,7 +604,6 @@ void ReadPastTranslationForScore(const int cur_pass, vector* c, DocScore string details; acc->ScoreDetails(&details); cerr << "Previous run: " << details << score << endl; - } @@ -670,10 +662,9 @@ int main(int argc, char** argv) { //check training pass,if >0, then use previous iterations corpus bleu stats cur_pass = stream ? 0 : conf["pass"].as(); - if(cur_pass > 0) - { - ReadPastTranslationForScore(cur_pass, &corpus_bleu_sent_stats, *ds, output_dir); - } + if(cur_pass > 0) { + ReadPastTranslationForScore(cur_pass, &corpus_bleu_sent_stats, *ds, output_dir); + } cerr << "Using optimizer:" << optimizer << endl; -- cgit v1.2.3