Browse files

Fixed some bugs in BatchMira's sparse feature handling.

  • Loading branch information...
1 parent 06f7615 commit a901fc9f5089a0ac358a7507c7a188544c7214a1 @cherryc cherryc committed Jun 14, 2012
Showing with 8 additions and 5 deletions.
  1. +2 −2 mert/MiraFeatureVector.cpp
  2. +6 −3 mert/kbmira.cpp
View
4 mert/MiraFeatureVector.cpp
@@ -58,14 +58,14 @@ ValType MiraFeatureVector::val(size_t index) const {
if(index < m_dense.size())
return m_dense[index];
else
- return m_sparseVals[index];
+ return m_sparseVals[index-m_dense.size()];
}
size_t MiraFeatureVector::feat(size_t index) const {
if(index < m_dense.size())
return index;
else
- return m_sparseFeats[index];
+ return m_sparseFeats[index-m_dense.size()];
}
size_t MiraFeatureVector::size() const {
View
9 mert/kbmira.cpp
@@ -129,14 +129,17 @@ int main(int argc, char** argv)
vector<parameter_t> initParams;
if(!denseInitFile.empty()) {
ifstream opt(denseInitFile.c_str());
- string buffer; istringstream strstrm(buffer);
+ string buffer;
if (opt.fail()) {
cerr << "could not open dense initfile: " << denseInitFile << endl;
exit(3);
}
parameter_t val;
getline(opt,buffer);
- while(strstrm >> val) initParams.push_back(val);
+ istringstream strstrm(buffer);
+ while(strstrm >> val) {
+ initParams.push_back(val);
+ }
opt.close();
}
size_t initDenseSize = initParams.size();
@@ -225,7 +228,7 @@ int main(int argc, char** argv)
ValType hopeBleu = sentenceLevelBackgroundBleu(hope_stats, bg);
const vector<float>& fear_stats = train->scoresAt(fear_index);
ValType fearBleu = sentenceLevelBackgroundBleu(fear_stats, bg);
- assert(hopeBleu > fearBleu);
+ assert(hopeBleu + 1e-8 >= fearBleu);
ValType delta = hopeBleu - fearBleu;
// Loss and update
ValType diff_score = wv.score(diff);

0 comments on commit a901fc9

Please sign in to comment.