From b2488f83c3c3a3871c27050c03d4dedb0e5d280e Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 15 May 2013 14:34:31 +0100 Subject: [PATCH] port PhraseDictionaryMultiModelCounts to new format. Runs but doesn't pass regression test --- .../PhraseDictionaryMultiModelCounts.cpp | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp index e373ad505..0b6d8fe26 100644 --- a/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp +++ b/moses/TranslationModel/PhraseDictionaryMultiModelCounts.cpp @@ -25,6 +25,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; +template +void outVec(const vector &vec) +{ + for (size_t i = 0; i < vec.size(); ++i) { + cerr << vec[i] << " " << flush; + } + cerr << endl; +} + // from phrase-extract/tables-core.cpp vector tokenize( const char* input ) { @@ -62,11 +71,12 @@ PhraseDictionaryMultiModelCounts::PhraseDictionaryMultiModelCounts(const std::st for (size_t i = 0; i < m_args.size(); ++i) { const vector &args = m_args[i]; if (args[0] == "mode") { - m_mode =args[1]; + m_mode = args[1]; if (m_mode == "instance_weighting") m_combineFunction = InstanceWeighting; - else if (m_mode == "interpolate") + else if (m_mode == "interpolate") { m_combineFunction = LinearInterpolationFromCounts; + } else { ostringstream msg; msg << "combination mode unknown: " << m_mode; @@ -285,6 +295,8 @@ void PhraseDictionaryMultiModelCounts::CollectSufficientStatistics(const Phrase& statistics->ft[i] = UntransformScore(raw_scores[1]); fs[i] = UntransformScore(raw_scores[2]); (*allStats)[targetString] = statistics; + + outVec(statistics->ft); } } } @@ -298,10 +310,10 @@ void PhraseDictionaryMultiModelCounts::CollectSufficientStatistics(const Phrase& statistics->ft[i] = GetTargetCount(static_cast(*statistics->targetPhrase), i); } } + outVec(statistics->ft); } } - TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseCollectionCounts(const Phrase &src, vector &fs, map* allStats, vector > &multimodelweights) const { TargetPhraseCollection *ret = new TargetPhraseCollection(); @@ -332,6 +344,15 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl cerr << scoreVector[i] << " "; cerr << endl; + vector a = statistics->fst; + vector b = statistics->ft; + vector c = multimodelweights[0]; + float d = m_combineFunction(statistics->fst, statistics->ft, multimodelweights[0]); + outVec(a); + outVec(b); + outVec(c); + cerr << d << endl; + statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); } catch (AlignmentException& e) { @@ -349,12 +370,13 @@ TargetPhraseCollection* PhraseDictionaryMultiModelCounts::CreateTargetPhraseColl float PhraseDictionaryMultiModelCounts::GetTargetCount(const Phrase &target, size_t modelIndex) const { - TargetPhraseCollection *ret_raw = (TargetPhraseCollection*) m_inverse_pd[modelIndex]->GetTargetPhraseCollection(target); + const PhraseDictionary &pd = *m_inverse_pd[modelIndex]; + TargetPhraseCollection *ret_raw = (TargetPhraseCollection*) pd.GetTargetPhraseCollection(target); // in inverse mode, we want the first score of the first phrase pair (note: if we were to work with truly symmetric models, it would be the third score) if (ret_raw != NULL) { TargetPhrase * targetPhrase = *(ret_raw->begin()); - return UntransformScore(targetPhrase->GetScoreBreakdown().GetScoresForProducer(this)[0]); + return UntransformScore(targetPhrase->GetScoreBreakdown().GetScoresForProducer(&pd)[0]); } // target phrase unknown