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:
authorhieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230>2006-08-02 20:12:41 +0400
committerhieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230>2006-08-02 20:12:41 +0400
commitf0f45f64f179e3b4769ca594052a671ea4b34ed7 (patch)
tree29b825d4d26b0201ed35c118620d6c1ce2c448cd
parent763bb726426ed84417437cf4559cd7e4315aaf01 (diff)
multiple LM per factor
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@461 1f5c12ca-751b-0410-a591-d2e778427230
-rwxr-xr-xmoses/src/LanguageModel_SRI.cpp30
-rwxr-xr-xmoses/src/LanguageModel_SRI.h12
2 files changed, 22 insertions, 20 deletions
diff --git a/moses/src/LanguageModel_SRI.cpp b/moses/src/LanguageModel_SRI.cpp
index 06fb85339..951a87065 100755
--- a/moses/src/LanguageModel_SRI.cpp
+++ b/moses/src/LanguageModel_SRI.cpp
@@ -79,25 +79,29 @@ void LanguageModel_SRI::CreateFactors(FactorCollection &factorCollection)
{ // add factors which have srilm id
VocabString str;
- LmId lmId;
VocabIter iter(*m_srilmVocab);
while ( (str = iter.next()) != NULL)
{
- LmId lmId = GetLmID(str);
- factorCollection.AddFactor(Output, m_factorType, str, lmId);
+ VocabIndex lmId = GetLmID(str);
+ const Factor *factor = factorCollection.AddFactor(Output, m_factorType, str);
+ m_lmIdLookup[factor] = lmId;
}
+ LmId lmId;
lmId = GetLmID(SENTENCE_START);
m_sentenceStart = factorCollection.AddFactor(Output, m_factorType, SENTENCE_START, lmId);
lmId = GetLmID(SENTENCE_END);
m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, SENTENCE_END, lmId);
}
-LmId LanguageModel_SRI::GetLmID( const std::string &str ) const
+VocabIndex LanguageModel_SRI::GetLmID( const std::string &str ) const
+{
+ return m_srilmVocab->getIndex( str.c_str(), m_unknownId.sri );
+}
+VocabIndex LanguageModel_SRI::GetLmID( const Factor *factor ) const
{
- LmId res;
- res.sri = m_srilmVocab->getIndex( str.c_str(), m_unknownId.sri );
- return res;
+ std::map<const Factor*, VocabIndex>::const_iterator iter = m_lmIdLookup.find(factor);
+ return (iter == m_lmIdLookup.end()) ? m_unknownId.sri : iter->second;
}
float LanguageModel_SRI::GetValue(VocabIndex wordId, VocabIndex *context) const
@@ -113,20 +117,20 @@ float LanguageModel_SRI::GetValue(const vector<const Factor*> &contextFactor, St
size_t count = contextFactor.size();
for (size_t i = 0 ; i < count - 1 ; i++)
{
- LmId x = contextFactor[count-2-i]->GetLmId();
- context[i] = x.sri==UNKNOWN_LM_ID.sri ? m_unknownId.sri : x.sri;
+ VocabIndex lmId = GetLmID(contextFactor[count-2-i]);
+ context[i] = (lmId == UNKNOWN_LM_ID.sri) ? m_unknownId.sri : lmId;
}
context[count-1] = Vocab_None;
// call sri lm fn
- LmId x = contextFactor[count-1]->GetLmId();
- x.sri = x.sri==UNKNOWN_LM_ID.sri ? m_unknownId.sri : x.sri;
- float ret = GetValue(x.sri, context);
+ VocabIndex lmId = GetLmID(contextFactor[count-1]);
+ lmId= (lmId == UNKNOWN_LM_ID.sri) ? m_unknownId.sri : lmId;
+ float ret = GetValue(lmId, context);
if (finalState) {
for (int i = count - 2 ; i >= 0 ; i--)
context[i+1] = context[i];
- context[0] = x.sri;
+ context[0] = lmId;
unsigned int len;
*finalState = m_srilmModel->contextID(context,len);
}
diff --git a/moses/src/LanguageModel_SRI.h b/moses/src/LanguageModel_SRI.h
index d546cb104..f47c4db3c 100755
--- a/moses/src/LanguageModel_SRI.h
+++ b/moses/src/LanguageModel_SRI.h
@@ -25,27 +25,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <vector>
#include "Factor.h"
#include "TypeDef.h"
-
+#include "Vocab.h"
#include "LanguageModel.h"
class FactorCollection;
class Factor;
class Phrase;
-
-#include "Vocab.h"
-class Vocab; // SRI forward decl
class Ngram; // SRI forward decl
class LanguageModel_SRI : public LanguageModel
{
protected:
+ std::map<const Factor*, VocabIndex> m_lmIdLookup;
Vocab *m_srilmVocab;
Ngram *m_srilmModel;
float GetValue(VocabIndex wordId, VocabIndex *context) const;
-
void CreateFactors(FactorCollection &factorCollection);
+ VocabIndex GetLmID( const std::string &str ) const;
+ VocabIndex GetLmID( const Factor *factor ) const;
+
public:
LanguageModel_SRI();
~LanguageModel_SRI();
@@ -55,8 +55,6 @@ public:
, float weight
, size_t nGramOrder);
- LmId GetLmID( const std::string &str ) const;
-
virtual float GetValue(const std::vector<const Factor*> &contextFactor, State* finalState = 0) const;
};