add completed-hypo to Distortion FF

This commit is contained in:
Hieu Hoang 2017-01-01 22:54:48 +00:00
parent e14a71c3ea
commit d4642a34c1
2 changed files with 34 additions and 8 deletions

View File

@ -57,6 +57,7 @@ struct DistortionState_traditional: public FFState
Distortion::Distortion(size_t startInd, const std::string &line) :
StatefulFeatureFunction(startInd, line)
{
m_completedHypo = false;
ReadParameters();
}
@ -65,6 +66,16 @@ Distortion::~Distortion()
// TODO Auto-generated destructor stub
}
void Distortion::SetParameter(const std::string& key, const std::string& value)
{
if (key == "completed-hypo") {
m_completedHypo = Scan<bool>(value);
}
else {
StatefulFeatureFunction::SetParameter(key, value);
}
}
FFState* Distortion::BlankState(MemPool &pool, const System &sys) const
{
return new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional();
@ -110,7 +121,7 @@ void Distortion::EvaluateWhenApplied(const ManagerBase &mgr,
const DistortionState_traditional &prev =
static_cast<const DistortionState_traditional&>(prevState);
SCORE distortionScore = CalculateDistortionScore(prev.range,
hypo.GetInputPath().range, prev.first_gap);
hypo.GetInputPath().range, prev.first_gap, hypo.GetBitmap());
//cerr << "distortionScore=" << distortionScore << endl;
scores.PlusEquals(mgr.system, *this, distortionScore);
@ -123,11 +134,11 @@ void Distortion::EvaluateWhenApplied(const ManagerBase &mgr,
}
SCORE Distortion::CalculateDistortionScore(const Range &prev, const Range &curr,
const int FirstGap) const
const int FirstGap, const Bitmap &coverage) const
{
bool useEarlyDistortionCost = false;
if (!useEarlyDistortionCost) {
return -(SCORE) ComputeDistortionDistance(prev, curr);
return -(SCORE) ComputeDistortionDistance(prev, curr, coverage);
}
else {
/* Pay distortion score as soon as possible, from Moore and Quirk MT Summit 2007
@ -168,7 +179,7 @@ SCORE Distortion::CalculateDistortionScore(const Range &prev, const Range &curr,
}
int Distortion::ComputeDistortionDistance(const Range& prev,
const Range& current) const
const Range& current, const Bitmap &coverage) const
{
int dist = 0;
if (prev.GetNumWordsCovered() == 0) {
@ -176,8 +187,18 @@ int Distortion::ComputeDistortionDistance(const Range& prev,
}
else {
dist = (int) prev.GetEndPos() - (int) current.GetStartPos() + 1;
dist = abs(dist);
if (m_completedHypo && coverage.IsComplete()) {
dist += coverage.GetSize() - current.GetEndPos() - 1;
/*
cerr << "completed=" << coverage << " " << coverage.GetSize() << " "
<< prev << " "
<< current << " " << dist << endl;
*/
}
}
return abs(dist);
return dist;
}
void Distortion::EvaluateWhenApplied(const SCFG::Manager &mgr,

View File

@ -14,6 +14,7 @@
namespace Moses2
{
class Bitmap;
class Distortion: public StatefulFeatureFunction
{
@ -21,6 +22,8 @@ public:
Distortion(size_t startInd, const std::string &line);
virtual ~Distortion();
virtual void SetParameter(const std::string& key, const std::string& value);
virtual FFState* BlankState(MemPool &pool, const System &sys) const;
virtual void EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
const InputType &input, const Hypothesis &hypo) const;
@ -48,10 +51,12 @@ public:
FFState &state) const;
protected:
SCORE CalculateDistortionScore(const Range &prev, const Range &curr,
const int FirstGap) const;
bool m_completedHypo;
int ComputeDistortionDistance(const Range& prev, const Range& current) const;
SCORE CalculateDistortionScore(const Range &prev, const Range &curr,
const int FirstGap, const Bitmap &coverage) const;
int ComputeDistortionDistance(const Range& prev, const Range& current, const Bitmap &coverage) const;
};