mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 15:00:33 +03:00
fixing scores
This commit is contained in:
parent
82a2129eb4
commit
9a68ff8da4
@ -11,6 +11,8 @@
|
||||
#include "moses/Range.h"
|
||||
#include "moses/Bitmap.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct DistortionState_traditional : public Moses::FFState {
|
||||
Moses::Range range;
|
||||
int first_gap;
|
||||
@ -79,6 +81,7 @@ Moses::FFState* Distortion::EvaluateWhenApplied(const Manager &mgr,
|
||||
prev.range,
|
||||
hypo.GetRange(),
|
||||
prev.first_gap);
|
||||
//cerr << "distortionScore=" << distortionScore << endl;
|
||||
|
||||
score.PlusEquals(mgr.GetSystem(), *this, distortionScore);
|
||||
|
||||
|
@ -31,7 +31,7 @@ FeatureFunctions::~FeatureFunctions() {
|
||||
Moses::RemoveAllInColl(m_featureFunctions);
|
||||
}
|
||||
|
||||
void FeatureFunctions::LoadFeatureFunctions()
|
||||
void FeatureFunctions::Create()
|
||||
{
|
||||
const Moses::Parameter ¶ms = m_system.GetParameter();
|
||||
|
||||
@ -56,7 +56,10 @@ void FeatureFunctions::LoadFeatureFunctions()
|
||||
m_phraseTables.push_back(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FeatureFunctions::Load()
|
||||
{
|
||||
// load, everything but pts
|
||||
BOOST_FOREACH(const FeatureFunction *ff, m_featureFunctions) {
|
||||
FeatureFunction *nonConstFF = const_cast<FeatureFunction*>(ff);
|
||||
@ -107,7 +110,7 @@ FeatureFunction *FeatureFunctions::Create(const std::string &line)
|
||||
return ret;
|
||||
}
|
||||
|
||||
const FeatureFunction &FeatureFunctions::FindFeatureFunction(const std::string &name)
|
||||
const FeatureFunction &FeatureFunctions::FindFeatureFunction(const std::string &name) const
|
||||
{
|
||||
BOOST_FOREACH(const FeatureFunction *ff, m_featureFunctions) {
|
||||
if (ff->GetName() == name) {
|
||||
|
@ -36,9 +36,10 @@ public:
|
||||
size_t GetNumScores() const
|
||||
{ return m_ffStartInd; }
|
||||
|
||||
void LoadFeatureFunctions();
|
||||
void Create();
|
||||
void Load();
|
||||
|
||||
const FeatureFunction &FindFeatureFunction(const std::string &name);
|
||||
const FeatureFunction &FindFeatureFunction(const std::string &name) const;
|
||||
|
||||
virtual void
|
||||
EvaluateInIsolation(const System &system,
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "Scores.h"
|
||||
#include "StatefulFeatureFunction.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Hypothesis::Hypothesis(Manager &mgr,
|
||||
const TargetPhrase &tp,
|
||||
const Moses::Range &range,
|
||||
@ -135,5 +137,6 @@ void Hypothesis::EvaluateWhenApplied()
|
||||
m_ffStates[statefulInd] = state;
|
||||
}
|
||||
|
||||
cerr << *this << endl;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ void Scores::PlusEquals(const System &system,
|
||||
SCORE incrScore = scores[i];
|
||||
m_scores[ffStartInd + i] += incrScore;
|
||||
|
||||
cerr << "ffStartInd=" << ffStartInd << " " << i << endl;
|
||||
SCORE weight = weights[ffStartInd + i];
|
||||
m_total += incrScore * weight;
|
||||
}
|
||||
@ -72,13 +73,13 @@ void Scores::PlusEquals(const System &system,
|
||||
|
||||
}
|
||||
|
||||
void Scores::PlusEquals(const System &system, const Scores &scores)
|
||||
void Scores::PlusEquals(const System &system, const Scores &other)
|
||||
{
|
||||
size_t numScores = system.GetFeatureFunctions().GetNumScores();
|
||||
for (size_t i = 0; i < numScores; ++i) {
|
||||
m_scores[i] += scores.m_scores[i];
|
||||
m_scores[i] += other.m_scores[i];
|
||||
}
|
||||
m_total += scores.m_total;
|
||||
m_total += other.m_total;
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,9 @@ System::System(const Moses::Parameter ¶ms)
|
||||
:m_featureFunctions(*this)
|
||||
,m_params(params)
|
||||
{
|
||||
m_featureFunctions.LoadFeatureFunctions();
|
||||
m_featureFunctions.Create();
|
||||
LoadWeights();
|
||||
m_featureFunctions.Load();
|
||||
}
|
||||
|
||||
System::~System() {
|
||||
@ -30,6 +31,7 @@ void System::LoadWeights()
|
||||
const Moses::PARAM_VEC *weightParams = m_params.GetParam("weight");
|
||||
UTIL_THROW_IF2(weightParams == NULL, "Must have [weight] section");
|
||||
|
||||
m_weights.Init(m_featureFunctions);
|
||||
BOOST_FOREACH(const std::string &line, *weightParams) {
|
||||
m_weights.CreateFromString(m_featureFunctions, line);
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ TargetPhrases::shared_const_ptr UnknownWordPenalty::Lookup(const Manager &mgr, I
|
||||
//const Moses::Factor *factor = fc.AddFactor("SSS", false);
|
||||
word[0] = factor;
|
||||
|
||||
// TODO - set score
|
||||
Scores &scores = target->GetScores();
|
||||
scores.PlusEquals(mgr.GetSystem(), *this, -100);
|
||||
|
||||
system.GetFeatureFunctions().EvaluateInIsolation(system, source, *target, target->GetScores(), NULL);
|
||||
|
||||
|
@ -7,13 +7,15 @@
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "FeatureFunction.h"
|
||||
#include "FeatureFunctions.h"
|
||||
#include "Weights.h"
|
||||
#include "moses/Util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Weights::Weights() {
|
||||
Weights::Weights()
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
@ -22,6 +24,22 @@ Weights::~Weights() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void Weights::Init(const FeatureFunctions &ffs)
|
||||
{
|
||||
size_t totalNumScores = ffs.GetNumScores();
|
||||
cerr << "totalNumScores=" << totalNumScores << endl;
|
||||
m_weights.resize(totalNumScores, 1);
|
||||
}
|
||||
|
||||
void Weights::Debug(std::ostream &out, const FeatureFunctions &ffs) const
|
||||
{
|
||||
size_t numScores = ffs.GetNumScores();
|
||||
for (size_t i = 0; i < numScores; ++i) {
|
||||
out << m_weights[i] << " ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &out, const Weights &obj)
|
||||
{
|
||||
|
||||
@ -39,5 +57,13 @@ void Weights::CreateFromString(const FeatureFunctions &ffs, const std::string &l
|
||||
ffName = ffName.substr(0, ffName.size() - 1);
|
||||
cerr << "ffName=" << ffName << endl;
|
||||
|
||||
const FeatureFunction &ff = ffs.FindFeatureFunction(ffName);
|
||||
size_t startInd = ff.GetStartInd();
|
||||
size_t numScores = ff.GetNumScores();
|
||||
assert(numScores == toks.size() -1);
|
||||
|
||||
for (size_t i = 0; i < numScores; ++i) {
|
||||
SCORE score = Moses::Scan<SCORE>(toks[i+1]);
|
||||
m_weights[i + startInd] = score;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define WEIGHTS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "TypeDef.h"
|
||||
|
||||
class FeatureFunctions;
|
||||
@ -18,13 +19,18 @@ class Weights {
|
||||
public:
|
||||
Weights();
|
||||
virtual ~Weights();
|
||||
void Init(const FeatureFunctions &ffs);
|
||||
|
||||
SCORE operator[](size_t ind) const {
|
||||
return 444.5f;
|
||||
return m_weights[ind];
|
||||
}
|
||||
|
||||
void Debug(std::ostream &out, const FeatureFunctions &ffs) const;
|
||||
|
||||
void CreateFromString(const FeatureFunctions &ffs, const std::string &line);
|
||||
|
||||
protected:
|
||||
std::vector<SCORE> m_weights;
|
||||
};
|
||||
|
||||
#endif /* WEIGHTS_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user