create ResetWeights(). Only for dense weights

This commit is contained in:
Hieu Hoang 2014-02-23 20:07:28 +00:00
parent 007799eb07
commit 1716514eda
3 changed files with 39 additions and 0 deletions

View File

@ -65,6 +65,11 @@
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/phrase-extract/OutputFileStream.h</locationURI>
</link>
<link>
<name>RuleExtractionOptions.h</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/phrase-extract/RuleExtractionOptions.h</locationURI>
</link>
<link>
<name>SentenceAlignment.cpp</name>
<type>1</type>

View File

@ -1184,5 +1184,36 @@ void StaticData::CheckLEGACYPT()
}
void StaticData::ResetWeights(const std::string &denseWeights, const std::string &sparseFile)
{
// dense weights
string name("");
vector<float> weights;
vector<string> toks = Tokenize(denseWeights);
for (size_t i = 0; i < toks.size(); ++i) {
const string &tok = toks[i];
if (tok.substr(tok.size() - 1, 1) == "=") {
// start of new feature
if (name != "") {
// save previous ff
const FeatureFunction &ff = FeatureFunction::FindFeatureFunction(name);
m_allWeights.Assign(&ff, weights);
weights.clear();
}
name = tok.substr(0, tok.size() - 1);
} else {
// a weight for curr ff
float weight = Scan<float>(toks[i]);
weights.push_back(weight);
}
}
// sparse weights
}
} // namespace

View File

@ -756,6 +756,9 @@ public:
bool AdjacentOnly() const
{ return m_adjacentOnly; }
void ResetWeights(const std::string &denseWeights, const std::string &sparseFile);
};
}