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-10-26 18:24:53 +0300
committerMichael Denkowski <mdenkows@amazon.com>2015-10-26 19:42:42 +0300
commitd3f3389f20bb49830b3837370ca96543e4093660 (patch)
treef75bac6d6952b756a115e34cde051a17f8fc4473 /moses/BitmapContainer.cpp
parent6a37dfd2ce279e8493e151b505215eb9f21865f9 (diff)
More deterministic tie-breaking for cube pruning (--cbds)
Doesn't slow down regular non-deterministic cube pruning
Diffstat (limited to 'moses/BitmapContainer.cpp')
-rw-r--r--moses/BitmapContainer.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/moses/BitmapContainer.cpp b/moses/BitmapContainer.cpp
index 54207ba07..7adadee82 100644
--- a/moses/BitmapContainer.cpp
+++ b/moses/BitmapContainer.cpp
@@ -51,9 +51,14 @@ public:
class HypothesisScoreOrdererWithDistortion
{
+private:
+ bool m_deterministic;
+
public:
- HypothesisScoreOrdererWithDistortion(const Range* transOptRange) :
- m_transOptRange(transOptRange) {
+ HypothesisScoreOrdererWithDistortion(const Range* transOptRange,
+ const bool deterministic = false)
+ : m_transOptRange(transOptRange)
+ , m_deterministic(deterministic) {
m_totalWeightDistortion = 0;
const StaticData &staticData = StaticData::Instance();
@@ -97,6 +102,11 @@ public:
} else if (scoreA < scoreB) {
return false;
} else {
+ if (m_deterministic) {
+ // Equal scores: break ties by comparing target phrases
+ return (hypoA->GetCurrTargetPhrase().Compare(hypoB->GetCurrTargetPhrase()) < 0);
+ }
+ // Fallback: non-deterministic sort
return hypoA < hypoB;
}
}
@@ -111,13 +121,15 @@ BackwardsEdge::BackwardsEdge(const BitmapContainer &prevBitmapContainer
, BitmapContainer &parent
, const TranslationOptionList &translations
, const SquareMatrix &futureScores,
- const InputType& itype)
+ const InputType& itype,
+ const bool deterministic)
: m_initialized(false)
, m_prevBitmapContainer(prevBitmapContainer)
, m_parent(parent)
, m_translations(translations)
, m_futureScores(futureScores)
, m_seenPosition()
+ , m_deterministic(deterministic)
{
// If either dimension is empty, we haven't got anything to do.
@@ -174,7 +186,7 @@ BackwardsEdge::BackwardsEdge(const BitmapContainer &prevBitmapContainer
<< m_hypotheses[1]->GetTotalScore());
}
- HypothesisScoreOrdererWithDistortion orderer (&transOptRange);
+ HypothesisScoreOrdererWithDistortion orderer (&transOptRange, m_deterministic);
std::sort(m_hypotheses.begin(), m_hypotheses.end(), orderer);
// std::sort(m_hypotheses.begin(), m_hypotheses.end(), HypothesisScoreOrdererNoDistortion());
@@ -478,7 +490,7 @@ BitmapContainer::ProcessBestHypothesis()
void
BitmapContainer::SortHypotheses()
{
- std::sort(m_hypotheses.begin(), m_hypotheses.end(), HypothesisScoreOrderer());
+ std::sort(m_hypotheses.begin(), m_hypotheses.end(), HypothesisScoreOrderer(m_deterministic));
}
}