diff options
author | Chris Dyer <redpony@gmail.com> | 2014-04-02 02:35:19 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-04-02 02:35:19 -0400 |
commit | c3ecdd0009b269a360b240a3a99fc6f8d8b117d3 (patch) | |
tree | e4a6a93867aa23b4e82a0e907ab6ab3ab4de54ea /word-aligner/fast_align.cc | |
parent | 32dcedf28adef39ddd07aaa1ad49e3e73e50b98e (diff) |
speed up fast align by 20% or so
Diffstat (limited to 'word-aligner/fast_align.cc')
-rw-r--r-- | word-aligner/fast_align.cc | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/word-aligner/fast_align.cc b/word-aligner/fast_align.cc index f54233eb..73b72399 100644 --- a/word-aligner/fast_align.cc +++ b/word-aligner/fast_align.cc @@ -190,6 +190,7 @@ int main(int argc, char** argv) { cout << (max_index - 1) << '-' << j; } } + if (s2t_viterbi.size() <= static_cast<unsigned>(max_i)) s2t_viterbi.resize(max_i + 1); s2t_viterbi[max_i][f_j] = 1.0; } } else { @@ -308,17 +309,17 @@ int main(int argc, char** argv) { if (output_parameters) { WriteFile params_out(conf["output_parameters"].as<string>()); - for (TTable::Word2Word2Double::iterator ei = s2t.ttable.begin(); ei != s2t.ttable.end(); ++ei) { - const TTable::Word2Double& cpd = ei->second; - const TTable::Word2Double& vit = s2t_viterbi[ei->first]; - const string& esym = TD::Convert(ei->first); + for (unsigned eind = 1; eind < s2t.ttable.size(); ++eind) { + const auto& cpd = s2t.ttable[eind]; + const TTable::Word2Double& vit = s2t_viterbi[eind]; + const string& esym = TD::Convert(eind); double max_p = -1; - for (TTable::Word2Double::const_iterator fi = cpd.begin(); fi != cpd.end(); ++fi) - if (fi->second > max_p) max_p = fi->second; + for (auto& fi : cpd) + if (fi.second > max_p) max_p = fi.second; const double threshold = max_p * BEAM_THRESHOLD; - for (TTable::Word2Double::const_iterator fi = cpd.begin(); fi != cpd.end(); ++fi) { - if (fi->second > threshold || (vit.find(fi->first) != vit.end())) { - *params_out << esym << ' ' << TD::Convert(fi->first) << ' ' << log(fi->second) << endl; + for (auto& fi : cpd) { + if (fi.second > threshold || (vit.find(fi.first) != vit.end())) { + *params_out << esym << ' ' << TD::Convert(fi.first) << ' ' << log(fi.second) << endl; } } } |