diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-10 17:36:21 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-10 17:36:21 +0400 |
commit | f379e5cb8a1d7e04072b4931b4f852b9a8ceb979 (patch) | |
tree | 483cd36ec820b3ce66d2b5f9db1a65c2a6bf9943 | |
parent | 52bb3bdf5aeaadba612a350d525201e55b6bf368 (diff) |
lattice decoding with sparse features
-rw-r--r-- | moses/InputPath.cpp | 2 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.cpp | 31 | ||||
-rw-r--r-- | moses/ScoreComponentCollection.h | 10 |
3 files changed, 35 insertions, 8 deletions
diff --git a/moses/InputPath.cpp b/moses/InputPath.cpp index 6340e11d7..eb27e41f6 100644 --- a/moses/InputPath.cpp +++ b/moses/InputPath.cpp @@ -18,6 +18,8 @@ InputPath::InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, ,m_range(range) ,m_inputScore(inputScore) { + //cerr << "phrase=" << phrase << " m_inputScore=" << *m_inputScore << endl; + FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor().first; if (placeholderFactor != NOT_FOUND) { for (size_t pos = 0; pos < m_phrase.GetSize(); ++pos) { diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index 7cd9be701..0ce50d992 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -1,6 +1,6 @@ // $Id$ #include <vector> - +#include "util/exception.hh" #include "ScoreComponentCollection.h" #include "StaticData.h" @@ -30,6 +30,20 @@ void ScorePair::PlusEquals(const StringPiece &key, float value) } } +std::ostream& operator<<(std::ostream& os, const ScorePair& rhs) +{ + for (size_t i = 0; i < rhs.denseScores.size(); ++i) { + os << rhs.denseScores[i] << ","; + } + + std::map<StringPiece, float>::const_iterator iter; + for (iter = rhs.sparseScores.begin(); iter != rhs.sparseScores.end(); ++iter) { + os << iter->first << "=" << iter->second << ","; + } + + return os; +} + ScoreComponentCollection::ScoreIndexMap ScoreComponentCollection::s_scoreIndexes; size_t ScoreComponentCollection::s_denseVectorSize = 0; @@ -206,6 +220,21 @@ void ScoreComponentCollection::Assign(const FeatureFunction* sp, const string li } } +void ScoreComponentCollection::Assign(const FeatureFunction* sp, const std::vector<float>& scores) { + IndexPair indexes = GetIndexes(sp); + size_t numScores = indexes.second - indexes.first; + + if (scores.size() != numScores) { + UTIL_THROW(util::Exception, "Feature function " << sp->GetScoreProducerDescription() << " specified " + << numScores << " dense scores or weights. Actually has " << scores.size()); + } + + for (size_t i = 0; i < scores.size(); ++i) { + m_scores[i + indexes.first] = scores[i]; + } +} + + void ScoreComponentCollection::InvertDenseFeatures(const FeatureFunction* sp) { diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 5eb353981..6501242ec 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -46,6 +46,8 @@ namespace Moses */ struct ScorePair { + friend std::ostream& operator<<(std::ostream& os, const ScorePair& rhs); + std::vector<float> denseScores; std::map<StringPiece, float> sparseScores; @@ -262,13 +264,7 @@ public: m_scores[fname] += score; } - void Assign(const FeatureFunction* sp, const std::vector<float>& scores) { - IndexPair indexes = GetIndexes(sp); - CHECK(scores.size() == indexes.second - indexes.first); - for (size_t i = 0; i < scores.size(); ++i) { - m_scores[i + indexes.first] = scores[i]; - } - } + void Assign(const FeatureFunction* sp, const std::vector<float>& scores); //! Special version Assign(ScoreProducer, vector<float>) //! to add the score from a single ScoreProducer that produces |