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:
-rw-r--r--moses/DecodeFeature.cpp12
-rw-r--r--moses/DecodeFeature.h4
-rw-r--r--moses/DecodeStep.cpp8
-rw-r--r--moses/FF/BleuScoreFeature.cpp6
-rw-r--r--moses/FF/BleuScoreFeature.h3
-rw-r--r--moses/FF/DistortionScoreProducer.h3
-rw-r--r--moses/FF/FeatureFunction.h3
-rw-r--r--moses/FF/GlobalLexicalModel.cpp13
-rw-r--r--moses/FF/GlobalLexicalModel.h2
-rw-r--r--moses/FF/PhraseBoundaryFeature.cpp10
-rw-r--r--moses/FF/PhraseBoundaryFeature.h2
-rw-r--r--moses/FF/PhraseLengthFeature.h3
-rw-r--r--moses/FF/PhrasePairFeature.cpp6
-rw-r--r--moses/FF/PhrasePairFeature.h2
-rw-r--r--moses/FF/SourceWordDeletionFeature.h3
-rw-r--r--moses/FF/TargetBigramFeature.cpp6
-rw-r--r--moses/FF/TargetBigramFeature.h2
-rw-r--r--moses/FF/TargetNgramFeature.cpp6
-rw-r--r--moses/FF/TargetNgramFeature.h2
-rw-r--r--moses/FF/TargetWordInsertionFeature.cpp6
-rw-r--r--moses/FF/TargetWordInsertionFeature.h2
-rw-r--r--moses/FF/UnknownWordPenaltyProducer.h3
-rw-r--r--moses/FF/WordPenaltyProducer.h6
-rw-r--r--moses/FF/WordTranslationFeature.cpp6
-rw-r--r--moses/FF/WordTranslationFeature.h2
-rw-r--r--moses/LM/Ken.cpp8
-rw-r--r--moses/LM/SingleFactor.cpp6
-rw-r--r--moses/LM/SingleFactor.h2
-rw-r--r--moses/LexicalReordering.cpp11
-rw-r--r--moses/LexicalReordering.h2
-rw-r--r--moses/ScoreComponentCollectionTest.cpp9
31 files changed, 150 insertions, 9 deletions
diff --git a/moses/DecodeFeature.cpp b/moses/DecodeFeature.cpp
index 57137170e..dd950e82c 100644
--- a/moses/DecodeFeature.cpp
+++ b/moses/DecodeFeature.cpp
@@ -91,5 +91,17 @@ const std::vector<FactorType>& DecodeFeature::GetOutput() const
return m_output;
}
+bool DecodeFeature::IsUseable(const FactorMask &mask) const
+{
+ for (size_t i = 0; i < m_output.size(); ++i) {
+ const FactorType &factor = m_output[i];
+ if (!mask[factor]) {
+ return false;
+ }
+ }
+ return true;
+
+}
+
}
diff --git a/moses/DecodeFeature.h b/moses/DecodeFeature.h
index d6cf3a323..15092ee80 100644
--- a/moses/DecodeFeature.h
+++ b/moses/DecodeFeature.h
@@ -60,9 +60,7 @@ public:
const std::vector<FactorType>& GetInput() const;
const std::vector<FactorType>& GetOutput() const;
- bool IsDecodeFeature() const {
- return true;
- }
+ bool IsUseable(const FactorMask &mask) const;
protected:
std::vector<FactorType> m_input;
diff --git a/moses/DecodeStep.cpp b/moses/DecodeStep.cpp
index c8b2e36c1..f4f10e33b 100644
--- a/moses/DecodeStep.cpp
+++ b/moses/DecodeStep.cpp
@@ -49,7 +49,13 @@ DecodeStep::DecodeStep(const DecodeFeature *decodeFeature,
// find out which feature function can be applied in this decode step
for (size_t i = 0; i < features.size(); ++i) {
- const FeatureFunction *feature = features[i];
+ FeatureFunction *feature = features[i];
+ if (feature->IsUseable(m_outputFactors)) {
+ m_featuresToApply.push_back(feature);
+ }
+ else {
+ m_featuresRemaining.push_back(feature);
+ }
}
}
diff --git a/moses/FF/BleuScoreFeature.cpp b/moses/FF/BleuScoreFeature.cpp
index 7808d6012..e2e0b1317 100644
--- a/moses/FF/BleuScoreFeature.cpp
+++ b/moses/FF/BleuScoreFeature.cpp
@@ -865,5 +865,11 @@ const FFState* BleuScoreFeature::EmptyHypothesisState(const InputType& input) co
return new BleuScoreState();
}
+bool BleuScoreFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[0];
+ return 0;
+}
+
} // namespace.
diff --git a/moses/FF/BleuScoreFeature.h b/moses/FF/BleuScoreFeature.h
index 96e273672..39455dd9f 100644
--- a/moses/FF/BleuScoreFeature.h
+++ b/moses/FF/BleuScoreFeature.h
@@ -117,6 +117,9 @@ public:
bool Enabled() const {
return m_enabled;
}
+
+ bool IsUseable(const FactorMask &mask) const;
+
float CalculateBleu(BleuScoreState*) const;
float CalculateBleu(Phrase translation) const;
const FFState* EmptyHypothesisState(const InputType&) const;
diff --git a/moses/FF/DistortionScoreProducer.h b/moses/FF/DistortionScoreProducer.h
index 2601e6398..929d16c56 100644
--- a/moses/FF/DistortionScoreProducer.h
+++ b/moses/FF/DistortionScoreProducer.h
@@ -21,6 +21,9 @@ public:
: StatefulFeatureFunction("Distortion", 1, line)
{}
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
+
static float CalculateDistortionScore(const Hypothesis& hypo,
const WordsRange &prev, const WordsRange &curr, const int FirstGapPosition);
diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h
index f529e76e1..e06a032af 100644
--- a/moses/FF/FeatureFunction.h
+++ b/moses/FF/FeatureFunction.h
@@ -21,6 +21,7 @@ class InputType;
class ScoreComponentCollection;
class WordsBitmap;
class WordsRange;
+class FactorMask;
@@ -82,7 +83,7 @@ public:
return m_argLine;
}
- //virtual bool IsUseable() const = 0;
+ virtual bool IsUseable(const FactorMask &mask) const = 0;
virtual void Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase
diff --git a/moses/FF/GlobalLexicalModel.cpp b/moses/FF/GlobalLexicalModel.cpp
index cbc6811ee..4cff69140 100644
--- a/moses/FF/GlobalLexicalModel.cpp
+++ b/moses/FF/GlobalLexicalModel.cpp
@@ -183,4 +183,17 @@ void GlobalLexicalModel::Evaluate
GetFromCacheOrScorePhrase(context.GetTargetPhrase()) );
}
+bool GlobalLexicalModel::IsUseable(const FactorMask &mask) const
+{
+ for (size_t i = 0; i < m_outputFactors.size(); ++i) {
+ if (m_outputFactors[i]) {
+ if (!mask[i]) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
}
diff --git a/moses/FF/GlobalLexicalModel.h b/moses/FF/GlobalLexicalModel.h
index b3bf79b53..ac9ab71a5 100644
--- a/moses/FF/GlobalLexicalModel.h
+++ b/moses/FF/GlobalLexicalModel.h
@@ -67,6 +67,8 @@ public:
void InitializeForInput( Sentence const& in );
+ bool IsUseable(const FactorMask &mask) const;
+
void Evaluate(const PhraseBasedFeatureContext& context,
ScoreComponentCollection* accumulator) const;
diff --git a/moses/FF/PhraseBoundaryFeature.cpp b/moses/FF/PhraseBoundaryFeature.cpp
index ff73c760e..350495802 100644
--- a/moses/FF/PhraseBoundaryFeature.cpp
+++ b/moses/FF/PhraseBoundaryFeature.cpp
@@ -94,5 +94,15 @@ FFState* PhraseBoundaryFeature::Evaluate
return new PhraseBoundaryState(endSourceWord,endTargetWord);
}
+bool PhraseBoundaryFeature::IsUseable(const FactorMask &mask) const
+{
+ for (size_t i = 0; i < m_targetFactors.size(); ++i) {
+ const FactorType &factor = m_targetFactors[i];
+ if (!mask[factor]) {
+ return false;
+ }
+ }
+ return true;
+}
}
diff --git a/moses/FF/PhraseBoundaryFeature.h b/moses/FF/PhraseBoundaryFeature.h
index b06e66eea..f61faef66 100644
--- a/moses/FF/PhraseBoundaryFeature.h
+++ b/moses/FF/PhraseBoundaryFeature.h
@@ -40,7 +40,7 @@ class PhraseBoundaryFeature : public StatefulFeatureFunction
public:
PhraseBoundaryFeature(const std::string &line);
- size_t GetNumScoreComponents() const;
+ bool IsUseable(const FactorMask &mask) const;
virtual const FFState* EmptyHypothesisState(const InputType &) const;
diff --git a/moses/FF/PhraseLengthFeature.h b/moses/FF/PhraseLengthFeature.h
index 23c168417..40d517928 100644
--- a/moses/FF/PhraseLengthFeature.h
+++ b/moses/FF/PhraseLengthFeature.h
@@ -20,6 +20,9 @@ class PhraseLengthFeature : public StatelessFeatureFunction
public:
PhraseLengthFeature(const std::string &line);
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
+
void EvaluateChart(const ChartBasedFeatureContext& context,
ScoreComponentCollection*) const {
throw std::logic_error("PhraseLengthFeature not valid in chart decoder");
diff --git a/moses/FF/PhrasePairFeature.cpp b/moses/FF/PhrasePairFeature.cpp
index 9fce7ff4e..4ed69fb66 100644
--- a/moses/FF/PhrasePairFeature.cpp
+++ b/moses/FF/PhrasePairFeature.cpp
@@ -238,4 +238,10 @@ void PhrasePairFeature::Evaluate(
}
}
+bool PhrasePairFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_targetFactorId];
+ return ret;
+}
+
}
diff --git a/moses/FF/PhrasePairFeature.h b/moses/FF/PhrasePairFeature.h
index d7aa80be7..84d94f09b 100644
--- a/moses/FF/PhrasePairFeature.h
+++ b/moses/FF/PhrasePairFeature.h
@@ -34,6 +34,8 @@ class PhrasePairFeature: public StatelessFeatureFunction
public:
PhrasePairFeature(const std::string &line);
+ bool IsUseable(const FactorMask &mask) const;
+
void Evaluate(const PhraseBasedFeatureContext& context,
ScoreComponentCollection* accumulator) const;
diff --git a/moses/FF/SourceWordDeletionFeature.h b/moses/FF/SourceWordDeletionFeature.h
index 7a25ee6e1..1f4be834a 100644
--- a/moses/FF/SourceWordDeletionFeature.h
+++ b/moses/FF/SourceWordDeletionFeature.h
@@ -25,6 +25,9 @@ public:
bool Load(const std::string &filePath);
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
+
virtual void Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
diff --git a/moses/FF/TargetBigramFeature.cpp b/moses/FF/TargetBigramFeature.cpp
index fc30a737f..30819054e 100644
--- a/moses/FF/TargetBigramFeature.cpp
+++ b/moses/FF/TargetBigramFeature.cpp
@@ -113,5 +113,11 @@ FFState* TargetBigramFeature::Evaluate(const Hypothesis& cur_hypo,
return new TargetBigramState(targetPhrase.GetWord(targetPhrase.GetSize()-1));
}
+bool TargetBigramFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorType];
+ return ret;
+}
+
}
diff --git a/moses/FF/TargetBigramFeature.h b/moses/FF/TargetBigramFeature.h
index e29eace14..d90c6276a 100644
--- a/moses/FF/TargetBigramFeature.h
+++ b/moses/FF/TargetBigramFeature.h
@@ -35,6 +35,8 @@ public:
bool Load(const std::string &filePath);
+ bool IsUseable(const FactorMask &mask) const;
+
virtual const FFState* EmptyHypothesisState(const InputType &input) const;
virtual FFState* Evaluate(const Hypothesis& cur_hypo, const FFState* prev_state,
diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp
index 3c36aef0e..a93e204ca 100644
--- a/moses/FF/TargetNgramFeature.cpp
+++ b/moses/FF/TargetNgramFeature.cpp
@@ -429,5 +429,11 @@ void TargetNgramFeature::MakeSuffixNgrams(std::vector<const Word*> &contextFacto
}
}
+bool TargetNgramFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorType];
+ return ret;
+}
+
}
diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h
index 8001f2f87..c15f54e49 100644
--- a/moses/FF/TargetNgramFeature.h
+++ b/moses/FF/TargetNgramFeature.h
@@ -182,6 +182,8 @@ public:
bool Load(const std::string &filePath);
+ bool IsUseable(const FactorMask &mask) const;
+
virtual const FFState* EmptyHypothesisState(const InputType &input) const;
virtual FFState* Evaluate(const Hypothesis& cur_hypo, const FFState* prev_state,
diff --git a/moses/FF/TargetWordInsertionFeature.cpp b/moses/FF/TargetWordInsertionFeature.cpp
index f20a652e4..27f2e4bc8 100644
--- a/moses/FF/TargetWordInsertionFeature.cpp
+++ b/moses/FF/TargetWordInsertionFeature.cpp
@@ -111,4 +111,10 @@ void TargetWordInsertionFeature::ComputeFeatures(const Phrase &source,
}
}
+bool TargetWordInsertionFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorType];
+ return ret;
+}
+
}
diff --git a/moses/FF/TargetWordInsertionFeature.h b/moses/FF/TargetWordInsertionFeature.h
index 50f7e5f88..ed8f1e249 100644
--- a/moses/FF/TargetWordInsertionFeature.h
+++ b/moses/FF/TargetWordInsertionFeature.h
@@ -23,6 +23,8 @@ private:
public:
TargetWordInsertionFeature(const std::string &line);
+ bool IsUseable(const FactorMask &mask) const;
+
bool Load(const std::string &filePath);
virtual void Evaluate(const Phrase &source
diff --git a/moses/FF/UnknownWordPenaltyProducer.h b/moses/FF/UnknownWordPenaltyProducer.h
index 200033cfc..a78b4552c 100644
--- a/moses/FF/UnknownWordPenaltyProducer.h
+++ b/moses/FF/UnknownWordPenaltyProducer.h
@@ -19,6 +19,9 @@ public:
m_tuneable = false;
}
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
+
};
}
diff --git a/moses/FF/WordPenaltyProducer.h b/moses/FF/WordPenaltyProducer.h
index 1892c459c..3fcddd128 100644
--- a/moses/FF/WordPenaltyProducer.h
+++ b/moses/FF/WordPenaltyProducer.h
@@ -8,14 +8,14 @@ namespace Moses
class TargetPhrase;
class ScoreComponentCollection;
-/** Doesn't do anything but provide a key into the global
- * score array to store the word penalty in.
- */
class WordPenaltyProducer : public StatelessFeatureFunction
{
public:
WordPenaltyProducer(const std::string &line) : StatelessFeatureFunction("WordPenalty",1, line) {}
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
+
virtual void Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown
diff --git a/moses/FF/WordTranslationFeature.cpp b/moses/FF/WordTranslationFeature.cpp
index 3f282609f..ad5c5c354 100644
--- a/moses/FF/WordTranslationFeature.cpp
+++ b/moses/FF/WordTranslationFeature.cpp
@@ -510,4 +510,10 @@ void WordTranslationFeature::EvaluateChart(
}
+bool WordTranslationFeature::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorTypeTarget];
+ return ret;
+}
+
}
diff --git a/moses/FF/WordTranslationFeature.h b/moses/FF/WordTranslationFeature.h
index b3a434325..3232669ad 100644
--- a/moses/FF/WordTranslationFeature.h
+++ b/moses/FF/WordTranslationFeature.h
@@ -37,6 +37,8 @@ private:
public:
WordTranslationFeature(const std::string &line);
+ bool IsUseable(const FactorMask &mask) const;
+
bool Load(const std::string &filePathSource, const std::string &filePathTarget);
const FFState* EmptyHypothesisState(const InputType &) const {
diff --git a/moses/LM/Ken.cpp b/moses/LM/Ken.cpp
index af24ad858..c91d2a7a2 100644
--- a/moses/LM/Ken.cpp
+++ b/moses/LM/Ken.cpp
@@ -88,6 +88,7 @@ public:
manager.LMCallback(*m_ngram, m_lmIdLookup);
}
+ bool IsUseable(const FactorMask &mask) const;
private:
LanguageModelKen(const LanguageModelKen<Model> &copy_from);
@@ -345,6 +346,13 @@ template <class Model> FFState *LanguageModelKen<Model>::EvaluateChart(const Cha
return newState;
}
+template <class Model>
+bool LanguageModelKen<Model>::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorType];
+ return ret;
+}
+
} // namespace
LanguageModel *ConstructKenLM(const std::string &description, const std::string &line)
diff --git a/moses/LM/SingleFactor.cpp b/moses/LM/SingleFactor.cpp
index abd8aca51..6247648f3 100644
--- a/moses/LM/SingleFactor.cpp
+++ b/moses/LM/SingleFactor.cpp
@@ -66,6 +66,12 @@ LMResult LanguageModelSingleFactor::GetValueForgotState(const std::vector<const
return GetValue(contextFactor, &static_cast<PointerState&>(outState).lmstate);
}
+bool LanguageModelSingleFactor::IsUseable(const FactorMask &mask) const
+{
+ bool ret = mask[m_factorType];
+ return ret;
+}
+
}
diff --git a/moses/LM/SingleFactor.h b/moses/LM/SingleFactor.h
index 9a1f30216..15e4ea834 100644
--- a/moses/LM/SingleFactor.h
+++ b/moses/LM/SingleFactor.h
@@ -51,6 +51,8 @@ public:
, FactorType factorType
, size_t nGramOrder) = 0;
+ bool IsUseable(const FactorMask &mask) const;
+
bool Useable(const Phrase &phrase) const {
return (phrase.GetSize()>0 && phrase.GetFactor(0, m_factorType) != NULL);
}
diff --git a/moses/LexicalReordering.cpp b/moses/LexicalReordering.cpp
index 98dca7b5f..80c5afa20 100644
--- a/moses/LexicalReordering.cpp
+++ b/moses/LexicalReordering.cpp
@@ -91,5 +91,16 @@ const FFState* LexicalReordering::EmptyHypothesisState(const InputType &input) c
return m_configuration->CreateLexicalReorderingState(input);
}
+bool LexicalReordering::IsUseable(const FactorMask &mask) const
+{
+ for (size_t i = 0; i < m_factorsE.size(); ++i) {
+ const FactorType &factor = m_factorsE[i];
+ if (!mask[factor]) {
+ return false;
+ }
+ }
+ return true;
+
+}
}
diff --git a/moses/LexicalReordering.h b/moses/LexicalReordering.h
index abaa31c25..812cfec27 100644
--- a/moses/LexicalReordering.h
+++ b/moses/LexicalReordering.h
@@ -30,6 +30,8 @@ public:
LexicalReordering(const std::string &line);
virtual ~LexicalReordering();
+ virtual bool IsUseable(const FactorMask &mask) const;
+
virtual const FFState* EmptyHypothesisState(const InputType &input) const;
void InitializeForInput(const InputType& i) {
diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp
index 41fa6562f..e948996dd 100644
--- a/moses/ScoreComponentCollectionTest.cpp
+++ b/moses/ScoreComponentCollectionTest.cpp
@@ -46,18 +46,27 @@ class MockSingleFeature : public MockStatelessFeatureFunction
{
public:
MockSingleFeature(): MockStatelessFeatureFunction("MockSingle",1, "MockSingle") {}
+
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
};
class MockMultiFeature : public MockStatelessFeatureFunction
{
public:
MockMultiFeature(): MockStatelessFeatureFunction("MockMulti", 5, "MockMulti") {}
+
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
};
class MockSparseFeature : public MockStatelessFeatureFunction
{
public:
MockSparseFeature(): MockStatelessFeatureFunction("MockSparse", 0, "MockSparse") {}
+
+ bool IsUseable(const FactorMask &mask) const
+ { return true; }
};