diff --git a/contrib/other-builds/moses/.cproject b/contrib/other-builds/moses/.cproject index 3b1b96426..66e518dcc 100644 --- a/contrib/other-builds/moses/.cproject +++ b/contrib/other-builds/moses/.cproject @@ -50,7 +50,7 @@ - + diff --git a/contrib/other-builds/moses/.project b/contrib/other-builds/moses/.project index 5b72b7fca..70fe2c0be 100644 --- a/contrib/other-builds/moses/.project +++ b/contrib/other-builds/moses/.project @@ -1427,14 +1427,14 @@ PARENT-3-PROJECT_LOC/moses/LM/MultiFactor.h - LM/NeuralLM.cpp + LM/NeuralLMWrapper.cpp 1 - PARENT-3-PROJECT_LOC/moses/LM/NeuralLM.cpp + PARENT-3-PROJECT_LOC/moses/LM/NeuralLMWrapper.cpp - LM/NeuralLM.h + LM/NeuralLMWrapper.h 1 - PARENT-3-PROJECT_LOC/moses/LM/NeuralLM.h + PARENT-3-PROJECT_LOC/moses/LM/NeuralLMWrapper.h LM/ORLM.cpp diff --git a/moses/FF/Factory.cpp b/moses/FF/Factory.cpp index 2a869f5a8..9a9bcdb82 100644 --- a/moses/FF/Factory.cpp +++ b/moses/FF/Factory.cpp @@ -59,8 +59,8 @@ #include "moses/SyntacticLanguageModel.h" #endif -#ifdef HAVE_NPLM -#include "moses/LM/NeuralLM.h" +#ifdef LM_NEURAL +#include "moses/LM/NeuralLMWrapper.h" #endif #include "util/exception.hh" @@ -176,8 +176,8 @@ FeatureRegistry::FeatureRegistry() #ifdef LM_RAND MOSES_FNAME2("RANDLM", LanguageModelRandLM); #endif -#ifdef HAVE_NPLM - MOSES_FNAME(NeuralLM); +#ifdef LM_NEURAL + MOSES_FNAME2("NeuralLM", NeuralLMWrapper); #endif Add("KENLM", new KenFactory()); diff --git a/moses/LM/Jamfile b/moses/LM/Jamfile index a7cb55a14..d6841121d 100644 --- a/moses/LM/Jamfile +++ b/moses/LM/Jamfile @@ -70,6 +70,16 @@ if $(with-ldhtlm) { lmmacros += LM_LDHT ; } +#NPLM +local with-nplm = [ option.get "with-nplm" ] ; +if $(with-nplm) { + lib neuralLM : : $(with-nplm)/lib $(with-nplm)/lib64 ; + obj NeuralLMWrapper.o : NeuralLMWrapper.cpp neuralLM ..//headers : $(with-nplm)/src $(with-nplm)/3rdparty/eigen ; + alias nplm : NeuralLMWrapper.o neuralLM : : : LM_NEURAL ; + dependencies += nplm ; + lmmacros += LM_NEURAL ; +} + #ORLM is always compiled but needs special headers obj ORLM.o : ORLM.cpp ..//headers ../TranslationModel/DynSAInclude//dynsa : : : ../TranslationModel/DynSAInclude ; diff --git a/moses/LM/NeuralLM.cpp b/moses/LM/NeuralLMWrapper.cpp similarity index 85% rename from moses/LM/NeuralLM.cpp rename to moses/LM/NeuralLMWrapper.cpp index 4c0861cbc..99e1a7e2c 100644 --- a/moses/LM/NeuralLM.cpp +++ b/moses/LM/NeuralLMWrapper.cpp @@ -1,28 +1,28 @@ #include "moses/StaticData.h" #include "moses/FactorCollection.h" -#include "NeuralLM.h" +#include "NeuralLMWrapper.h" #include "neuralLM.h" -#include "model.h" +#include using namespace std; namespace Moses { -NeuralLM::NeuralLM(const std::string &line) +NeuralLMWrapper::NeuralLMWrapper(const std::string &line) :LanguageModelSingleFactor("NeuralLM", line) { // This space intentionally left blank } -NeuralLM::~NeuralLM() +NeuralLMWrapper::~NeuralLMWrapper() { delete m_neuralLM; } -bool NeuralLM::Load(const std::string &filePath, FactorType factorType, size_t nGramOrder) +bool NeuralLMWrapper::Load(const std::string &filePath, FactorType factorType, size_t nGramOrder) { TRACE_ERR("Loading NeuralLM " << filePath << endl); @@ -42,7 +42,7 @@ bool NeuralLM::Load(const std::string &filePath, FactorType factorType, size_t n m_sentenceEnd = factorCollection.AddFactor(Output, m_factorType, EOS_); m_sentenceEndWord[m_factorType] = m_sentenceEnd; - m_neuralLM = new nplm::neuralLM(24234); + m_neuralLM = new nplm::neuralLM(); m_neuralLM->read(m_filePath); m_neuralLM->set_log_base(10); @@ -51,7 +51,7 @@ bool NeuralLM::Load(const std::string &filePath, FactorType factorType, size_t n } -LMResult NeuralLM::GetValue(const vector &contextFactor, State* finalState) const +LMResult NeuralLMWrapper::GetValue(const vector &contextFactor, State* finalState) const { unsigned int hashCode = 0; diff --git a/moses/LM/NeuralLM.h b/moses/LM/NeuralLMWrapper.h similarity index 79% rename from moses/LM/NeuralLM.h rename to moses/LM/NeuralLMWrapper.h index 02d6ebd54..0c70725b5 100644 --- a/moses/LM/NeuralLM.h +++ b/moses/LM/NeuralLMWrapper.h @@ -11,15 +11,15 @@ namespace Moses /** Implementation of single factor LM using IRST's code. */ -class NeuralLM : public LanguageModelSingleFactor +class NeuralLMWrapper : public LanguageModelSingleFactor { protected: nplm::neuralLM *m_neuralLM; public: - NeuralLM(const std::string &line); + NeuralLMWrapper(const std::string &line); // NeuralLM(const std::string &line); - ~NeuralLM(); + ~NeuralLMWrapper(); virtual LMResult GetValue(const std::vector &contextFactor, State* finalState = 0) const;