delete chart translation option if -inf score. Add FF MaxSpanFreeNonTermSource to use it

This commit is contained in:
Hieu Hoang 2014-05-12 19:44:31 +01:00
parent 5f7c424f7f
commit 6c9bc9f988
5 changed files with 53 additions and 4 deletions

View File

@ -176,6 +176,36 @@ void ChartTranslationOptionList::Evaluate(const InputType &input, const InputPat
ChartTranslationOptions &transOpts = **iter;
transOpts.Evaluate(input, inputPath);
}
// get rid of empty trans opts
size_t numDiscard = 0;
for (size_t i = 0; i < m_size; ++i) {
ChartTranslationOptions *transOpts = m_collection[i];
if (transOpts->GetSize() == 0) {
//delete transOpts;
++numDiscard;
}
else if (numDiscard) {
SwapTranslationOptions(i - numDiscard, i);
//m_collection[] = transOpts;
}
}
size_t newSize = m_size - numDiscard;
if (numDiscard) {
cerr << "LIST numDiscard=" << numDiscard << " newSize=" << newSize << endl;
}
m_size = newSize;
}
void ChartTranslationOptionList::SwapTranslationOptions(size_t a, size_t b)
{
ChartTranslationOptions *transOptsA = m_collection[a];
ChartTranslationOptions *transOptsB = m_collection[b];
m_collection[a] = transOptsB;
m_collection[b] = transOptsA;
}
std::ostream& operator<<(std::ostream &out, const ChartTranslationOptionList &obj)

View File

@ -78,6 +78,8 @@ private:
float m_thresholdScore;
};
void SwapTranslationOptions(size_t a, size_t b);
CollType m_collection;
size_t m_size;
float m_scoreThreshold;

View File

@ -78,9 +78,12 @@ void ChartTranslationOptions::Evaluate(const InputType &input, const InputPath &
}
}
m_collection.resize(m_collection.size() - numDiscard);
size_t newSize = m_collection.size() - numDiscard;
if (numDiscard) {
cerr << "numDiscard=" << numDiscard << " newSize=" << newSize << endl;
}
m_collection.resize(newSize);
}
void ChartTranslationOptions::SetInputPath(const InputPath *inputPath)

View File

@ -7,6 +7,7 @@
#include "moses/StackVec.h"
#include "moses/WordsRange.h"
#include "moses/ChartCellLabel.h"
#include "moses/FactorCollection.h"
using namespace std;
@ -15,9 +16,15 @@ namespace Moses
MaxSpanFreeNonTermSource::MaxSpanFreeNonTermSource(const std::string &line)
:StatelessFeatureFunction(1, line)
,m_maxSpan(2)
,m_glueTargetLHSStr("S")
,m_glueTargetLHS(true)
{
m_tuneable = false;
ReadParameters();
FactorCollection &fc = FactorCollection::Instance();
const Factor *factor = fc.AddFactor(Output, 0, m_glueTargetLHSStr);
m_glueTargetLHS.SetFactor(0, factor);
}
void MaxSpanFreeNonTermSource::Evaluate(const Phrase &source
@ -35,10 +42,14 @@ void MaxSpanFreeNonTermSource::Evaluate(const InputType &input
, ScoreComponentCollection &scoreBreakdown
, ScoreComponentCollection *estimatedFutureScore) const
{
const Word &targetLHS = targetPhrase.GetTargetLHS();
if (m_glueTargetLHS == m_glueTargetLHS) {
// don't delete glue rules
return;
}
const Phrase *source = targetPhrase.GetRuleSource();
assert(source);
cerr << "stackVec=" << stackVec->size() << " source="<< *source << endl;
float score = 0;
if (source->Front().IsNonTerminal()) {

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include "StatelessFeatureFunction.h"
#include "moses/Word.h"
namespace Moses
{
@ -39,6 +40,8 @@ public:
protected:
int m_maxSpan;
std::string m_glueTargetLHSStr;
Word m_glueTargetLHS;
};
}