mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-26 19:37:58 +03:00
add -feature-name-overwrite. Specifically to replace PhraseDictionaryMemory with PhraseDictionaryScope3 for scope-3 decoding
This commit is contained in:
parent
a57c9d6fe8
commit
028edf8550
@ -192,6 +192,7 @@ Parameter::Parameter()
|
||||
AddParam("weight-overwrite", "special parameter for mert. All on 1 line. Overrides weights specified in 'weights' argument");
|
||||
AddParam("feature-overwrite", "Override arguments in a particular feature function with a particular key");
|
||||
AddParam("feature-add", "Add a feature function on the command line. Used by mira to add BLEU feature");
|
||||
AddParam("feature-name-overwrite", "Override feature name (NOT arguments). Eg. SRILM-->KENLM, PhraseDictionaryMemory-->PhraseDictionaryScope3");
|
||||
|
||||
AddParam("feature", "All the feature functions should be here");
|
||||
AddParam("print-id", "prefix translations with id. Default if false");
|
||||
|
@ -500,6 +500,7 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
m_placeHolderFactor = NOT_FOUND;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> featureNameOverride = OverrideFeatureNames();
|
||||
|
||||
// all features
|
||||
map<string, int> featureIndexMap;
|
||||
@ -513,9 +514,20 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
|
||||
vector<string> toks = Tokenize(line);
|
||||
|
||||
const string &feature = toks[0];
|
||||
string &feature = toks[0];
|
||||
std::map<std::string, std::string>::const_iterator iter = featureNameOverride.find(feature);
|
||||
if (iter == featureNameOverride.end()) {
|
||||
// feature name not override
|
||||
m_registry.Construct(feature, line);
|
||||
}
|
||||
else {
|
||||
// replace feature name with new name
|
||||
string newName = iter->second;
|
||||
feature = newName;
|
||||
string newLine = Join(" ", toks);
|
||||
m_registry.Construct(newName, newLine);
|
||||
}
|
||||
|
||||
m_registry.Construct(feature, line);
|
||||
}
|
||||
|
||||
NoCache();
|
||||
@ -746,7 +758,7 @@ bool StaticData::LoadDecodeGraphs()
|
||||
|
||||
void StaticData::ReLoadParameter()
|
||||
{
|
||||
assert(false); // TODO completely redo. Too many hardcoded ff
|
||||
UTIL_THROW(util::Exception, "completely redo. Too many hardcoded ff"); // TODO completely redo. Too many hardcoded ff
|
||||
/*
|
||||
m_verboseLevel = 1;
|
||||
if (m_parameter->GetParam("verbose").size() == 1) {
|
||||
@ -1065,6 +1077,26 @@ void StaticData::NoCache()
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> StaticData::OverrideFeatureNames()
|
||||
{
|
||||
std::map<std::string, std::string> ret;
|
||||
|
||||
const PARAM_VEC ¶ms = m_parameter->GetParam("feature-name-overwrite");
|
||||
if (params.size()) {
|
||||
UTIL_THROW_IF2(params.size() != 1, "Only provide 1 line in the section [feature-name-overwrite]");
|
||||
vector<string> toks = Tokenize(params[0]);
|
||||
UTIL_THROW_IF2(toks.size() % 2 == 0, "Format of -feature-name-overwrite must be [old-name new-name]*");
|
||||
|
||||
for (size_t i = 0; i < toks.size(); i += 2) {
|
||||
const string &oldName = toks[i];
|
||||
const string &newName = toks[i+1];
|
||||
ret[oldName] = newName;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void StaticData::OverrideFeatures()
|
||||
{
|
||||
const PARAM_VEC ¶ms = m_parameter->GetParam("feature-overwrite");
|
||||
|
@ -733,6 +733,7 @@ public:
|
||||
bool LoadWeightSettings();
|
||||
bool LoadAlternateWeightSettings();
|
||||
|
||||
std::map<std::string, std::string> OverrideFeatureNames();
|
||||
void OverrideFeatures();
|
||||
|
||||
FactorType GetPlaceholderFactor() const {
|
||||
|
Loading…
Reference in New Issue
Block a user