From 3b371a950f9ae04c9072f3df9b21dafa475916fa Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Thu, 29 Jan 2015 19:50:27 +0100
Subject: dtrain: output_pairs, print_ranking
---
training/dtrain/dtrain.cc | 27 +++++++++++++++++++++++++--
training/dtrain/score.cc | 2 +-
2 files changed, 26 insertions(+), 3 deletions(-)
(limited to 'training')
diff --git a/training/dtrain/dtrain.cc b/training/dtrain/dtrain.cc
index 737326f8..0b648d95 100644
--- a/training/dtrain/dtrain.cc
+++ b/training/dtrain/dtrain.cc
@@ -41,8 +41,9 @@ dtrain_init(int argc, char** argv, po::variables_map* cfg)
("max_pairs", po::value()->default_value(std::numeric_limits::max()), "max. # of pairs per Sent.")
("pclr", po::value()->default_value("no"), "use a (simple|adagrad) per-coordinate learning rate")
("batch", po::value()->zero_tokens(), "do batch optimization")
- ("repeat", po::value()->default_value(1), "repeat optimization over kbest list this number of times")
+ ("repeat", po::value()->default_value(1), "repeat optimization over kbest list this number of times")
("check", po::value()->zero_tokens(), "produce list of loss differentials")
+ ("print_ranking", po::value()->zero_tokens(), "output kbest with model score and metric")
("noup", po::value()->zero_tokens(), "do not update weights");
po::options_description cl("Command Line Options");
cl.add_options()
@@ -71,7 +72,7 @@ dtrain_init(int argc, char** argv, po::variables_map* cfg)
return false;
}
if ((*cfg)["pair_sampling"].as() != "all" && (*cfg)["pair_sampling"].as() != "XYX" &&
- (*cfg)["pair_sampling"].as() != "PRO") {
+ (*cfg)["pair_sampling"].as() != "PRO" && (*cfg)["pair_sampling"].as() != "output_pairs") {
cerr << "Wrong 'pair_sampling' param: '" << (*cfg)["pair_sampling"].as() << "'." << endl;
return false;
}
@@ -114,6 +115,8 @@ main(int argc, char** argv)
if (cfg.count("rescale")) rescale = true;
bool keep = false;
if (cfg.count("keep")) keep = true;
+ bool print_ranking = false;
+ if (cfg.count("print_ranking")) print_ranking = true;
const unsigned k = cfg["k"].as();
const unsigned N = cfg["N"].as();
@@ -356,6 +359,14 @@ main(int argc, char** argv)
// get (scored) samples
vector* samples = observer->GetSamples();
+ if (print_ranking) {
+ for (auto s: *samples) {
+ cout << ii << " ||| ";
+ printWordIDVec(s.w, cout);
+ cout << " ||| " << s.model << " ||| " << s.score << endl;
+ }
+ }
+
if (verbose) {
cerr << "--- refs for " << ii << ": ";
for (auto r: refs_as_ids_buf[ii]) {
@@ -389,6 +400,8 @@ main(int argc, char** argv)
partXYX(samples, pairs, pair_threshold, max_pairs, faster_perceptron, hi_lo);
if (pair_sampling == "PRO")
PROsampling(samples, pairs, pair_threshold, max_pairs);
+ if (pair_sampling == "output_pairs")
+ all_pairs(samples, pairs, pair_threshold, max_pairs, false);
int cur_npairs = pairs.size();
npairs += cur_npairs;
@@ -397,6 +410,15 @@ main(int argc, char** argv)
if (check) repeat = 2;
vector losses; // for check
+ if (pair_sampling == "output_pairs") {
+ for (auto p: pairs) {
+ cout << p.first.model << " ||| " << p.first.score << " ||| " << p.first.f << endl;
+ cout << p.second.model << " ||| " << p.second.score << " ||| " << p.second.f << endl;
+ cout << endl;
+ }
+ continue;
+ }
+
for (vector >::iterator it = pairs.begin();
it != pairs.end(); it++) {
score_t model_diff = it->first.model - it->second.model;
@@ -547,6 +569,7 @@ main(int argc, char** argv)
if (t == 0) in_sz = ii; // remember size of input (# lines)
+ if (print_ranking) cout << "---" << endl;
if (batch) {
lambdas.plus_eq_v_times_s(batch_updates, eta);
diff --git a/training/dtrain/score.cc b/training/dtrain/score.cc
index d81eafcb..8a28771f 100644
--- a/training/dtrain/score.cc
+++ b/training/dtrain/score.cc
@@ -36,7 +36,7 @@ RefLen(vector > refs)
{
size_t ref_len = 0;
for (auto r: refs)
- ref_len = max(ref_len, r.size());
+ ref_len = max(ref_len, r.size()); // FIXME
return ref_len;
}
--
cgit v1.2.3