mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-20 07:42:21 +03:00
Call sparse reordering
This commit is contained in:
parent
4aa4fe0a04
commit
3dec0abf0a
@ -134,24 +134,26 @@ void LexicalReorderingState::CopyScores(ScoreComponentCollection* accum, const
|
||||
// don't call this on a bidirectional object
|
||||
UTIL_THROW_IF2(m_direction != LexicalReorderingConfiguration::Backward && m_direction != LexicalReorderingConfiguration::Forward,
|
||||
"Unknown direction: " << m_direction);
|
||||
const Scores *cachedScores = (m_direction == LexicalReorderingConfiguration::Backward) ?
|
||||
topt.GetLexReorderingScores(m_configuration.GetScoreProducer()) :
|
||||
m_prevOption->GetLexReorderingScores(m_configuration.GetScoreProducer());
|
||||
const TranslationOption* relevantOpt = &topt;
|
||||
if (m_direction != LexicalReorderingConfiguration::Backward) relevantOpt = m_prevOption;
|
||||
const Scores *cachedScores = relevantOpt->GetLexReorderingScores(m_configuration.GetScoreProducer());
|
||||
|
||||
// No scores available. TODO: Using a good prior distribution would be nicer.
|
||||
if(cachedScores == NULL)
|
||||
return;
|
||||
if(cachedScores) {
|
||||
Scores scores(m_configuration.GetScoreProducer()->GetNumScoreComponents(),0);
|
||||
|
||||
Scores scores(m_configuration.GetScoreProducer()->GetNumScoreComponents(),0);
|
||||
|
||||
const Scores &scoreSet = *cachedScores;
|
||||
if(m_configuration.CollapseScores())
|
||||
scores[m_offset] = scoreSet[m_offset + reoType];
|
||||
else {
|
||||
std::fill(scores.begin() + m_offset, scores.begin() + m_offset + m_configuration.GetNumberOfTypes(), 0);
|
||||
scores[m_offset + reoType] = scoreSet[m_offset + reoType];
|
||||
const Scores &scoreSet = *cachedScores;
|
||||
if(m_configuration.CollapseScores())
|
||||
scores[m_offset] = scoreSet[m_offset + reoType];
|
||||
else {
|
||||
std::fill(scores.begin() + m_offset, scores.begin() + m_offset + m_configuration.GetNumberOfTypes(), 0);
|
||||
scores[m_offset + reoType] = scoreSet[m_offset + reoType];
|
||||
}
|
||||
accum->PlusEquals(m_configuration.GetScoreProducer(), scores);
|
||||
}
|
||||
accum->PlusEquals(m_configuration.GetScoreProducer(), scores);
|
||||
|
||||
const SparseReordering* sparse = m_configuration.GetSparseReordering();
|
||||
if (sparse) sparse->CopyScores(*relevantOpt, reoType, m_direction, accum);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,6 +67,10 @@ public:
|
||||
return m_collapseScores;
|
||||
}
|
||||
|
||||
const SparseReordering* GetSparseReordering() const {
|
||||
return m_sparse.get();
|
||||
}
|
||||
|
||||
private:
|
||||
void SetScoreProducer(LexicalReordering* scoreProducer) {
|
||||
m_scoreProducer = scoreProducer;
|
||||
|
@ -50,12 +50,13 @@ void SparseReordering::ReadWordList(const string& filename, const string& id, ve
|
||||
}
|
||||
}
|
||||
|
||||
void SparseReordering::AddScores(
|
||||
const TranslationOption& topt,
|
||||
void SparseReordering::CopyScores(
|
||||
const TranslationOption& topt,
|
||||
LexicalReorderingState::ReorderingType reoType,
|
||||
LexicalReorderingConfiguration::Direction direction,
|
||||
ScoreComponentCollection* scores) const
|
||||
{
|
||||
//std::cerr << "SR " << topt << " " << reoType << " " << direction << std::endl;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
@ -20,9 +20,9 @@
|
||||
sparse-words-(source|target)-<id>=<filename> -- Features which fire for the words in the list
|
||||
sparse-clusters-(source|target)-<id>=<filename> -- Features which fire for clusters in the list. Format
|
||||
of cluster file TBD
|
||||
sparse-phrase -- Add features which depend on the current phrase
|
||||
sparse-phrase -- Add features which depend on the current phrase (backward)
|
||||
sparse-stack -- Add features which depend on the previous phrase, or
|
||||
top of stack.
|
||||
top of stack. (forward)
|
||||
sparse-between -- Add features which depend on words between previous phrase
|
||||
(or top of stack) and current phrase.
|
||||
**/
|
||||
@ -34,7 +34,8 @@ class SparseReordering
|
||||
public:
|
||||
SparseReordering(const std::map<std::string,std::string>& config);
|
||||
|
||||
void AddScores(const TranslationOption& topt,
|
||||
//If direction is backward topt is the current option, otherwise the previous
|
||||
void CopyScores(const TranslationOption& topt,
|
||||
LexicalReorderingState::ReorderingType reoType,
|
||||
LexicalReorderingConfiguration::Direction direction,
|
||||
ScoreComponentCollection* scores) const ;
|
||||
|
Loading…
Reference in New Issue
Block a user