mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 22:14:57 +03:00
add DALM. Just a skeleton so far
This commit is contained in:
parent
7e78dc5a63
commit
08d888382d
@ -48,6 +48,7 @@
|
||||
<listOptionValue builtIn="false" value="KENLM_MAX_ORDER=7"/>
|
||||
<listOptionValue builtIn="false" value="TRACE_ENABLE"/>
|
||||
<listOptionValue builtIn="false" value="LM_IRST"/>
|
||||
<listOptionValue builtIn="false" value="LM_DALM"/>
|
||||
<listOptionValue builtIn="false" value="LM_RAND"/>
|
||||
<listOptionValue builtIn="false" value="LM_NPLM"/>
|
||||
<listOptionValue builtIn="false" value="_FILE_OFFSET_BIT=64"/>
|
||||
|
@ -1371,6 +1371,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/ChartState.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>LM/DALM.cpp</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/DALM.cpp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>LM/DALM.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/LM/DALM.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>LM/IRST.cpp</name>
|
||||
<type>1</type>
|
||||
|
@ -65,6 +65,10 @@
|
||||
#include "moses/LM/NeuralLMWrapper.h"
|
||||
#endif
|
||||
|
||||
#ifdef LM_DALM
|
||||
#include "moses/LM/DALM.h"
|
||||
#endif
|
||||
|
||||
#include "util/exception.hh"
|
||||
|
||||
#include <vector>
|
||||
@ -183,6 +187,9 @@ FeatureRegistry::FeatureRegistry()
|
||||
#ifdef LM_NEURAL
|
||||
MOSES_FNAME2("NeuralLM", NeuralLMWrapper);
|
||||
#endif
|
||||
#ifdef LM_DALM
|
||||
MOSES_FNAME2("DALM", LanguageModelDALM);
|
||||
#endif
|
||||
|
||||
Add("KENLM", new KenFactory());
|
||||
}
|
||||
|
55
moses/LM/DALM.cpp
Normal file
55
moses/LM/DALM.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
#include "DALM.h"
|
||||
#include "moses/FactorCollection.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
LanguageModelDALM::LanguageModelDALM(const std::string &line)
|
||||
:LanguageModelSingleFactor(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;
|
||||
}
|
||||
|
||||
LanguageModelDALM::~LanguageModelDALM()
|
||||
{
|
||||
}
|
||||
|
||||
LMResult LanguageModelDALM::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/DALM.h
Normal file
22
moses/LM/DALM.h
Normal file
@ -0,0 +1,22 @@
|
||||
// $Id$
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "SingleFactor.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
class LanguageModelDALM : public LanguageModelSingleFactor
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
LanguageModelDALM(const std::string &line);
|
||||
~LanguageModelDALM();
|
||||
|
||||
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const;
|
||||
};
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user