summaryrefslogtreecommitdiff
path: root/training
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-01-30 16:21:35 +0100
committerPatrick Simianer <p@simianer.de>2015-01-30 16:21:35 +0100
commit88a597f7bea6cd8325b48678dfaf874fae4d660d (patch)
treefa049d7b85be4e9e07686d2ef66a479324874eac /training
parente716e3f01a7787ff20f185d6fa1882ed8de941fb (diff)
dtrain: fix_features
Diffstat (limited to 'training')
-rw-r--r--training/dtrain/dtrain.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/training/dtrain/dtrain.cc b/training/dtrain/dtrain.cc
index b180bc82..ae5b630a 100644
--- a/training/dtrain/dtrain.cc
+++ b/training/dtrain/dtrain.cc
@@ -44,6 +44,7 @@ dtrain_init(int argc, char** argv, po::variables_map* cfg)
("repeat", po::value<unsigned>()->default_value(1), "repeat optimization over kbest list this number of times")
("check", po::value<bool>()->zero_tokens(), "produce list of loss differentials")
("output_ranking", po::value<string>()->default_value(""), "Output kbests with model scores and metric per iteration to this folder.")
+ ("fix_features", po::value<bool>()->zero_tokens(), "Ignore all features that are not in input_weights.")
("noup", po::value<bool>()->zero_tokens(), "do not update weights");
po::options_description cl("Command Line Options");
cl.add_options()
@@ -115,6 +116,8 @@ main(int argc, char** argv)
if (cfg.count("rescale")) rescale = true;
bool keep = false;
if (cfg.count("keep")) keep = true;
+ bool fix_features = false;
+ if (cfg.count("fix_features")) fix_features = true;
const unsigned k = cfg["k"].as<unsigned>();
const unsigned N = cfg["N"].as<unsigned>();
@@ -193,8 +196,18 @@ main(int argc, char** argv)
// init weights
vector<weight_t>& decoder_weights = decoder.CurrentWeightVector();
- SparseVector<weight_t> lambdas, cumulative_penalties, w_average;
- if (cfg.count("input_weights")) Weights::InitFromFile(cfg["input_weights"].as<string>(), &decoder_weights);
+
+ SparseVector<weight_t> lambdas, cumulative_penalties, w_average, fixed;
+ if (cfg.count("input_weights")) {
+ Weights::InitFromFile(cfg["input_weights"].as<string>(), &decoder_weights);
+ if (fix_features) {
+ Weights::InitSparseVector(decoder_weights, &fixed);
+ SparseVector<weight_t>::iterator it = fixed.begin();
+ for (; it != fixed.end(); ++it) {
+ it->second = 1.0;
+ }
+ }
+ }
Weights::InitSparseVector(decoder_weights, &lambdas);
// meta params for perceptron, SVM
@@ -334,6 +347,8 @@ main(int argc, char** argv)
if (next || stop) break;
// weights
+ if (fix_features)
+ lambdas.cw_mult(fixed);
lambdas.init_vector(&decoder_weights);
// getting input
@@ -642,6 +657,8 @@ main(int argc, char** argv)
// write weights to file
if (select_weights == "best" || keep) {
+ if (fix_features)
+ lambdas.cw_mult(fixed);
lambdas.init_vector(&decoder_weights);
string w_fn = "weights." + boost::lexical_cast<string>(t) + ".gz";
Weights::WriteToFile(w_fn, decoder_weights, true);