mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
skeleton LM
This commit is contained in:
parent
e07b3afa12
commit
cff36b6638
@ -35,6 +35,7 @@
|
||||
|
||||
#include "moses/FF/SkeletonStatelessFF.h"
|
||||
#include "moses/FF/SkeletonStatefulFF.h"
|
||||
#include "moses/LM/SkeletonLM.h"
|
||||
|
||||
#include "moses/LM/Ken.h"
|
||||
#ifdef LM_IRST
|
||||
@ -148,6 +149,7 @@ FeatureRegistry::FeatureRegistry()
|
||||
|
||||
MOSES_FNAME(SkeletonStatelessFF);
|
||||
MOSES_FNAME(SkeletonStatefulFF);
|
||||
MOSES_FNAME(SkeletonLM);
|
||||
|
||||
#ifdef HAVE_SYNLM
|
||||
MOSES_FNAME(SyntacticLanguageModel);
|
||||
|
@ -75,7 +75,7 @@ obj ORLM.o : ORLM.cpp ..//headers ../TranslationModel/DynSAInclude//dynsa : : :
|
||||
|
||||
#Top-level LM library. If you've added a file that doesn't depend on external
|
||||
#libraries, put it here.
|
||||
alias LM : Backward.cpp BackwardLMState.cpp Base.cpp Implementation.cpp Joint.cpp Ken.cpp MultiFactor.cpp Remote.cpp SingleFactor.cpp ORLM.o
|
||||
alias LM : Backward.cpp BackwardLMState.cpp Base.cpp Implementation.cpp Joint.cpp Ken.cpp MultiFactor.cpp Remote.cpp SingleFactor.cpp SkeletonLM.cpp ORLM.o
|
||||
../../lm//kenlm ..//headers $(dependencies) ;
|
||||
|
||||
alias macros : : : : <define>$(lmmacros) ;
|
||||
|
56
moses/LM/SkeletonLM.cpp
Normal file
56
moses/LM/SkeletonLM.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
#include "SkeletonLM.h"
|
||||
#include "moses/FactorCollection.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
SkeletonLM::SkeletonLM(const std::string &line)
|
||||
:LanguageModelSingleFactor("SkeletonLM", line)
|
||||
{
|
||||
ReadParameters();
|
||||
|
||||
if (m_factorType == NOT_FOUND) {
|
||||
m_factorType = 0;
|
||||
}
|
||||
|
||||
FactorCollection &factorCollection = FactorCollection::Instance();
|
||||
|
||||
// needed by parent language model classes. Why didn't they set these themselves?
|
||||
m_sentenceStart = factorCollection.AddFactor(Output, m_factorType, BOS_);
|
||||
m_sentenceStartWord[m_factorType] = m_sentenceStart;
|
||||
|
||||
m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, EOS_);
|
||||
m_sentenceEndWord[m_factorType] = m_sentenceEnd;
|
||||
}
|
||||
|
||||
SkeletonLM::~SkeletonLM()
|
||||
{
|
||||
}
|
||||
|
||||
LMResult SkeletonLM::GetValue(const vector<const Word*> &contextFactor, State* finalState) const
|
||||
{
|
||||
LMResult ret;
|
||||
ret.score = contextFactor.size();
|
||||
ret.unknown = false;
|
||||
|
||||
// use last word as state info
|
||||
const Factor *factor;
|
||||
size_t hash_value(const Factor &f);
|
||||
if (contextFactor.size()) {
|
||||
factor = contextFactor.back()->GetFactor(m_factorType);
|
||||
}
|
||||
else {
|
||||
factor = NULL;
|
||||
}
|
||||
|
||||
(*finalState) = (State*) factor;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
22
moses/LM/SkeletonLM.h
Normal file
22
moses/LM/SkeletonLM.h
Normal file
@ -0,0 +1,22 @@
|
||||
// $Id$
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "SingleFactor.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
class SkeletonLM : public LanguageModelSingleFactor
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
SkeletonLM(const std::string &line);
|
||||
~SkeletonLM();
|
||||
|
||||
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const;
|
||||
};
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user