integrate compact lex RO

This commit is contained in:
Hieu Hoang 2015-12-20 17:03:16 +00:00
parent 6f25f43cf9
commit 4a36aa59c8
9 changed files with 25 additions and 14 deletions

View File

@ -53,7 +53,7 @@ public:
Scores *estimatedScores) const = 0;
virtual void
EvaluateAfterTablePruning(const TargetPhrases &tps) const
EvaluateAfterTablePruning(MemPool &pool, const TargetPhrases &tps, const Phrase &sourcePhrase) const
{}
// clean up temporary memory, called after processing each sentence

View File

@ -189,10 +189,11 @@ FeatureFunctions::EvaluateInIsolation(MemPool &pool, const System &system,
targetPhrase.SetEstimatedScore(estimatedScores.GetTotalScore());
}
void FeatureFunctions::EvaluateAfterTablePruning(const TargetPhrases &tps) const
void FeatureFunctions::EvaluateAfterTablePruning(MemPool &pool, const TargetPhrases &tps, const Phrase &sourcePhrase) const
{
BOOST_FOREACH(const FeatureFunction *ff, m_featureFunctions) {
ff->EvaluateAfterTablePruning(tps); }
ff->EvaluateAfterTablePruning(pool, tps, sourcePhrase);
}
}

View File

@ -54,7 +54,7 @@ public:
// the pool here must be the system pool if the rule was loaded during load, or the mgr if it was loaded on demand
void EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase &source, TargetPhrase &targetPhrase) const;
void EvaluateAfterTablePruning(const TargetPhrases &tps) const;
void EvaluateAfterTablePruning(MemPool &pool, const TargetPhrases &tps, const Phrase &sourcePhrase) const;
protected:
std::vector<const FeatureFunction*> m_featureFunctions;

View File

@ -140,18 +140,22 @@ void LexicalReordering::EvaluateInIsolation(MemPool &pool,
{
}
void LexicalReordering::EvaluateAfterTablePruning(const TargetPhrases &tps) const
void LexicalReordering::EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrases &tps,
const Phrase &sourcePhrase) const
{
BOOST_FOREACH(const TargetPhrase *tp, tps) {
EvaluateAfterTablePruning(*tp);
EvaluateAfterTablePruning(pool, *tp, sourcePhrase);
}
}
void LexicalReordering::EvaluateAfterTablePruning(const TargetPhrase &targetPhrase) const
void LexicalReordering::EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrase &targetPhrase,
const Phrase &sourcePhrase) const
{
/*
if (m_compactModel) {
const Values values = m_compactModel->GetScore(source, targetPhrase, *m_blank);
const Values values = m_compactModel->GetScore(sourcePhrase, targetPhrase, *m_blank);
if (values.size()) {
assert(values.size() == 6);
SCORE *scoreArr = pool.Allocate<SCORE>(6);
@ -168,7 +172,7 @@ void LexicalReordering::EvaluateAfterTablePruning(const TargetPhrase &targetPhra
assert(m_coll);
// cache data in target phrase
const Values *values = GetValues(source, targetPhrase);
const Values *values = GetValues(sourcePhrase, targetPhrase);
if (values) {
SCORE *scoreArr = pool.Allocate<SCORE>(6);
for (size_t i = 0; i < 6; ++i) {

View File

@ -45,7 +45,9 @@ public:
Scores *estimatedScores) const;
virtual void
EvaluateAfterTablePruning(const TargetPhrases &tps) const;
EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrases &tps,
const Phrase &sourcePhrase) const;
virtual void EvaluateWhenApplied(const Manager &mgr,
const Hypothesis &hypo,
@ -60,7 +62,9 @@ protected:
FactorList m_FactorsC;
virtual void
EvaluateAfterTablePruning(const TargetPhrase &targetPhrase) const;
EvaluateAfterTablePruning(MemPool &pool,
const TargetPhrase &targetPhrase,
const Phrase &sourcePhrase) const;
// COMPACT MODEL
LexicalReorderingTableCompact *m_compactModel;

View File

@ -39,6 +39,7 @@ PhraseTableMemory::Node &PhraseTableMemory::Node::AddRule(PhraseImpl &source, Ta
if (pos == source.GetSize()) {
if (m_unsortedTPS == NULL) {
m_unsortedTPS = new std::vector<TargetPhrase*>();
m_source = &source;
}
m_unsortedTPS->push_back(target);
@ -88,7 +89,7 @@ void PhraseTableMemory::Node::SortAndPrune(size_t tableLimit, MemPool &pool, Sys
}
m_targetPhrases->SortAndPrune(tableLimit);
system.featureFunctions.EvaluateAfterTablePruning(*m_targetPhrases);
system.featureFunctions.EvaluateAfterTablePruning(system.systemPool, *m_targetPhrases, *m_source);
delete m_unsortedTPS;
}

View File

@ -30,6 +30,7 @@ class PhraseTableMemory : public PhraseTable
typedef boost::unordered_map<Word, Node, UnorderedComparer<Word>, UnorderedComparer<Word> > Children;
Children m_children;
TargetPhrases *m_targetPhrases;
PhraseImpl *m_source;
std::vector<TargetPhrase*> *m_unsortedTPS;
Node &AddRule(PhraseImpl &source, TargetPhrase *target, size_t pos);

View File

@ -126,7 +126,7 @@ TargetPhrases* ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system
}
tps->SortAndPrune(m_tableLimit);
system.featureFunctions.EvaluateAfterTablePruning(*tps);
system.featureFunctions.EvaluateAfterTablePruning(pool, *tps, sourcePhrase);
}
else {
assert(query_result.second.size() == 0);

View File

@ -78,7 +78,7 @@ TargetPhrases *UnknownWordPenalty::Lookup(const Manager &mgr, MemPool &pool, Inp
system.featureFunctions.EvaluateInIsolation(memPool, system, source, *target);
tps->AddTargetPhrase(*target);
system.featureFunctions.EvaluateAfterTablePruning(*tps);
system.featureFunctions.EvaluateAfterTablePruning(memPool, *tps, source);
return tps;
}