From 3cf76cc62341c04e0962705d011ab141190ae1da Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 7 Jul 2010 22:07:35 +0000 Subject: compute viterbi result once only per node (for best edge) git-svn-id: https://ws10smt.googlecode.com/svn/trunk@182 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/cdec.cc | 1 + decoder/viterbi.h | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'decoder') diff --git a/decoder/cdec.cc b/decoder/cdec.cc index bb29bafb..b43b7826 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -86,6 +86,7 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) { ("show_expected_length", "Show the expected translation length under the model") ("show_partition,z", "Compute and show the partition (inside score)") ("show_cfg_search_space", "Show the search space as a CFG") + ("show_viterbi_features","Show the feature vector for the viterbi translation") ("prelm_density_prune", po::value(), "Applied to -LM forest just before final LM rescoring: keep no more than this many times the number of edges used in the best derivation tree (>=1.0)") ("density_prune", po::value(), "Keep no more than this many times the number of edges used in the best derivation tree (>=1.0)") ("prelm_beam_prune", po::value(), "Prune paths from -LM forest before LM rescoring, keeping paths within exp(alpha>=0)") diff --git a/decoder/viterbi.h b/decoder/viterbi.h index d4a97516..6b8bbed1 100644 --- a/decoder/viterbi.h +++ b/decoder/viterbi.h @@ -29,20 +29,23 @@ WeightType Viterbi(const Hypergraph& hg, *cur_node_best_weight = WeightType(1); continue; } + Hypergraph::Edge const* edge_best=0; for (int j = 0; j < num_in_edges; ++j) { const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]]; WeightType score = weight(edge); - std::vector ants(edge.tail_nodes_.size()); - for (int k = 0; k < edge.tail_nodes_.size(); ++k) { - const int tail_node_index = edge.tail_nodes_[k]; - score *= vit_weight[tail_node_index]; - ants[k] = &vit_result[tail_node_index]; - } - if (*cur_node_best_weight < score) { + for (int k = 0; k < edge.tail_nodes_.size(); ++k) + score *= vit_weight[edge.tail_nodes_[k]]; + if (!edge_best || *cur_node_best_weight < score) { *cur_node_best_weight = score; - traverse(edge, ants, cur_node_best_result); + edge_best=&edge; } } + assert(edge_best); + Hypergraph::Edge const& edgeb=*edge_best; + std::vector antsb(edgeb.tail_nodes_.size()); + for (int k = 0; k < edgeb.tail_nodes_.size(); ++k) + antsb[k] = &vit_result[edgeb.tail_nodes_[k]]; + traverse(edgeb, antsb, cur_node_best_result); } std::swap(*result, vit_result.back()); return vit_weight.back(); -- cgit v1.2.3