mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 22:14:57 +03:00
Merge github.com:moses-smt/mosesdecoder into hieu_opt_input
This commit is contained in:
commit
320f7d575d
@ -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() {}
|
||||
|
@ -109,5 +109,10 @@ void FeatureFunction::ReadParameters()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float> FeatureFunction::DefaultWeights() const
|
||||
{
|
||||
UTIL_THROW(util::Exception, "No default weights");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ public:
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
}
|
||||
std::vector<float> DefaultWeights() const;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user