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:
authorMichael Denkowski <mdenkows@amazon.com>2015-09-25 12:03:23 +0300
committerMichael Denkowski <mdenkows@amazon.com>2015-09-25 12:03:23 +0300
commit56e3bc1ea209540bc0ade9797e6dfba578738e1d (patch)
treea3594bc0cd9783e3d109f374a9e20b323e736a5e /moses/BitmapContainer.h
parentd2a6aa752e91ce62bd746a704b1a7e7534fdbb59 (diff)
Reintroduce deterministic cube pruning as option
Use --cube-pruning-deterministic-search or --cbds
Diffstat (limited to 'moses/BitmapContainer.h')
-rw-r--r--moses/BitmapContainer.h50
1 files changed, 28 insertions, 22 deletions
diff --git a/moses/BitmapContainer.h b/moses/BitmapContainer.h
index 500059081..88bc79efe 100644
--- a/moses/BitmapContainer.h
+++ b/moses/BitmapContainer.h
@@ -61,6 +61,7 @@ private:
size_t m_hypothesis_pos, m_translation_pos;
Hypothesis *m_hypothesis;
BackwardsEdge *m_edge;
+ boost::shared_ptr<TargetPhrase> m_target_phrase;
HypothesisQueueItem();
@@ -68,11 +69,16 @@ public:
HypothesisQueueItem(const size_t hypothesis_pos
, const size_t translation_pos
, Hypothesis *hypothesis
- , BackwardsEdge *edge)
+ , BackwardsEdge *edge
+ , const TargetPhrase *target_phrase = NULL)
: m_hypothesis_pos(hypothesis_pos)
, m_translation_pos(translation_pos)
, m_hypothesis(hypothesis)
, m_edge(edge) {
+ if (target_phrase != NULL)
+ {
+ m_target_phrase.reset(new TargetPhrase(*target_phrase));
+ }
}
~HypothesisQueueItem() {
@@ -93,6 +99,10 @@ public:
BackwardsEdge *GetBackwardsEdge() {
return m_edge;
}
+
+ boost::shared_ptr<TargetPhrase> GetTargetPhrase() {
+ return m_target_phrase;
+ }
};
//! Allows comparison of two HypothesisQueueItem objects by the corresponding scores.
@@ -103,20 +113,26 @@ public:
float scoreA = itemA->GetHypothesis()->GetTotalScore();
float scoreB = itemB->GetHypothesis()->GetTotalScore();
- return (scoreA < scoreB);
-
- /*
+ if (scoreA < scoreB)
{
- return true;
+ return true;
}
- else if (scoreA < scoreB)
+ else if (scoreA > scoreB)
{
- return false;
+ return false;
}
else
{
- return itemA < itemB;
- }*/
+ // Equal scores: break ties by comparing target phrases (if they exist)
+ boost::shared_ptr<TargetPhrase> phrA = itemA->GetTargetPhrase();
+ boost::shared_ptr<TargetPhrase> phrB = itemB->GetTargetPhrase();
+ if (!phrA || !phrB)
+ {
+ // Fallback: scoreA < scoreB == false, non-deterministic sort
+ return false;
+ }
+ return (phrA->Compare(*phrB) < 0);
+ }
}
};
@@ -134,18 +150,6 @@ public:
float scoreB = hypoB->GetTotalScore();
return (scoreA > scoreB);
- /*
- {
- return true;
- }
- else if (scoreA < scoreB)
- {
- return false;
- }
- else
- {
- return hypoA < hypoB;
- }*/
}
};
@@ -210,13 +214,15 @@ private:
BackwardsEdgeSet m_edges;
HypothesisQueue m_queue;
size_t m_numStackInsertions;
+ bool m_deterministic;
// We always require a corresponding bitmap to be supplied.
BitmapContainer();
BitmapContainer(const BitmapContainer &);
public:
BitmapContainer(const WordsBitmap &bitmap
- , HypothesisStackCubePruning &stack);
+ , HypothesisStackCubePruning &stack
+ , bool deterministic_sort = false);
// The destructor will also delete all the edges that are
// connected to this BitmapContainer.