mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
move backoff parameter into decode graph class
This commit is contained in:
parent
0dac035a12
commit
d3301fa1a3
@ -40,6 +40,7 @@ protected:
|
||||
std::list<const DecodeStep*> m_steps;
|
||||
size_t m_position;
|
||||
size_t m_maxChartSpan;
|
||||
size_t m_backoff;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -47,8 +48,9 @@ public:
|
||||
**/
|
||||
DecodeGraph(size_t position)
|
||||
: m_position(position)
|
||||
, m_maxChartSpan(NOT_FOUND) {
|
||||
}
|
||||
, m_maxChartSpan(NOT_FOUND)
|
||||
, m_backoff(0)
|
||||
{}
|
||||
|
||||
// for chart decoding
|
||||
DecodeGraph(size_t position, size_t maxChartSpan)
|
||||
@ -82,6 +84,14 @@ public:
|
||||
return m_maxChartSpan;
|
||||
}
|
||||
|
||||
size_t GetBackoff() const {
|
||||
return m_backoff;
|
||||
}
|
||||
|
||||
void SetBackoff(size_t backoff){
|
||||
m_backoff = backoff;
|
||||
}
|
||||
|
||||
size_t GetPosition() const {
|
||||
return m_position;
|
||||
}
|
||||
|
@ -744,13 +744,14 @@ bool StaticData::LoadDecodeGraphs()
|
||||
|
||||
// set maximum n-gram size for backoff approach to decoding paths
|
||||
// default is always use subsequent paths (value = 0)
|
||||
for(size_t i=0; i<m_decodeGraphs.size(); i++) {
|
||||
m_decodeGraphBackoff.push_back( 0 );
|
||||
}
|
||||
// if specified, record maxmimum unseen n-gram size
|
||||
const vector<string> &backoffVector = m_parameter->GetParam("decoding-graph-backoff");
|
||||
for(size_t i=0; i<m_decodeGraphs.size() && i<backoffVector.size(); i++) {
|
||||
m_decodeGraphBackoff[i] = Scan<size_t>(backoffVector[i]);
|
||||
DecodeGraph &decodeGraph = *m_decodeGraphs[i];
|
||||
|
||||
if (i < backoffVector.size()) {
|
||||
decodeGraph.SetBackoff(Scan<size_t>(backoffVector[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -70,7 +70,7 @@ protected:
|
||||
mutable ScoreComponentCollection m_allWeights;
|
||||
|
||||
std::vector<DecodeGraph*> m_decodeGraphs;
|
||||
std::vector<size_t> m_decodeGraphBackoff;
|
||||
|
||||
// Initial = 0 = can be used when creating poss trans
|
||||
// Other = 1 = used to calculate LM score once all steps have been processed
|
||||
float
|
||||
@ -720,9 +720,6 @@ public:
|
||||
const std::vector<DecodeGraph*>& GetDecodeGraphs() const {
|
||||
return m_decodeGraphs;
|
||||
}
|
||||
const std::vector<size_t>& GetDecodeGraphBackoff() const {
|
||||
return m_decodeGraphBackoff;
|
||||
}
|
||||
|
||||
//sentence (and thread) specific initialisationn and cleanup
|
||||
void InitializeForInput(const InputType& source) const;
|
||||
|
@ -371,7 +371,6 @@ void TranslationOptionCollection::CreateTranslationOptions()
|
||||
|
||||
// there may be multiple decoding graphs (factorizations of decoding)
|
||||
const vector <DecodeGraph*> &decodeGraphList = StaticData::Instance().GetDecodeGraphs();
|
||||
const vector <size_t> &decodeGraphBackoff = StaticData::Instance().GetDecodeGraphBackoff();
|
||||
|
||||
// length of the sentence
|
||||
const size_t size = m_source.GetSize();
|
||||
@ -383,6 +382,7 @@ void TranslationOptionCollection::CreateTranslationOptions()
|
||||
}
|
||||
|
||||
const DecodeGraph &decodeGraph = *decodeGraphList[graphInd];
|
||||
size_t backoff = decodeGraph.GetBackoff();
|
||||
// generate phrases that start at startPos ...
|
||||
for (size_t startPos = 0 ; startPos < size; startPos++) {
|
||||
size_t maxSize = size - startPos; // don't go over end of sentence
|
||||
@ -392,8 +392,8 @@ void TranslationOptionCollection::CreateTranslationOptions()
|
||||
// ... and that end at endPos
|
||||
for (size_t endPos = startPos ; endPos < startPos + maxSize ; endPos++) {
|
||||
if (graphInd > 0 && // only skip subsequent graphs
|
||||
decodeGraphBackoff[graphInd] != 0 && // use of backoff specified
|
||||
(endPos-startPos+1 >= decodeGraphBackoff[graphInd] || // size exceeds backoff limit or ...
|
||||
backoff != 0 && // use of backoff specified
|
||||
(endPos-startPos+1 >= backoff || // size exceeds backoff limit or ...
|
||||
m_collection[startPos][endPos-startPos].size() > 0)) { // no phrases found so far
|
||||
VERBOSE(3,"No backoff to graph " << graphInd << " for span [" << startPos << ";" << endPos << "]" << endl);
|
||||
// do not create more options
|
||||
|
Loading…
Reference in New Issue
Block a user