From ff188c454a14f112d7de1df65f600574fc033713 Mon Sep 17 00:00:00 2001 From: Barry Haddow Date: Wed, 6 Aug 2014 11:38:51 +0100 Subject: Sparse features trainable with hg mira (In phrase-based Moses) --- moses/ScoreComponentCollection.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'moses/ScoreComponentCollection.cpp') diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index 52ec00dd4..d4df4742e 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -179,25 +179,31 @@ void ScoreComponentCollection::SparseL2Regularize(float lambda) m_scores.sparseL2regularize(lambda); } -void ScoreComponentCollection::Save(ostream& out) const +void ScoreComponentCollection::Save(ostream& out, bool multiline) const { + string sep = " "; + string linesep = "\n"; + if (!multiline) { + sep = "="; + linesep = " "; + } ScoreIndexMap::const_iterator iter = s_scoreIndexes.begin(); for (; iter != s_scoreIndexes.end(); ++iter ) { string name = iter->first->GetScoreProducerDescription(); IndexPair ip = iter->second; // feature indices if (ip.second-ip.first == 1) { - out << name << " " << m_scores[ip.first] << endl; + out << name << sep << m_scores[ip.first] << linesep; } else { for (size_t i=ip.first; i < ip.second; ++i) { ostringstream fullname; fullname << name << "_" << (i + 1 - ip.first); - out << fullname.str() << " " << m_scores[i] << endl; + out << fullname.str() << sep << m_scores[i] << linesep; } } } // write sparse features - m_scores.write(out); + m_scores.write(out,sep); } void ScoreComponentCollection::Save(const string& filename) const -- cgit v1.2.3