Merge github.com:moses-smt/mosesdecoder into hieu_opt_input

This commit is contained in:
Hieu Hoang 2013-07-19 13:42:21 +01:00
commit 320f7d575d
5 changed files with 26 additions and 15 deletions

View File

@ -67,7 +67,17 @@ class FeatureFactory {
template <class F> void FeatureFactory::DefaultSetup(F *feature) {
StaticData &static_data = StaticData::InstanceNonConst();
static_data.SetWeights(feature, static_data.GetParameter()->GetWeights(feature->GetScoreProducerDescription()));
std::vector<float> &weights = static_data.GetParameter()->GetWeights(feature->GetScoreProducerDescription());
if (feature->IsTuneable() || weights.size()) {
// if it's tuneable, ini file MUST have weights
// even it it's not tuneable, people can still set the weights in the ini file
static_data.SetWeights(feature, weights);
}
else {
std::vector<float> defaultWeights = feature->DefaultWeights();
static_data.SetWeights(feature, defaultWeights);
}
}
namespace {
@ -86,19 +96,6 @@ class KenFactory : public FeatureFactory {
}
};
//WTF(hieu): unknown word should be a normal feature
class UnknownFactory : public FeatureFactory {
public:
void Create(const std::string &line) {
StaticData &static_data = StaticData::InstanceNonConst();
UnknownWordPenaltyProducer *f = new UnknownWordPenaltyProducer(line);
std::vector<float> weights = static_data.GetParameter()->GetWeights(f->GetScoreProducerDescription());
if (weights.empty())
weights.push_back(1.0f);
static_data.SetWeights(f, weights);
}
};
#ifdef LM_RAND
class RandFactory : public FeatureFactory {
public:
@ -141,6 +138,8 @@ FeatureRegistry::FeatureRegistry() {
MOSES_FNAME(PhraseDictionaryDynSuffixArray);
MOSES_FNAME(OpSequenceModel);
MOSES_FNAME(PhrasePenalty);
MOSES_FNAME2("UnknownWordPenalty", UnknownWordPenaltyProducer);
#ifdef HAVE_SYNLM
MOSES_FNAME(SyntacticLanguageModel);
#endif
@ -154,7 +153,6 @@ FeatureRegistry::FeatureRegistry() {
Add("RANDLM", new RandFactory());
#endif
Add("KENLM", new KenFactory());
Add("UnknownWordPenalty", new UnknownFactory());
}
FeatureRegistry::~FeatureRegistry() {}

View File

@ -109,5 +109,10 @@ void FeatureFunction::ReadParameters()
}
}
std::vector<float> FeatureFunction::DefaultWeights() const
{
UTIL_THROW(util::Exception, "No default weights");
}
}

View File

@ -78,6 +78,7 @@ public:
virtual bool IsTuneable() const {
return m_tuneable;
}
virtual std::vector<float> DefaultWeights() const;
//! Called before search and collecting of translation options
virtual void InitializeForInput(InputType const& source) {

View File

@ -13,5 +13,11 @@ UnknownWordPenaltyProducer::UnknownWordPenaltyProducer(const std::string &line)
ReadParameters();
}
std::vector<float> UnknownWordPenaltyProducer::DefaultWeights() const
{
std::vector<float> ret(1, 1.0f);
return ret;
}
}

View File

@ -20,6 +20,7 @@ public:
bool IsUseable(const FactorMask &mask) const {
return true;
}
std::vector<float> DefaultWeights() const;
};