add -feature-name-overwrite. Specifically to replace PhraseDictionaryMemory with PhraseDictionaryScope3 for scope-3 decoding

This commit is contained in:
Hieu Hoang 2013-11-22 19:13:09 +00:00
parent a57c9d6fe8
commit 028edf8550
3 changed files with 37 additions and 3 deletions

View File

@ -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");

View File

@ -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 &params = 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 &params = m_parameter->GetParam("feature-overwrite");

View File

@ -733,6 +733,7 @@ public:
bool LoadWeightSettings();
bool LoadAlternateWeightSettings();
std::map<std::string, std::string> OverrideFeatureNames();
void OverrideFeatures();
FactorType GetPlaceholderFactor() const {