Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2013-09-08 17:57:31 +0400
committerHieu Hoang <hieuhoang@gmail.com>2013-09-08 17:57:31 +0400
commit1adf7d05214526e98e8c6c31b090fbd3b485e4d4 (patch)
treeb04f4a3ce9d8a8e5a3a8e039cc8bd24dcfb39297
parent65e2806b1d5f39ee800606ca89f37ce2778533d4 (diff)
lattice decoding with sparse features
-rw-r--r--moses/FF/InputFeature.cpp2
-rw-r--r--moses/InputPath.cpp2
-rw-r--r--moses/InputPath.h9
-rw-r--r--moses/ScoreComponentCollection.cpp12
-rw-r--r--moses/ScoreComponentCollection.h20
-rw-r--r--moses/TranslationOptionCollection.cpp7
-rw-r--r--moses/TranslationOptionCollectionConfusionNet.cpp10
7 files changed, 49 insertions, 13 deletions
diff --git a/moses/FF/InputFeature.cpp b/moses/FF/InputFeature.cpp
index 114bd0dc6..efc668f90 100644
--- a/moses/FF/InputFeature.cpp
+++ b/moses/FF/InputFeature.cpp
@@ -47,7 +47,7 @@ void InputFeature::Evaluate(const InputType &input
return;
}
- const ScoreComponentCollection *scores = inputPath.GetInputScore();
+ const ScorePair *scores = inputPath.GetInputScore();
if (scores) {
}
diff --git a/moses/InputPath.cpp b/moses/InputPath.cpp
index fad2b3fc0..6340e11d7 100644
--- a/moses/InputPath.cpp
+++ b/moses/InputPath.cpp
@@ -11,7 +11,7 @@ using namespace std;
namespace Moses
{
InputPath::InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode
- ,const ScoreComponentCollection *inputScore)
+ ,const ScorePair *inputScore)
:m_prevNode(prevNode)
,m_phrase(phrase)
,m_sourceNonTerms(sourceNonTerms)
diff --git a/moses/InputPath.h b/moses/InputPath.h
index c6d022c9e..d152b496b 100644
--- a/moses/InputPath.h
+++ b/moses/InputPath.h
@@ -13,9 +13,10 @@ namespace Moses
class PhraseDictionary;
class TargetPhraseCollection;
class ScoreComponentCollection;
+class ScorePair;
class TargetPhrase;
-
class InputPath;
+
typedef std::list<InputPath*> InputPathList;
/** Each node contains
@@ -32,7 +33,7 @@ protected:
const InputPath *m_prevNode;
Phrase m_phrase;
WordsRange m_range;
- const ScoreComponentCollection *m_inputScore;
+ const ScorePair *m_inputScore;
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> > m_targetPhrases;
const NonTerminalSet m_sourceNonTerms;
@@ -47,7 +48,7 @@ public:
}
InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, const WordsRange &range, const InputPath *prevNode
- ,const ScoreComponentCollection *inputScore);
+ ,const ScorePair *inputScore);
~InputPath();
const Phrase &GetPhrase() const {
@@ -72,7 +73,7 @@ public:
// pointer to internal node in phrase-table. Since this is implementation dependent, this is a void*
const void *GetPtNode(const PhraseDictionary &phraseDictionary) const;
- const ScoreComponentCollection *GetInputScore() const {
+ const ScorePair *GetInputScore() const {
return m_inputScore;
}
diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp
index 97ae2684d..c9b4d1ea0 100644
--- a/moses/ScoreComponentCollection.cpp
+++ b/moses/ScoreComponentCollection.cpp
@@ -220,6 +220,18 @@ FVector ScoreComponentCollection::GetVectorForProducer(const FeatureFunction* sp
return fv;
}
+void ScoreComponentCollection::PlusEquals(const FeatureFunction* sp, const ScorePair &scorePair)
+{
+ PlusEquals(sp, scorePair.denseScores);
+
+ std::map<std::string, float>::const_iterator iter;
+ for (iter = scorePair.sparseScores.begin(); iter != scorePair.sparseScores.end(); ++iter) {
+ const string &key = iter->first;
+ float value = iter->second;
+ PlusEquals(sp, key, value);
+ }
+}
+
}
diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h
index 9f3ea49f4..c683dd822 100644
--- a/moses/ScoreComponentCollection.h
+++ b/moses/ScoreComponentCollection.h
@@ -41,6 +41,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
namespace Moses
{
+/**
+ * Smaller version for just 1 FF.
+ */
+struct ScorePair
+{
+ std::vector<float> denseScores;
+ std::map<std::string, float> sparseScores;
+
+ void PlusEquals(const std::vector<float> &other)
+ {
+ CHECK(denseScores.size() == other.size());
+ std::transform(denseScores.begin(),
+ denseScores.end(),
+ other.begin(),
+ denseScores.begin(),
+ std::plus<float>());
+ }
+};
/*** An unweighted collection of scores for a translation or step in a translation.
*
@@ -227,6 +245,8 @@ public:
m_scores[fname] += score;
}
+ void PlusEquals(const FeatureFunction* sp, const ScorePair &scorePair);
+
//For features which have an unbounded number of components
void SparsePlusEquals(const std::string& full_name, float score) {
FName fname(full_name);
diff --git a/moses/TranslationOptionCollection.cpp b/moses/TranslationOptionCollection.cpp
index d89eb0e8d..cea330678 100644
--- a/moses/TranslationOptionCollection.cpp
+++ b/moses/TranslationOptionCollection.cpp
@@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "InputPath.h"
#include "moses/FF/UnknownWordPenaltyProducer.h"
#include "moses/FF/LexicalReordering/LexicalReordering.h"
+#include "moses/FF/InputFeature.h"
using namespace std;
@@ -514,17 +515,19 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
void TranslationOptionCollection::SetInputScore(const InputPath &inputPath, PartialTranslOptColl &oldPtoc)
{
- const ScoreComponentCollection *inputScore = inputPath.GetInputScore();
+ const ScorePair *inputScore = inputPath.GetInputScore();
if (inputScore == NULL) {
return;
}
+ const InputFeature *inputFeature = StaticData::Instance().GetInputFeature();
+
const std::vector<TranslationOption*> &transOpts = oldPtoc.GetList();
for (size_t i = 0; i < transOpts.size(); ++i) {
TranslationOption &transOpt = *transOpts[i];
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
- scores.PlusEquals(*inputScore);
+ scores.PlusEquals(inputFeature, *inputScore);
}
}
diff --git a/moses/TranslationOptionCollectionConfusionNet.cpp b/moses/TranslationOptionCollectionConfusionNet.cpp
index e398af6ae..3780a1aeb 100644
--- a/moses/TranslationOptionCollectionConfusionNet.cpp
+++ b/moses/TranslationOptionCollectionConfusionNet.cpp
@@ -43,8 +43,8 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet
subphrase.AddWord(word);
const std::vector<float> &scores = col[i].second;
- ScoreComponentCollection *inputScore = new ScoreComponentCollection();
- inputScore->Assign(inputFeature, scores);
+ ScorePair *inputScore = new ScorePair();
+ inputScore->denseScores = scores;
InputPath *node = new InputPath(subphrase, labels, range, NULL, inputScore);
list.push_back(node);
@@ -76,7 +76,7 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet
//const InputPath &prevNode = *prevNodes[pathInd];
const Phrase &prevPhrase = prevNode.GetPhrase();
- const ScoreComponentCollection *prevInputScore = prevNode.GetInputScore();
+ const ScorePair *prevInputScore = prevNode.GetInputScore();
CHECK(prevInputScore);
// loop thru every word at this position
@@ -88,8 +88,8 @@ TranslationOptionCollectionConfusionNet::TranslationOptionCollectionConfusionNet
subphrase.AddWord(word);
const std::vector<float> &scores = col[i].second;
- ScoreComponentCollection *inputScore = new ScoreComponentCollection(*prevInputScore);
- inputScore->PlusEquals(inputFeature, scores);
+ ScorePair *inputScore = new ScorePair(*prevInputScore);
+ inputScore->PlusEquals(scores);
InputPath *node = new InputPath(subphrase, labels, range, &prevNode, inputScore);
list.push_back(node);