From 0a537a9f58b27d43098095531820db0c7a6c0a2a Mon Sep 17 00:00:00 2001 From: Eva Hasler Date: Thu, 29 Mar 2012 22:01:17 +0100 Subject: [PATCH] print feature counts to file --- mira/Main.cpp | 5 ++++- moses/src/FeatureVector.cpp | 4 ++-- moses/src/FeatureVector.h | 2 +- moses/src/ScoreComponentCollection.h | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mira/Main.cpp b/mira/Main.cpp index 447dab2ec..3c869a102 100644 --- a/mira/Main.cpp +++ b/mira/Main.cpp @@ -606,8 +606,10 @@ int main(int argc, char** argv) { string f1 = "decode_hope_epoch0"; string f2 = "decode_fear_epoch0"; + string s1 = "sparse_feature_hope_counts"; ofstream hopePlusFeatures(f1.c_str()); ofstream fearPlusFeatures(f2.c_str()); + ofstream sparseFeatureCounts(s1.c_str()); if (!hopePlusFeatures || !fearPlusFeatures) { ostringstream msg; msg << "Unable to open file"; @@ -1362,7 +1364,8 @@ int main(int argc, char** argv) { if (weightEpochDump == weightDumpFrequency && printFeatureInfo) { // print out all features with counts - mixedAverageWeights.PrintSparseFeatureCounts(); + mixedAverageWeights.PrintSparseFeatureCounts(sparseFeatureCounts); + sparseFeatureCounts.close(); } } } diff --git a/moses/src/FeatureVector.cpp b/moses/src/FeatureVector.cpp index 638690fa9..40ea8419c 100644 --- a/moses/src/FeatureVector.cpp +++ b/moses/src/FeatureVector.cpp @@ -323,9 +323,9 @@ namespace Moses { FName::incrementId((i->first).name()); } - void FVector::printSparseFeatureCounts() { + void FVector::printSparseFeatureCounts(std::ofstream& out) { for (const_iterator i = cbegin(); i != cend(); ++i) - std::cerr << (i->first).name() << ": " << FName::getIdCount((i->first).name()) << std::endl; + out << (i->first).name() << ": " << FName::getIdCount((i->first).name()) << std::endl; } size_t FVector::pruneSparseFeatures(size_t threshold) { diff --git a/moses/src/FeatureVector.h b/moses/src/FeatureVector.h index 38e23b9c6..6dd6d6d27 100644 --- a/moses/src/FeatureVector.h +++ b/moses/src/FeatureVector.h @@ -202,7 +202,7 @@ namespace Moses { void sparsePlusEquals(const FVector& rhs); void incrementSparseFeatures(); - void printSparseFeatureCounts(); + void printSparseFeatureCounts(std::ofstream& out); size_t pruneSparseFeatures(size_t threshold); size_t pruneZeroWeightFeatures(); diff --git a/moses/src/ScoreComponentCollection.h b/moses/src/ScoreComponentCollection.h index 3c2186d90..61a02c51f 100644 --- a/moses/src/ScoreComponentCollection.h +++ b/moses/src/ScoreComponentCollection.h @@ -365,7 +365,7 @@ public: void Save(std::ostream&) const; void IncrementSparseFeatures() { m_scores.incrementSparseFeatures(); } - void PrintSparseFeatureCounts() { m_scores.printSparseFeatureCounts(); } + void PrintSparseFeatureCounts(std::ofstream& out) { m_scores.printSparseFeatureCounts(out); } size_t PruneSparseFeatures(size_t threshold) { return m_scores.pruneSparseFeatures(threshold); } size_t PruneZeroWeightFeatures() { return m_scores.pruneZeroWeightFeatures(); }