diff --git a/moses/src/LanguageModel.cpp b/moses/src/LanguageModel.cpp index 0e6ed011..f1226b51 100644 --- a/moses/src/LanguageModel.cpp +++ b/moses/src/LanguageModel.cpp @@ -222,9 +222,8 @@ FFState* LanguageModel::Evaluate( contextFactor[index++] = &m_implementation->GetSentenceStartArray(); } } - unsigned int statelen; FFState *res = m_implementation->NewState(ps); - float lmScore = ps ? m_implementation->GetValueGivenState(contextFactor, *res, &statelen) : m_implementation->GetValueForgotState(contextFactor, *res, &statelen); + float lmScore = ps ? m_implementation->GetValueGivenState(contextFactor, *res) : m_implementation->GetValueForgotState(contextFactor, *res); // main loop size_t endPos = std::min(startPos + GetNGramOrder() - 2 @@ -238,7 +237,7 @@ FFState* LanguageModel::Evaluate( // add last factor contextFactor.back() = &hypo.GetWord(currPos); - lmScore += m_implementation->GetValueGivenState(contextFactor, *res, &statelen); + lmScore += m_implementation->GetValueGivenState(contextFactor, *res); } // end of sentence diff --git a/moses/src/LanguageModelIRST.cpp b/moses/src/LanguageModelIRST.cpp index d65d5d98..ec1042d4 100644 --- a/moses/src/LanguageModelIRST.cpp +++ b/moses/src/LanguageModelIRST.cpp @@ -184,10 +184,8 @@ int LanguageModelIRST::GetLmID( const Factor *factor ) const return ( factorId >= m_lmIdLookup.size()) ? m_unknownId : m_lmIdLookup[factorId]; } -float LanguageModelIRST::GetValue(const vector &contextFactor, State* finalState, unsigned int* len) const +float LanguageModelIRST::GetValue(const vector &contextFactor, State* finalState) const { - unsigned int dummy; - if (!len) { len = &dummy; } FactorType factorType = GetFactorType(); // set up context @@ -212,7 +210,6 @@ float LanguageModelIRST::GetValue(const vector &contextFactor, Stat prob = m_lmtb->clprob(codes,idx,NULL,NULL,&msp,&ilen); if (finalState) *finalState=(State *) msp; - if (len) *len = ilen; return TransformLMScore(prob); } diff --git a/moses/src/LanguageModelIRST.h b/moses/src/LanguageModelIRST.h index 0ddbae3e..010c5688 100644 --- a/moses/src/LanguageModelIRST.h +++ b/moses/src/LanguageModelIRST.h @@ -68,7 +68,7 @@ class LanguageModelIRST : public LanguageModelPointerState , FactorType factorType , size_t nGramOrder); - virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL, unsigned int* len=0) const; + virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL) const; void CleanUpAfterSentenceProcessing(); void InitializeBeforeSentenceProcessing(); diff --git a/moses/src/LanguageModelImplementation.cpp b/moses/src/LanguageModelImplementation.cpp index c3fd85ee..442fd7aa 100644 --- a/moses/src/LanguageModelImplementation.cpp +++ b/moses/src/LanguageModelImplementation.cpp @@ -40,17 +40,16 @@ namespace Moses { float LanguageModelImplementation::GetValueGivenState( const std::vector &contextFactor, - FFState &state, - unsigned int* len) const + FFState &state) const { - return GetValueForgotState(contextFactor, state, len); + return GetValueForgotState(contextFactor, state); } void LanguageModelImplementation::GetState( const std::vector &contextFactor, FFState &state) const { - GetValueForgotState(contextFactor, state, NULL); + GetValueForgotState(contextFactor, state); } } diff --git a/moses/src/LanguageModelImplementation.h b/moses/src/LanguageModelImplementation.h index 902133b0..aaf02f8b 100644 --- a/moses/src/LanguageModelImplementation.h +++ b/moses/src/LanguageModelImplementation.h @@ -74,22 +74,16 @@ class LanguageModelImplementation * Specific implementation can return State and len data to be used in hypothesis pruning * \param contextFactor n-gram to be scored * \param state LM state. Input and output. state must be initialized. If state isn't initialized, you want GetValueWithoutState. - * \param len If non-null, the n-gram length is written here. */ - virtual float GetValueGivenState(const std::vector &contextFactor, FFState &state, unsigned int* len = 0) const; + virtual float GetValueGivenState(const std::vector &contextFactor, FFState &state) const; // Like GetValueGivenState but state may not be initialized (however it is non-NULL). // For example, state just came from NewState(NULL). - virtual float GetValueForgotState( - const std::vector &contextFactor, - FFState &outState, - unsigned int* len = 0) const = 0; + virtual float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const = 0; //! get State for a particular n-gram. We don't care what the score is. // This is here so models can implement a shortcut to GetValueAndState. - virtual void GetState( - const std::vector &contextFactor, - FFState &outState) const; + virtual void GetState(const std::vector &contextFactor, FFState &outState) const; virtual FFState *GetNullContextState() const = 0; virtual FFState *GetBeginSentenceState() const = 0; diff --git a/moses/src/LanguageModelInternal.cpp b/moses/src/LanguageModelInternal.cpp index 0599dc35..12e02711 100644 --- a/moses/src/LanguageModelInternal.cpp +++ b/moses/src/LanguageModelInternal.cpp @@ -111,8 +111,7 @@ bool LanguageModelInternal::Load(const std::string &filePath } float LanguageModelInternal::GetValue(const std::vector &contextFactor - , State* finalState - , unsigned int* /*len*/) const + , State* finalState) const { const size_t ngram = contextFactor.size(); switch (ngram) diff --git a/moses/src/LanguageModelInternal.h b/moses/src/LanguageModelInternal.h index 93161dfd..4ad5c9a6 100644 --- a/moses/src/LanguageModelInternal.h +++ b/moses/src/LanguageModelInternal.h @@ -30,8 +30,7 @@ class LanguageModelInternal : public LanguageModelPointerState , FactorType factorType , size_t nGramOrder); float GetValue(const std::vector &contextFactor - , State* finalState = 0 - , unsigned int* len = 0) const; + , State* finalState = 0) const; }; } diff --git a/moses/src/LanguageModelJoint.h b/moses/src/LanguageModelJoint.h index 2053b778..308d3dd9 100644 --- a/moses/src/LanguageModelJoint.h +++ b/moses/src/LanguageModelJoint.h @@ -82,7 +82,7 @@ class LanguageModelJoint : public LanguageModelMultiFactor return m_lmImpl->Load(filePath, m_implFactor, nGramOrder); } - float GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len = NULL) const + float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const { if (contextFactor.size() == 0) { @@ -117,7 +117,7 @@ class LanguageModelJoint : public LanguageModelMultiFactor } // calc score on chunked phrase - float ret = m_lmImpl->GetValueForgotState(jointContext, outState, len); + float ret = m_lmImpl->GetValueForgotState(jointContext, outState); RemoveAllInColl(jointContext); diff --git a/moses/src/LanguageModelKen.cpp b/moses/src/LanguageModelKen.cpp index 37aa05c6..0361a25c 100644 --- a/moses/src/LanguageModelKen.cpp +++ b/moses/src/LanguageModelKen.cpp @@ -95,8 +95,8 @@ template class LanguageModelKen : public LanguageModelSingleFactor , FactorType factorType , size_t nGramOrder); - float GetValueGivenState(const std::vector &contextFactor, FFState &state, unsigned int* len = 0) const; - float GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len=0) const; + float GetValueGivenState(const std::vector &contextFactor, FFState &state) const; + float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const; void GetState(const std::vector &contextFactor, FFState &outState) const; FFState *GetNullContextState() const; @@ -169,7 +169,7 @@ template bool LanguageModelKen::Load(const std::string &fil return true; } -template float LanguageModelKen::GetValueGivenState(const std::vector &contextFactor, FFState &state, unsigned int* len) const +template float LanguageModelKen::GetValueGivenState(const std::vector &contextFactor, FFState &state) const { if (contextFactor.empty()) { @@ -181,14 +181,10 @@ template float LanguageModelKen::GetValueGivenState(const s lm::ngram::State copied(realState); lm::FullScoreReturn ret(m_ngram->FullScore(copied, new_word, realState)); - if (len) - { - *len = ret.ngram_length; - } return TransformLMScore(ret.prob); } -template float LanguageModelKen::GetValueForgotState(const vector &contextFactor, FFState &outState, unsigned int* len) const +template float LanguageModelKen::GetValueForgotState(const vector &contextFactor, FFState &outState) const { if (contextFactor.empty()) { @@ -200,10 +196,6 @@ template float LanguageModelKen::GetValueForgotState(const TranslateIDs(contextFactor, indices); lm::FullScoreReturn ret(m_ngram->FullScoreForgotState(indices + 1, indices + contextFactor.size(), indices[0], static_cast(outState).state)); - if (len) - { - *len = ret.ngram_length; - } return TransformLMScore(ret.prob); } diff --git a/moses/src/LanguageModelParallelBackoff.cpp b/moses/src/LanguageModelParallelBackoff.cpp index 2a6b357d..f6dab9c8 100644 --- a/moses/src/LanguageModelParallelBackoff.cpp +++ b/moses/src/LanguageModelParallelBackoff.cpp @@ -225,7 +225,7 @@ void LanguageModelParallelBackoff::CreateFactors() } - float LanguageModelParallelBackoff::GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len) const + float LanguageModelParallelBackoff::GetValueForgotState(const std::vector &contextFactor, FFState &outState) const { static WidMatrix widMatrix; diff --git a/moses/src/LanguageModelParallelBackoff.h b/moses/src/LanguageModelParallelBackoff.h index 23179dc7..ea29343f 100644 --- a/moses/src/LanguageModelParallelBackoff.h +++ b/moses/src/LanguageModelParallelBackoff.h @@ -88,7 +88,7 @@ VocabIndex GetLmID( const Factor *factor, FactorType ft ) const; void CreateFactors(); -float GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len = 0) const; +float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const; FFState *GetNullContextState() const; FFState *GetBeginSentenceState() const; FFState *NewState(const FFState *from) const; diff --git a/moses/src/LanguageModelRandLM.cpp b/moses/src/LanguageModelRandLM.cpp index 72b05143..6ffa5eb2 100644 --- a/moses/src/LanguageModelRandLM.cpp +++ b/moses/src/LanguageModelRandLM.cpp @@ -88,9 +88,7 @@ randlm::WordID LanguageModelRandLM::GetLmID( const std::string &str ) const { } float LanguageModelRandLM::GetValue(const vector &contextFactor, - State* finalState, unsigned int* len) const { - unsigned int dummy; // is this needed ? - if (!len) { len = &dummy; } + State* finalState) const { FactorType factorType = GetFactorType(); // set up context randlm::WordID ngram[MAX_NGRAM_SIZE]; @@ -101,9 +99,8 @@ float LanguageModelRandLM::GetValue(const vector &contextFactor, } int found = 0; float logprob = FloorScore(TransformLMScore(m_lm->getProb(&ngram[0], count, &found, finalState))); - *len = 0; // not available //if (finalState) - // std::cerr << " = " << logprob << "(" << *finalState << ", " << *len <<")"<< std::endl; + // std::cerr << " = " << logprob << "(" << *finalState << ", " <<")"<< std::endl; //else // std::cerr << " = " << logprob << std::endl; return logprob; diff --git a/moses/src/LanguageModelRandLM.h b/moses/src/LanguageModelRandLM.h index 0cd2ef45..8f748b5f 100644 --- a/moses/src/LanguageModelRandLM.h +++ b/moses/src/LanguageModelRandLM.h @@ -41,7 +41,7 @@ class LanguageModelRandLM : public LanguageModelPointerState { LanguageModelRandLM() : m_lm(0) {} bool Load(const std::string &filePath, FactorType factorType, size_t nGramOrder); - virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL, unsigned int* len=0) const; + virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL) const; ~LanguageModelRandLM() { delete m_lm; } diff --git a/moses/src/LanguageModelRemote.cpp b/moses/src/LanguageModelRemote.cpp index 5e401d24..9b96f394 100644 --- a/moses/src/LanguageModelRemote.cpp +++ b/moses/src/LanguageModelRemote.cpp @@ -55,7 +55,7 @@ bool LanguageModelRemote::start(const std::string& host, int port) { return true; } -float LanguageModelRemote::GetValue(const std::vector &contextFactor, State* finalState, unsigned int* len) const { +float LanguageModelRemote::GetValue(const std::vector &contextFactor, State* finalState) const { size_t count = contextFactor.size(); if (count == 0) { if (finalState) *finalState = NULL; @@ -76,7 +76,6 @@ float LanguageModelRemote::GetValue(const std::vector &contextFacto cur = &cur->tree[event_word ? event_word : EOS]; if (cur->prob) { if (finalState) *finalState = cur->boState; - if (len) *len = m_nGramOrder; return cur->prob; } cur->boState = *reinterpret_cast(&m_curId); @@ -119,7 +118,6 @@ float LanguageModelRemote::GetValue(const std::vector &contextFacto cur->prob = FloorScore(TransformLMScore(*reinterpret_cast(res))); if (finalState) { *finalState = cur->boState; - if (len) *len = m_nGramOrder; } return cur->prob; } diff --git a/moses/src/LanguageModelRemote.h b/moses/src/LanguageModelRemote.h index 7a2328bc..2f7d7d50 100644 --- a/moses/src/LanguageModelRemote.h +++ b/moses/src/LanguageModelRemote.h @@ -31,7 +31,7 @@ class LanguageModelRemote : public LanguageModelPointerState { public: ~LanguageModelRemote(); void ClearSentenceCache() { m_cache.tree.clear(); m_curId = 1000; } - virtual float GetValue(const std::vector &contextFactor, State* finalState = 0, unsigned int* len = 0) const; + virtual float GetValue(const std::vector &contextFactor, State* finalState = 0) const; bool Load(const std::string &filePath , FactorType factorType , size_t nGramOrder); diff --git a/moses/src/LanguageModelSRI.cpp b/moses/src/LanguageModelSRI.cpp index 71fe45b5..c379afc0 100644 --- a/moses/src/LanguageModelSRI.cpp +++ b/moses/src/LanguageModelSRI.cpp @@ -128,7 +128,7 @@ float LanguageModelSRI::GetValue(VocabIndex wordId, VocabIndex *context) const return FloorScore(TransformLMScore(p)); // log10->log } -float LanguageModelSRI::GetValue(const vector &contextFactor, State* finalState, unsigned int *len) const +float LanguageModelSRI::GetValue(const vector &contextFactor, State* finalState) const { FactorType factorType = GetFactorType(); size_t count = contextFactor.size(); @@ -155,9 +155,7 @@ float LanguageModelSRI::GetValue(const vector &contextFactor, State if (finalState) { ngram[0] = lmId; unsigned int dummy; - if (!len) { len = &dummy; } - *finalState = m_srilmModel->contextID(ngram, *len); - (*len)++; + *finalState = m_srilmModel->contextID(ngram, dummy); } return ret; } diff --git a/moses/src/LanguageModelSRI.h b/moses/src/LanguageModelSRI.h index eb6712c9..341fd881 100644 --- a/moses/src/LanguageModelSRI.h +++ b/moses/src/LanguageModelSRI.h @@ -56,7 +56,7 @@ class LanguageModelSRI : public LanguageModelPointerState , FactorType factorType , size_t nGramOrder); - virtual float GetValue(const std::vector &contextFactor, State* finalState = 0, unsigned int* len = 0) const; + virtual float GetValue(const std::vector &contextFactor, State* finalState = 0) const; }; diff --git a/moses/src/LanguageModelSingleFactor.cpp b/moses/src/LanguageModelSingleFactor.cpp index f574c963..23f19722 100644 --- a/moses/src/LanguageModelSingleFactor.cpp +++ b/moses/src/LanguageModelSingleFactor.cpp @@ -82,9 +82,9 @@ FFState *LanguageModelPointerState::NewState(const FFState *from) const return new PointerState(from ? static_cast(from)->lmstate : NULL); } -float LanguageModelPointerState::GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len) const +float LanguageModelPointerState::GetValueForgotState(const std::vector &contextFactor, FFState &outState) const { - return GetValue(contextFactor, &static_cast(outState).lmstate, len); + return GetValue(contextFactor, &static_cast(outState).lmstate); } } diff --git a/moses/src/LanguageModelSingleFactor.h b/moses/src/LanguageModelSingleFactor.h index 08ba43b0..aefd8dea 100644 --- a/moses/src/LanguageModelSingleFactor.h +++ b/moses/src/LanguageModelSingleFactor.h @@ -86,9 +86,9 @@ class LanguageModelPointerState : public LanguageModelSingleFactor virtual FFState *GetBeginSentenceState() const; virtual FFState *NewState(const FFState *from = NULL) const; - virtual float GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len = 0) const; + virtual float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const; - virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL, unsigned int* len=0) const = 0; + virtual float GetValue(const std::vector &contextFactor, State* finalState = NULL) const = 0; }; diff --git a/moses/src/LanguageModelSkip.h b/moses/src/LanguageModelSkip.h index 10c8d1a5..3dddce35 100644 --- a/moses/src/LanguageModelSkip.h +++ b/moses/src/LanguageModelSkip.h @@ -87,7 +87,7 @@ class LanguageModelSkip : public LanguageModelSingleFactor return m_lmImpl->NewState(from); } - float GetValueForgotState(const std::vector &contextFactor, FFState &outState, unsigned int* len = 0) const + float GetValueForgotState(const std::vector &contextFactor, FFState &outState) const { if (contextFactor.size() == 0) { @@ -126,7 +126,7 @@ class LanguageModelSkip : public LanguageModelSingleFactor std::reverse(chunkContext.begin(), chunkContext.end()); // calc score on chunked phrase - float ret = m_lmImpl->GetValueForgotState(chunkContext, outState, len); + float ret = m_lmImpl->GetValueForgotState(chunkContext, outState); RemoveAllInColl(chunkContext);