summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'decoder')
-rw-r--r--decoder/apply_models.cc2
-rw-r--r--decoder/decoder.cc5
-rw-r--r--decoder/decoder.h1
-rw-r--r--decoder/ff_wordalign.cc14
-rw-r--r--decoder/viterbi.cc2
5 files changed, 14 insertions, 10 deletions
diff --git a/decoder/apply_models.cc b/decoder/apply_models.cc
index aec31a4f..18460950 100644
--- a/decoder/apply_models.cc
+++ b/decoder/apply_models.cc
@@ -319,7 +319,7 @@ struct NoPruningRescorer {
in(i),
out(*o),
nodemap(i.nodes_.size()) {
- cerr << " Rescoring forest (full intersection)\n";
+ if (!SILENT) cerr << " Rescoring forest (full intersection)\n";
node_states_.reserve(kRESERVE_NUM_NODES);
}
diff --git a/decoder/decoder.cc b/decoder/decoder.cc
index 1a233fc5..537fdffa 100644
--- a/decoder/decoder.cc
+++ b/decoder/decoder.cc
@@ -147,6 +147,7 @@ struct DecoderImpl {
void SetWeights(const vector<double>& weights) {
feature_weights = weights;
}
+ void SetId(int next_sent_id) { sent_id = next_sent_id - 1; }
void forest_stats(Hypergraph &forest,string name,bool show_tree,bool show_features,WeightVector *weights=0,bool show_deriv=false) {
cerr << viterbi_stats(forest,name,true,show_tree,show_deriv);
@@ -622,6 +623,7 @@ DecoderImpl::DecoderImpl(po::variables_map& conf, int argc, char** argv, istream
Decoder::Decoder(istream* cfg) { pimpl_.reset(new DecoderImpl(conf,0,0,cfg)); }
Decoder::Decoder(int argc, char** argv) { pimpl_.reset(new DecoderImpl(conf,argc, argv, 0)); }
Decoder::~Decoder() {}
+void Decoder::SetId(int next_sent_id) { pimpl_->SetId(next_sent_id); }
bool Decoder::Decode(const string& input, DecoderObserver* o) {
bool del = false;
if (!o) { o = new DecoderObserver; del = true; }
@@ -818,8 +820,7 @@ bool DecoderImpl::Decode(const string& input, DecoderObserver* o) {
HypergraphIO::WriteAsCFG(forest);
if (has_ref) {
if (HG::Intersect(ref, &forest)) {
- if (!SILENT) cerr << " Constr. forest (nodes/edges): " << forest.nodes_.size() << '/' << forest.edges_.size() << endl;
- if (!SILENT) cerr << " Constr. forest (paths): " << forest.NumberOfPaths() << endl;
+ if (!SILENT) forest_stats(forest," Constr. forest",show_tree_structure,show_features,feature_weights,oracle.show_derivation);
if (crf_uniform_empirical) {
if (!SILENT) cerr << " USING UNIFORM WEIGHTS\n";
for (int i = 0; i < forest.edges_.size(); ++i)
diff --git a/decoder/decoder.h b/decoder/decoder.h
index 2a1a43ce..abaf3740 100644
--- a/decoder/decoder.h
+++ b/decoder/decoder.h
@@ -26,6 +26,7 @@ struct Decoder {
Decoder(std::istream* config_file);
bool Decode(const std::string& input, DecoderObserver* observer = NULL);
void SetWeights(const std::vector<double>& weights);
+ void SetId(int id);
~Decoder();
const boost::program_options::variables_map& GetConf() const { return conf; }
private:
diff --git a/decoder/ff_wordalign.cc b/decoder/ff_wordalign.cc
index 087bff0c..a1968159 100644
--- a/decoder/ff_wordalign.cc
+++ b/decoder/ff_wordalign.cc
@@ -72,11 +72,11 @@ RelativeSentencePosition::RelativeSentencePosition(const string& param) :
pos_.push_back(v);
for (int i = 0; i < v.size(); ++i)
classes.insert(v[i]);
- for (set<WordID>::iterator i = classes.begin(); i != classes.end(); ++i) {
- ostringstream os;
- os << "RelPos_FC:" << TD::Convert(*i);
- fids_[*i] = FD::Convert(os.str());
- }
+ }
+ for (set<WordID>::iterator i = classes.begin(); i != classes.end(); ++i) {
+ ostringstream os;
+ os << "RelPos_FC:" << TD::Convert(*i);
+ fids_[*i] = FD::Convert(os.str());
}
} else {
condition_on_fclass_ = false;
@@ -104,7 +104,9 @@ void RelativeSentencePosition::TraversalFeaturesImpl(const SentenceMetadata& sme
if (condition_on_fclass_) {
assert(smeta.GetSentenceID() < pos_.size());
const WordID cur_fclass = pos_[smeta.GetSentenceID()][edge.i_];
- const int fid = fids_.find(cur_fclass)->second;
+ std::map<WordID, int>::const_iterator fidit = fids_.find(cur_fclass);
+ assert(fidit != fids_.end());
+ const int fid = fidit->second;
features->set_value(fid, val);
}
// cerr << f_len_ << " " << e_len_ << " [" << edge.i_ << "," << edge.j_ << "|" << edge.prev_i_ << "," << edge.prev_j_ << "]\t" << edge.rule_->AsString() << "\tVAL=" << val << endl;
diff --git a/decoder/viterbi.cc b/decoder/viterbi.cc
index fac9dd70..a8192a9f 100644
--- a/decoder/viterbi.cc
+++ b/decoder/viterbi.cc
@@ -16,7 +16,7 @@ std::string viterbi_stats(Hypergraph const& hg, std::string const& name, bool es
if (estring) {
vector<WordID> trans;
const prob_t vs = ViterbiESentence(hg, &trans);
- o<<name<<" Viterbi logp: "<<log(vs)<<endl;
+ o<<name<<" Viterbi logp: "<<log(vs)<< " (norm=" << log(vs)/trans.size() << ")" << endl;
o<<name<<" Viterbi: "<<TD::GetString(trans)<<endl;
}
if (etree) {