mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
refactor input score handling to use Evaluate(inputtype, inputpath). Not a placeholder factor anymore
This commit is contained in:
parent
2b030339e0
commit
abfe02f154
@ -1,6 +1,8 @@
|
||||
#include <stdexcept>
|
||||
#include "InputFeature.h"
|
||||
#include "moses/Util.h"
|
||||
#include "moses/ScoreComponentCollection.h"
|
||||
#include "moses/InputPath.h"
|
||||
#include "util/check.hh"
|
||||
|
||||
using namespace std;
|
||||
@ -10,20 +12,30 @@ namespace Moses
|
||||
InputFeature::InputFeature(const std::string &line)
|
||||
:StatelessFeatureFunction("InputFeature", line)
|
||||
{
|
||||
for (size_t i = 0; i < m_args.size(); ++i) {
|
||||
const vector<string> &args = m_args[i];
|
||||
CHECK(args.size() == 2);
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
if (args[0] == "num-input-features") {
|
||||
m_numInputScores = Scan<size_t>(args[1]);
|
||||
} else if (args[0] == "real-word-count") {
|
||||
m_numRealWordCount = Scan<size_t>(args[1]);
|
||||
} else {
|
||||
throw "Unknown argument " + args[0];
|
||||
}
|
||||
}
|
||||
void InputFeature::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "num-input-features") {
|
||||
m_numInputScores = Scan<size_t>(value);
|
||||
} else if (key == "real-word-count") {
|
||||
m_numRealWordCount = Scan<size_t>(value);
|
||||
} else {
|
||||
StatelessFeatureFunction::SetParameter(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InputFeature::Evaluate(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, ScoreComponentCollection &scoreBreakdown) const
|
||||
{
|
||||
const ScoreComponentCollection *scores = inputPath.GetInputScore();
|
||||
if (scores) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -16,6 +16,8 @@ protected:
|
||||
public:
|
||||
InputFeature(const std::string &line);
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
}
|
||||
@ -27,6 +29,9 @@ public:
|
||||
return m_numRealWordCount;
|
||||
}
|
||||
|
||||
virtual void Evaluate(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, ScoreComponentCollection &scoreBreakdown) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -149,20 +149,6 @@ void TargetPhrase::SetXMLScore(float score)
|
||||
m_scoreBreakdown.Assign(prod, scoreVector);
|
||||
}
|
||||
|
||||
void TargetPhrase::SetInputScore(const Scores &scoreVector)
|
||||
{
|
||||
//we use an existing score producer to figure out information for score setting (number of scores and weights)
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const FeatureFunction* prod = staticData.GetPhraseDictionaries()[0];
|
||||
|
||||
//expand the input weight vector
|
||||
CHECK(scoreVector.size() <= prod->GetNumScoreComponents());
|
||||
Scores sizedScoreVector = scoreVector;
|
||||
sizedScoreVector.resize(prod->GetNumScoreComponents(),0.0f);
|
||||
|
||||
m_scoreBreakdown.Assign(prod, sizedScoreVector);
|
||||
}
|
||||
|
||||
void TargetPhrase::SetAlignmentInfo(const StringPiece &alignString)
|
||||
{
|
||||
AlignmentInfo::CollType alignTerm, alignNonTerm;
|
||||
|
@ -72,7 +72,6 @@ public:
|
||||
|
||||
// used to set translation or gen score
|
||||
void SetXMLScore(float score);
|
||||
void SetInputScore(const Scores &scoreVector);
|
||||
|
||||
#ifdef HAVE_PROTOBUF
|
||||
void WriteToRulePB(hgmert::Rule* pb) const;
|
||||
|
@ -257,10 +257,6 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const InputPath &inputPa
|
||||
|
||||
targetPhrase.GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
|
||||
|
||||
if (inputScores != NULL) {
|
||||
targetPhrase.SetInputScore(*inputScores);
|
||||
}
|
||||
|
||||
// source phrase
|
||||
const Phrase &sourcePhrase = inputPath.GetPhrase();
|
||||
m_unksrcs.push_back(&sourcePhrase);
|
||||
|
Loading…
Reference in New Issue
Block a user