diff options
author | Matthias Huck <huck@i6.informatik.rwth-aachen.de> | 2015-04-23 20:13:02 +0300 |
---|---|---|
committer | Matthias Huck <huck@i6.informatik.rwth-aachen.de> | 2015-04-23 20:13:02 +0300 |
commit | f24f31f965abd3b3e02b48f7aaaf17a8003a4b8f (patch) | |
tree | 469a534918c66b69083d4803f87eee46f3621d31 /moses/TrellisPath.cpp | |
parent | 388e180afc77409558f46f4899815163a09a8681 (diff) |
n-best list creation in phrase-based decoding: improved efficiency with sparse features
Diffstat (limited to 'moses/TrellisPath.cpp')
-rw-r--r-- | moses/TrellisPath.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/moses/TrellisPath.cpp b/moses/TrellisPath.cpp index e76adc2db..36397e006 100644 --- a/moses/TrellisPath.cpp +++ b/moses/TrellisPath.cpp @@ -31,7 +31,6 @@ namespace Moses TrellisPath::TrellisPath(const Hypothesis *hypo) : m_prevEdgeChanged(NOT_FOUND) { - m_scoreBreakdown = hypo->GetScoreBreakdown(); m_totalScore = hypo->GetTotalScore(); // enumerate path using prevHypo @@ -41,10 +40,9 @@ TrellisPath::TrellisPath(const Hypothesis *hypo) } } -void TrellisPath::InitScore() +void TrellisPath::InitTotalScore() { m_totalScore = m_path[0]->GetWinningHypo()->GetTotalScore(); - m_scoreBreakdown= m_path[0]->GetWinningHypo()->GetScoreBreakdown(); //calc score size_t sizePath = m_path.size(); @@ -53,12 +51,8 @@ void TrellisPath::InitScore() const Hypothesis *winningHypo = hypo->GetWinningHypo(); if (hypo != winningHypo) { m_totalScore = m_totalScore - winningHypo->GetTotalScore() + hypo->GetTotalScore(); - m_scoreBreakdown.MinusEquals(winningHypo->GetScoreBreakdown()); - m_scoreBreakdown.PlusEquals(hypo->GetScoreBreakdown()); } } - - } TrellisPath::TrellisPath(const TrellisPath ©, size_t edgeIndex, const Hypothesis *arc) @@ -80,7 +74,7 @@ TrellisPath::TrellisPath(const TrellisPath ©, size_t edgeIndex, const Hypoth prevHypo = prevHypo->GetPrevHypo(); } - InitScore(); + InitTotalScore(); } TrellisPath::TrellisPath(const vector<const Hypothesis*> edges) @@ -88,9 +82,7 @@ TrellisPath::TrellisPath(const vector<const Hypothesis*> edges) { m_path.resize(edges.size()); copy(edges.rbegin(),edges.rend(),m_path.begin()); - InitScore(); - - + InitTotalScore(); } @@ -172,6 +164,32 @@ void TrellisPath::CreateDeviantPaths(TrellisPathList &pathColl) const } } +const boost::shared_ptr<ScoreComponentCollection> TrellisPath::GetScoreBreakdown() const +{ + if (!m_scoreBreakdown) { + float totalScore = m_path[0]->GetWinningHypo()->GetTotalScore(); // calculated for sanity check only + + m_scoreBreakdown = boost::shared_ptr<ScoreComponentCollection>(new ScoreComponentCollection()); + m_scoreBreakdown->PlusEquals(ScoreComponentCollection(m_path[0]->GetWinningHypo()->GetScoreBreakdown())); + + //calc score + size_t sizePath = m_path.size(); + for (size_t pos = 0 ; pos < sizePath ; pos++) { + const Hypothesis *hypo = m_path[pos]; + const Hypothesis *winningHypo = hypo->GetWinningHypo(); + if (hypo != winningHypo) { + totalScore = totalScore - winningHypo->GetTotalScore() + hypo->GetTotalScore(); + m_scoreBreakdown->MinusEquals(winningHypo->GetScoreBreakdown()); + m_scoreBreakdown->PlusEquals(hypo->GetScoreBreakdown()); + } + } + + assert(totalScore == m_totalScore); + } + + return m_scoreBreakdown; +} + Phrase TrellisPath::GetTargetPhrase() const { Phrase targetPhrase(ARRAY_SIZE_INCR); |