From 0f5a50a50c0a1984354ffbf131016b912f7be633 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 1 Feb 2015 19:52:38 +0100 Subject: dtrain: rename unfortunate var --- training/dtrain/dtrain.cc | 140 +++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 70 deletions(-) (limited to 'training') diff --git a/training/dtrain/dtrain.cc b/training/dtrain/dtrain.cc index 4f29c499..4c5972a1 100644 --- a/training/dtrain/dtrain.cc +++ b/training/dtrain/dtrain.cc @@ -8,7 +8,7 @@ using namespace dtrain; bool -dtrain_init(int argc, char** argv, po::variables_map* cfg) +dtrain_init(int argc, char** argv, po::variables_map* conf) { po::options_description ini("Configuration File Options"); ini.add_options() @@ -51,49 +51,49 @@ dtrain_init(int argc, char** argv, po::variables_map* cfg) ("quiet,q", po::value()->zero_tokens(), "be quiet") ("verbose,v", po::value()->zero_tokens(), "be verbose"); cl.add(ini); - po::store(parse_command_line(argc, argv, cl), *cfg); - if (cfg->count("config")) { - ifstream ini_f((*cfg)["config"].as().c_str()); - po::store(po::parse_config_file(ini_f, ini), *cfg); + po::store(parse_command_line(argc, argv, cl), *conf); + if (conf->count("config")) { + ifstream ini_f((*conf)["config"].as().c_str()); + po::store(po::parse_config_file(ini_f, ini), *conf); } - po::notify(*cfg); - if (!cfg->count("decoder_config")) { + po::notify(*conf); + if (!conf->count("decoder_config")) { cerr << cl << endl; return false; } - if ((*cfg)["sample_from"].as() != "kbest" - && (*cfg)["sample_from"].as() != "forest") { - cerr << "Wrong 'sample_from' param: '" << (*cfg)["sample_from"].as() << "', use 'kbest' or 'forest'." << endl; + if ((*conf)["sample_from"].as() != "kbest" + && (*conf)["sample_from"].as() != "forest") { + cerr << "Wrong 'sample_from' param: '" << (*conf)["sample_from"].as() << "', use 'kbest' or 'forest'." << endl; return false; } - if ((*cfg)["sample_from"].as() == "kbest" && (*cfg)["filter"].as() != "uniq" && - (*cfg)["filter"].as() != "not") { - cerr << "Wrong 'filter' param: '" << (*cfg)["filter"].as() << "', use 'uniq' or 'not'." << endl; + if ((*conf)["sample_from"].as() == "kbest" && (*conf)["filter"].as() != "uniq" && + (*conf)["filter"].as() != "not") { + cerr << "Wrong 'filter' param: '" << (*conf)["filter"].as() << "', use 'uniq' or 'not'." << endl; return false; } - if ((*cfg)["pair_sampling"].as() != "all" && (*cfg)["pair_sampling"].as() != "XYX" && - (*cfg)["pair_sampling"].as() != "PRO" && (*cfg)["pair_sampling"].as() != "output_pairs") { - cerr << "Wrong 'pair_sampling' param: '" << (*cfg)["pair_sampling"].as() << "'." << endl; + if ((*conf)["pair_sampling"].as() != "all" && (*conf)["pair_sampling"].as() != "XYX" && + (*conf)["pair_sampling"].as() != "PRO" && (*conf)["pair_sampling"].as() != "output_pairs") { + cerr << "Wrong 'pair_sampling' param: '" << (*conf)["pair_sampling"].as() << "'." << endl; return false; } - if (cfg->count("hi_lo") && (*cfg)["pair_sampling"].as() != "XYX") { + if (conf->count("hi_lo") && (*conf)["pair_sampling"].as() != "XYX") { cerr << "Warning: hi_lo only works with pair_sampling XYX." << endl; } - if ((*cfg)["hi_lo"].as() > 0.5 || (*cfg)["hi_lo"].as() < 0.01) { + if ((*conf)["hi_lo"].as() > 0.5 || (*conf)["hi_lo"].as() < 0.01) { cerr << "hi_lo must lie in [0.01, 0.5]" << endl; return false; } - if (!cfg->count("bitext")) { + if (!conf->count("bitext")) { cerr << "No training data given." << endl; return false; } - if ((*cfg)["pair_threshold"].as() < 0) { + if ((*conf)["pair_threshold"].as() < 0) { cerr << "The threshold must be >= 0!" << endl; return false; } - if ((*cfg)["select_weights"].as() != "last" && (*cfg)["select_weights"].as() != "best" && - (*cfg)["select_weights"].as() != "avg" && (*cfg)["select_weights"].as() != "VOID") { - cerr << "Wrong 'select_weights' param: '" << (*cfg)["select_weights"].as() << "', use 'last' or 'best'." << endl; + if ((*conf)["select_weights"].as() != "last" && (*conf)["select_weights"].as() != "best" && + (*conf)["select_weights"].as() != "avg" && (*conf)["select_weights"].as() != "VOID") { + cerr << "Wrong 'select_weights' param: '" << (*conf)["select_weights"].as() << "', use 'last' or 'best'." << endl; return false; } return true; @@ -103,60 +103,60 @@ int main(int argc, char** argv) { // handle most parameters - po::variables_map cfg; - if (!dtrain_init(argc, argv, &cfg)) exit(1); // something is wrong + po::variables_map conf; + if (!dtrain_init(argc, argv, &conf)) exit(1); // something is wrong bool quiet = false; - if (cfg.count("quiet")) quiet = true; + if (conf.count("quiet")) quiet = true; bool verbose = false; - if (cfg.count("verbose")) verbose = true; + if (conf.count("verbose")) verbose = true; bool noup = false; - if (cfg.count("noup")) noup = true; + if (conf.count("noup")) noup = true; bool rescale = false; - if (cfg.count("rescale")) rescale = true; + if (conf.count("rescale")) rescale = true; bool keep = false; - if (cfg.count("keep")) keep = true; + if (conf.count("keep")) keep = true; bool fix_features = false; - if (cfg.count("fix_features")) fix_features = true; - - const unsigned k = cfg["k"].as(); - const unsigned N = cfg["N"].as(); - const unsigned T = cfg["epochs"].as(); - const unsigned stop_after = cfg["stop_after"].as(); - const string filter_type = cfg["filter"].as(); - const string sample_from = cfg["sample_from"].as(); - const string pair_sampling = cfg["pair_sampling"].as(); - const score_t pair_threshold = cfg["pair_threshold"].as(); - const string select_weights = cfg["select_weights"].as(); - const string output_ranking = cfg["output_ranking"].as(); - const float hi_lo = cfg["hi_lo"].as(); - const score_t approx_bleu_d = cfg["approx_bleu_d"].as(); - const unsigned max_pairs = cfg["max_pairs"].as(); - int repeat = cfg["repeat"].as(); + if (conf.count("fix_features")) fix_features = true; + + const unsigned k = conf["k"].as(); + const unsigned N = conf["N"].as(); + const unsigned T = conf["epochs"].as(); + const unsigned stop_after = conf["stop_after"].as(); + const string filter_type = conf["filter"].as(); + const string sample_from = conf["sample_from"].as(); + const string pair_sampling = conf["pair_sampling"].as(); + const score_t pair_threshold = conf["pair_threshold"].as(); + const string select_weights = conf["select_weights"].as(); + const string output_ranking = conf["output_ranking"].as(); + const float hi_lo = conf["hi_lo"].as(); + const score_t approx_bleu_d = conf["approx_bleu_d"].as(); + const unsigned max_pairs = conf["max_pairs"].as(); + int repeat = conf["repeat"].as(); bool check = false; - if (cfg.count("check")) check = true; - weight_t loss_margin = cfg["loss_margin"].as(); + if (conf.count("check")) check = true; + weight_t loss_margin = conf["loss_margin"].as(); bool batch = false; - if (cfg.count("batch")) batch = true; + if (conf.count("batch")) batch = true; if (loss_margin > 9998.) loss_margin = std::numeric_limits::max(); - const string pclr = cfg["pclr"].as(); + const string pclr = conf["pclr"].as(); bool average = false; if (select_weights == "avg") average = true; vector print_weights; - if (cfg.count("print_weights")) - boost::split(print_weights, cfg["print_weights"].as(), boost::is_any_of(" ")); + if (conf.count("print_weights")) + boost::split(print_weights, conf["print_weights"].as(), boost::is_any_of(" ")); // setup decoder register_feature_functions(); SetSilent(true); - ReadFile ini_rf(cfg["decoder_config"].as()); + ReadFile ini_rf(conf["decoder_config"].as()); if (!quiet) - cerr << setw(25) << "cdec cfg " << "'" << cfg["decoder_config"].as() << "'" << endl; + cerr << setw(25) << "cdec conf " << "'" << conf["decoder_config"].as() << "'" << endl; Decoder decoder(ini_rf.stream()); // scoring metric/scorer - string scorer_str = cfg["scorer"].as(); + string scorer_str = conf["scorer"].as(); LocalScorer* scorer; if (scorer_str == "bleu") { scorer = static_cast(new BleuScorer); @@ -196,8 +196,8 @@ main(int argc, char** argv) vector& decoder_weights = decoder.CurrentWeightVector(); SparseVector lambdas, cumulative_penalties, w_average, fixed; - if (cfg.count("input_weights")) { - Weights::InitFromFile(cfg["input_weights"].as(), &decoder_weights); + if (conf.count("input_weights")) { + Weights::InitFromFile(conf["input_weights"].as(), &decoder_weights); if (fix_features) { Weights::InitSparseVector(decoder_weights, &fixed); SparseVector::iterator it = fixed.begin(); @@ -209,8 +209,8 @@ main(int argc, char** argv) Weights::InitSparseVector(decoder_weights, &lambdas); // meta params for perceptron, SVM - weight_t eta = cfg["learning_rate"].as(); - weight_t gamma = cfg["gamma"].as(); + weight_t eta = conf["learning_rate"].as(); + weight_t gamma = conf["gamma"].as(); // faster perceptron: consider only misranked pairs, see bool faster_perceptron = false; @@ -221,19 +221,19 @@ main(int argc, char** argv) bool l1clip = false; bool l1cumul = false; weight_t l1_reg = 0; - if (cfg["l1_reg"].as() != "none") { - string s = cfg["l1_reg"].as(); + if (conf["l1_reg"].as() != "none") { + string s = conf["l1_reg"].as(); if (s == "naive") l1naive = true; else if (s == "clip") l1clip = true; else if (s == "cumul") l1cumul = true; - l1_reg = cfg["l1_reg_strength"].as(); + l1_reg = conf["l1_reg_strength"].as(); } // output - string output_fn = cfg["output"].as(); + string output_fn = conf["output"].as(); // input string input_fn; - ReadFile input(cfg["bitext"].as()); + ReadFile input(conf["bitext"].as()); // buffer input for t > 0 vector src_str_buf; // source strings (decoder takes only strings) vector > > refs_as_ids_buf; // references as WordID vecs @@ -244,7 +244,7 @@ main(int argc, char** argv) unsigned best_it = 0; float overall_time = 0.; - // output cfg + // output conf if (!quiet) { cerr << _p5; cerr << endl << "dtrain" << endl << "Parameters:" << endl; @@ -267,19 +267,19 @@ main(int argc, char** argv) cerr << setw(25) << "hi lo " << hi_lo << endl; cerr << setw(25) << "pair threshold " << pair_threshold << endl; cerr << setw(25) << "select weights " << "'" << select_weights << "'" << endl; - if (cfg.count("l1_reg")) - cerr << setw(25) << "l1 reg " << l1_reg << " '" << cfg["l1_reg"].as() << "'" << endl; + if (conf.count("l1_reg")) + cerr << setw(25) << "l1 reg " << l1_reg << " '" << conf["l1_reg"].as() << "'" << endl; if (rescale) cerr << setw(25) << "rescale " << rescale << endl; cerr << setw(25) << "pclr " << pclr << endl; cerr << setw(25) << "max pairs " << max_pairs << endl; cerr << setw(25) << "repeat " << repeat << endl; //cerr << setw(25) << "test k-best " << test_k_best << endl; - cerr << setw(25) << "cdec cfg " << "'" << cfg["decoder_config"].as() << "'" << endl; + cerr << setw(25) << "cdec conf " << "'" << conf["decoder_config"].as() << "'" << endl; cerr << setw(25) << "input " << "'" << input_fn << "'" << endl; cerr << setw(25) << "output " << "'" << output_fn << "'" << endl; - if (cfg.count("input_weights")) - cerr << setw(25) << "weights in " << "'" << cfg["input_weights"].as() << "'" << endl; + if (conf.count("input_weights")) + cerr << setw(25) << "weights in " << "'" << conf["input_weights"].as() << "'" << endl; if (stop_after > 0) cerr << setw(25) << "stop_after " << stop_after << endl; if (!verbose) cerr << "(a dot represents " << DTRAIN_DOTS << " inputs)" << endl; -- cgit v1.2.3