Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Huck <huck@i6.informatik.rwth-aachen.de>2015-01-07 17:25:43 +0300
committerMatthias Huck <huck@i6.informatik.rwth-aachen.de>2015-01-07 17:25:43 +0300
commit465b47566424efb707bdc063d0bff52b0650eb0a (patch)
tree1d4b351a6bdd9be80ead4b7675c28fdbf3b79fb3 /moses/ChartHypothesis.h
parent0441fd6ab9600915297bcec1702f56fa5feedf98 (diff)
score deltas in chart decoding
Diffstat (limited to 'moses/ChartHypothesis.h')
-rw-r--r--moses/ChartHypothesis.h102
1 files changed, 79 insertions, 23 deletions
diff --git a/moses/ChartHypothesis.h b/moses/ChartHypothesis.h
index 8dc26e721..ecd35b867 100644
--- a/moses/ChartHypothesis.h
+++ b/moses/ChartHypothesis.h
@@ -21,6 +21,7 @@
#pragma once
#include <vector>
+#include <boost/scoped_ptr.hpp>
#include "Util.h"
#include "WordsRange.h"
#include "ScoreComponentCollection.h"
@@ -45,7 +46,7 @@ typedef std::vector<ChartHypothesis*> ChartArcList;
class ChartHypothesis
{
friend std::ostream& operator<<(std::ostream&, const ChartHypothesis&);
- friend class ChartKBestExtractor;
+// friend class ChartKBestExtractor;
protected:
#ifdef USE_HYPO_POOL
@@ -56,7 +57,10 @@ protected:
WordsRange m_currSourceWordsRange;
std::vector<const FFState*> m_ffStates; /*! stateful feature function states */
- ScoreComponentCollection m_scoreBreakdown /*! detailed score break-down by components (for instance language model, word penalty, etc) */
+ /*! sum of scores of this hypothesis, and previous hypotheses. Lazily initialised. */
+ mutable boost::scoped_ptr<ScoreComponentCollection> m_scoreBreakdown;
+ mutable boost::scoped_ptr<ScoreComponentCollection> m_deltaScoreBreakdown;
+ ScoreComponentCollection m_currScoreBreakdown /*! scores for this hypothesis only */
,m_lmNGram
,m_lmPrefix;
float m_totalScore;
@@ -76,23 +80,23 @@ protected:
//! not implemented
ChartHypothesis(const ChartHypothesis &copy);
- //! only used by ChartKBestExtractor
- ChartHypothesis(const ChartHypothesis &, const ChartKBestExtractor &);
-
public:
#ifdef USE_HYPO_POOL
- void *operator new(size_t /* num_bytes */) {
+ void *operator new(size_t /* num_bytes */)
+ {
void *ptr = s_objectPool.getPtr();
return ptr;
}
//! delete \param hypo. Works with object pool too
- static void Delete(ChartHypothesis *hypo) {
+ static void Delete(ChartHypothesis *hypo)
+ {
s_objectPool.freeObject(hypo);
}
#else
//! delete \param hypo. Works with object pool too
- static void Delete(ChartHypothesis *hypo) {
+ static void Delete(ChartHypothesis *hypo)
+ {
delete hypo;
}
#endif
@@ -100,38 +104,48 @@ public:
ChartHypothesis(const ChartTranslationOptions &, const RuleCubeItem &item,
ChartManager &manager);
+ //! only used by ChartKBestExtractor
+ ChartHypothesis(const ChartHypothesis &, const ChartKBestExtractor &);
+
~ChartHypothesis();
- unsigned GetId() const {
+ unsigned GetId() const
+ {
return m_id;
}
- const ChartTranslationOption &GetTranslationOption()const {
+ const ChartTranslationOption &GetTranslationOption() const
+ {
return *m_transOpt;
}
//! Get the rule that created this hypothesis
- const TargetPhrase &GetCurrTargetPhrase()const {
+ const TargetPhrase &GetCurrTargetPhrase() const
+ {
return m_transOpt->GetPhrase();
}
//! the source range that this hypothesis spans
- const WordsRange &GetCurrSourceRange()const {
+ const WordsRange &GetCurrSourceRange() const
+ {
return m_currSourceWordsRange;
}
//! the arc list when creating n-best lists
- inline const ChartArcList* GetArcList() const {
+ inline const ChartArcList* GetArcList() const
+ {
return m_arcList;
}
//! the feature function states for a particular feature \param featureID
- inline const FFState* GetFFState( size_t featureID ) const {
+ inline const FFState* GetFFState( size_t featureID ) const
+ {
return m_ffStates[ featureID ];
}
//! reference back to the manager
- inline const ChartManager& GetManager() const {
+ inline const ChartManager& GetManager() const
+ {
return m_manager;
}
@@ -140,7 +154,7 @@ public:
// get leftmost/rightmost words only
// leftRightMost: 1=left, 2=right
- void GetOutputPhrase(int leftRightMost, int numWords, Phrase &outPhrase) const;
+ void GetOutputPhrase(size_t leftRightMost, size_t numWords, Phrase &outPhrase) const;
int RecombineCompare(const ChartHypothesis &compare) const;
@@ -151,32 +165,74 @@ public:
void SetWinningHypo(const ChartHypothesis *hypo);
//! get the unweighted score for each feature function
- const ScoreComponentCollection &GetScoreBreakdown() const {
- return m_scoreBreakdown;
+ const ScoreComponentCollection &GetScoreBreakdown() const
+ {
+ // Note: never call this method before m_currScoreBreakdown is fully computed
+ if (!m_scoreBreakdown.get())
+ {
+ m_scoreBreakdown.reset(new ScoreComponentCollection());
+ // score breakdown from current translation rule
+ if (m_transOpt)
+ {
+ m_scoreBreakdown->PlusEquals(GetTranslationOption().GetScores());
+ }
+ m_scoreBreakdown->PlusEquals(m_currScoreBreakdown);
+ // score breakdowns from prev hypos
+ for (std::vector<const ChartHypothesis*>::const_iterator iter = m_prevHypos.begin(); iter != m_prevHypos.end(); ++iter)
+ {
+ const ChartHypothesis &prevHypo = **iter;
+ m_scoreBreakdown->PlusEquals(prevHypo.GetScoreBreakdown());
+ }
+ }
+ return *(m_scoreBreakdown.get());
+ }
+
+ //! get the unweighted score delta for each feature function
+ const ScoreComponentCollection &GetDeltaScoreBreakdown() const
+ {
+ // Note: never call this method before m_currScoreBreakdown is fully computed
+ if (!m_deltaScoreBreakdown.get())
+ {
+ m_deltaScoreBreakdown.reset(new ScoreComponentCollection());
+ // score breakdown from current translation rule
+ if (m_transOpt)
+ {
+ m_deltaScoreBreakdown->PlusEquals(GetTranslationOption().GetScores());
+ }
+ m_deltaScoreBreakdown->PlusEquals(m_currScoreBreakdown);
+ // delta: score breakdowns from prev hypos _not_ added
+ }
+ return *(m_deltaScoreBreakdown.get());
}
//! Get the weighted total score
- float GetTotalScore() const {
+ float GetTotalScore() const
+ {
+ // scores from current translation rule. eg. translation models & word penalty
return m_totalScore;
}
//! vector of previous hypotheses this hypo is built on
- const std::vector<const ChartHypothesis*> &GetPrevHypos() const {
+ const std::vector<const ChartHypothesis*> &GetPrevHypos() const
+ {
return m_prevHypos;
}
//! get a particular previous hypos
- const ChartHypothesis* GetPrevHypo(size_t pos) const {
+ const ChartHypothesis* GetPrevHypo(size_t pos) const
+ {
return m_prevHypos[pos];
}
//! get the constituency label that covers this hypo
- const Word &GetTargetLHS() const {
+ const Word &GetTargetLHS() const
+ {
return GetCurrTargetPhrase().GetTargetLHS();
}
//! get the best hypo in the arc list when doing n-best list creation. It's either this hypothesis, or the best hypo is this hypo is in the arc list
- const ChartHypothesis* GetWinningHypothesis() const {
+ const ChartHypothesis* GetWinningHypothesis() const
+ {
return m_winningHypo;
}