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