From bde2f6be8d0ea5b931f43fe7f518e9adcbcd2b49 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 9 Apr 2014 20:19:57 -0400 Subject: fix for loading parameters --- word-aligner/ttables.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'word-aligner') diff --git a/word-aligner/ttables.cc b/word-aligner/ttables.cc index a56bbcef..64d54bdf 100644 --- a/word-aligner/ttables.cc +++ b/word-aligner/ttables.cc @@ -8,28 +8,32 @@ using namespace std; void TTable::DeserializeProbsFromText(std::istream* in) { int c = 0; + string e; + string f; + double p; while(*in) { - string e; - string f; - double p; (*in) >> e >> f >> p; if (e.empty()) break; ++c; - ttable[TD::Convert(e)][TD::Convert(f)] = p; + WordID ie = TD::Convert(e); + if (ie >= static_cast(ttable.size())) ttable.resize(ie + 1); + ttable[ie][TD::Convert(f)] = p; } cerr << "Loaded " << c << " translation parameters.\n"; } void TTable::DeserializeLogProbsFromText(std::istream* in) { int c = 0; + string e; + string f; + double p; while(*in) { - string e; - string f; - double p; (*in) >> e >> f >> p; if (e.empty()) break; ++c; - ttable[TD::Convert(e)][TD::Convert(f)] = exp(p); + WordID ie = TD::Convert(e); + if (ie >= static_cast(ttable.size())) ttable.resize(ie + 1); + ttable[ie][TD::Convert(f)] = exp(p); } cerr << "Loaded " << c << " translation parameters.\n"; } -- cgit v1.2.3