Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/moses
diff options
context:
space:
mode:
authorEva <eva@deimos.(none)>2012-04-24 08:21:18 +0400
committerEva <eva@deimos.(none)>2012-04-24 08:21:18 +0400
commit3db7f5f3e92f95af7acddfd329c699819a1e5fe4 (patch)
treec0e43c534f35d1cc9bc97bce0f8735626e8062ff /moses
parent191a418aea695c44708fa7b3934cabbb4d7dded6 (diff)
don't use stored weightWP and weightT
Diffstat (limited to 'moses')
-rw-r--r--moses/src/ChartRuleLookupManagerOnDisk.cpp5
-rw-r--r--moses/src/LM/Base.cpp6
-rw-r--r--moses/src/PDTAimp.h12
-rw-r--r--moses/src/PhraseDictionary.cpp24
-rw-r--r--moses/src/PhraseDictionaryALSuffixArray.cpp6
-rw-r--r--moses/src/PhraseDictionaryOnDisk.cpp5
-rw-r--r--moses/src/TargetPhrase.cpp27
-rw-r--r--moses/src/TranslationSystem.cpp8
-rw-r--r--moses/src/TranslationSystem.h3
9 files changed, 76 insertions, 20 deletions
diff --git a/moses/src/ChartRuleLookupManagerOnDisk.cpp b/moses/src/ChartRuleLookupManagerOnDisk.cpp
index b8c0674f5..77e699a08 100644
--- a/moses/src/ChartRuleLookupManagerOnDisk.cpp
+++ b/moses/src/ChartRuleLookupManagerOnDisk.cpp
@@ -241,11 +241,14 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection(
const OnDiskPt::TargetPhraseCollection *tpcollBerkeleyDb = node->GetTargetPhraseCollection(m_dictionary.GetTableLimit(), m_dbWrapper);
+ std::vector<float> weightT = staticData.GetTranslationSystem(TranslationSystem::DEFAULT).GetTranslationWeights();
+ cerr << "Read weightT from translation sytem.. " << std::endl;
targetPhraseCollection
= tpcollBerkeleyDb->ConvertToMoses(m_inputFactorsVec
,m_outputFactorsVec
,m_dictionary
- ,m_weight
+ //, m_weight
+ ,weightT
,m_wpProducer
,*m_languageModels
,m_filePath
diff --git a/moses/src/LM/Base.cpp b/moses/src/LM/Base.cpp
index abfd75eb3..45edf973e 100644
--- a/moses/src/LM/Base.cpp
+++ b/moses/src/LM/Base.cpp
@@ -41,12 +41,14 @@ LanguageModel::LanguageModel() :
LanguageModel::~LanguageModel() {}
float LanguageModel::GetWeight() const {
- return StaticData::Instance().GetAllWeights().GetScoresForProducer(this)[0];
+ //return StaticData::Instance().GetAllWeights().GetScoresForProducer(this)[0];
+ return StaticData::Instance().GetWeights(this)[0];
}
float LanguageModel::GetOOVWeight() const {
if (m_enableOOVFeature) {
- return StaticData::Instance().GetAllWeights().GetScoresForProducer(this)[1];
+ //return StaticData::Instance().GetAllWeights().GetScoresForProducer(this)[1];
+ return StaticData::Instance().GetWeights(this)[1];
} else {
return 0;
}
diff --git a/moses/src/PDTAimp.h b/moses/src/PDTAimp.h
index 5ded31408..34a5d73b7 100644
--- a/moses/src/PDTAimp.h
+++ b/moses/src/PDTAimp.h
@@ -443,11 +443,19 @@ public:
CHECK(nscores.size()==m_weights.size());
+ const TranslationSystem& system = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT);
+
//tally up
- float score=std::inner_product(nscores.begin(), nscores.end(), m_weights.begin(), 0.0f);
+ std::vector<float> weightT = system.GetTranslationWeights();
+ std::cerr << "Read weightT from translation sytem.. " << std::endl;
+ //float score=std::inner_product(nscores.begin(), nscores.end(), m_weights.begin(), 0.0f);
+ float score=std::inner_product(nscores.begin(), nscores.end(), weightT.begin(), 0.0f);
//count word penalty
- score-=tcands[i].tokens.size() * m_weightWP;
+ float weightWP = system.GetWeightWordPenalty();
+ std::cerr << "Read weightWP from translation sytem: " << weightWP << std::endl;
+ //score-=tcands[i].tokens.size() * m_weightWP;
+ score-=tcands[i].tokens.size() * weightWP;
std::pair<E2Costs::iterator,bool> p=e2costs.insert(std::make_pair(tcands[i].tokens,TScores()));
diff --git a/moses/src/PhraseDictionary.cpp b/moses/src/PhraseDictionary.cpp
index d337da83e..20eef291f 100644
--- a/moses/src/PhraseDictionary.cpp
+++ b/moses/src/PhraseDictionary.cpp
@@ -78,6 +78,9 @@ PhraseDictionaryFeature::PhraseDictionaryFeature
PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSystem* system)
{
const StaticData& staticData = StaticData::Instance();
+ std::vector<float> weightT = system->GetTranslationWeights();
+ cerr << "Read weightT from translation sytem.. " << std::endl;
+
if (m_implementation == Memory) {
// memory phrase table
VERBOSE(2,"using standard phrase tables" << std::endl);
@@ -93,7 +96,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
PhraseDictionaryMemory* pdm = new PhraseDictionaryMemory(GetNumScoreComponents(),this);
bool ret = pdm->Load(GetInput(), GetOutput()
, m_filePath
- , m_weight
+ //, m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWeightWordPenalty());
@@ -104,7 +108,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
bool ret = pdta->Load( GetInput()
, GetOutput()
, m_filePath
- , m_weight
+ //, m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWeightWordPenalty());
@@ -122,7 +127,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
bool ret = pdm->Load(GetInput()
, GetOutput()
, m_filePath
- , m_weight
+ // m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWordPenaltyProducer());
@@ -140,7 +146,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
bool ret = pdm->Load(GetInput()
, GetOutput()
, m_filePath
- , m_weight
+ //, m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWordPenaltyProducer());
@@ -158,7 +165,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
bool ret = pdm->Load(GetInput()
, GetOutput()
, m_filePath
- , m_weight
+ //, m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWordPenaltyProducer());
@@ -170,7 +178,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
bool ret = pdta->Load(GetInput()
, GetOutput()
, m_filePath
- , m_weight
+ //, m_weight
+ , weightT
, m_tableLimit
, system->GetLanguageModels()
, system->GetWordPenaltyProducer());
@@ -185,7 +194,8 @@ PhraseDictionary* PhraseDictionaryFeature::LoadPhraseTable(const TranslationSyst
,m_filePath
,m_targetFile
, m_alignmentsFile
- , m_weight, m_tableLimit
+ //, m_weight, m_tableLimit
+ , weightT, m_tableLimit
, system->GetLanguageModels()
, system->GetWeightWordPenalty()))) {
std::cerr << "FAILED TO LOAD\n" << endl;
diff --git a/moses/src/PhraseDictionaryALSuffixArray.cpp b/moses/src/PhraseDictionaryALSuffixArray.cpp
index 26a9d2a31..f12f2939e 100644
--- a/moses/src/PhraseDictionaryALSuffixArray.cpp
+++ b/moses/src/PhraseDictionaryALSuffixArray.cpp
@@ -13,6 +13,7 @@
#include "RuleTableLoader.h"
#include "RuleTableLoaderFactory.h"
#include "TypeDef.h"
+#include "StaticData.h"
using namespace std;
@@ -55,7 +56,10 @@ void PhraseDictionaryALSuffixArray::InitializeForInput(InputType const& source)
std::auto_ptr<RuleTableLoader> loader =
RuleTableLoaderFactory::Create(grammarFile);
- bool ret = loader->Load(*m_input, *m_output, inFile, *m_weight, m_tableLimit,
+ std::vector<float> weightT = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT).GetTranslationWeights();
+ cerr << "Read weightT from translation sytem.. " << std::endl;
+ //bool ret = loader->Load(*m_input, *m_output, inFile, *m_weight, m_tableLimit,
+ bool ret = loader->Load(*m_input, *m_output, inFile, weightT, m_tableLimit,
*m_languageModels, m_wpProducer, *this);
CHECK(ret);
diff --git a/moses/src/PhraseDictionaryOnDisk.cpp b/moses/src/PhraseDictionaryOnDisk.cpp
index 04c29c449..50ce05d57 100644
--- a/moses/src/PhraseDictionaryOnDisk.cpp
+++ b/moses/src/PhraseDictionaryOnDisk.cpp
@@ -94,10 +94,13 @@ ChartRuleLookupManager *PhraseDictionaryOnDisk::CreateRuleLookupManager(
const InputType &sentence,
const ChartCellCollection &cellCollection)
{
+ std::vector<float> weightT = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT).GetTranslationWeights();
+ cerr << "Read weightT from translation sytem.. " << std::endl;
return new ChartRuleLookupManagerOnDisk(sentence, cellCollection, *this,
m_dbWrapper, m_languageModels,
m_wpProducer, m_inputFactorsVec,
- m_outputFactorsVec, m_weight,
+ //m_outputFactorsVec, m_weight,
+ m_outputFactorsVec, weightT,
m_filePath);
}
diff --git a/moses/src/TargetPhrase.cpp b/moses/src/TargetPhrase.cpp
index 069284eb5..332b6c19e 100644
--- a/moses/src/TargetPhrase.cpp
+++ b/moses/src/TargetPhrase.cpp
@@ -110,7 +110,7 @@ void TargetPhrase::SetScore(float score)
vector <float> scoreVector(numScores,score/numScores);
//Now we have what we need to call the full SetScore method
- SetScore(prod,scoreVector, ScoreComponentCollection(), weights,system.GetWeightWordPenalty(),system.GetLanguageModels());
+ SetScore(prod, scoreVector, ScoreComponentCollection(), weights, system.GetWeightWordPenalty(), system.GetLanguageModels());
}
/**
@@ -142,7 +142,13 @@ void TargetPhrase::SetScore(const ScoreProducer* translationScoreProducer,
CHECK(weightT.size() == scoreVector.size());
// calc average score if non-best
- m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightT.begin(), 0.0f);
+ const TranslationSystem& system = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT);
+ std::vector<float> weightsT = system.GetTranslationWeights();
+ weightWP = system.GetWeightWordPenalty();
+ cerr << "Read weightWP from translation sytem: " << weightWP << std::endl;
+
+ //m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightT.begin(), 0.0f);
+ m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightsT.begin(), 0.0f);
m_scoreBreakdown.PlusEquals(translationScoreProducer, scoreVector);
m_scoreBreakdown.PlusEquals(sparseScoreVector);
@@ -183,7 +189,7 @@ void TargetPhrase::SetScore(const ScoreProducer* translationScoreProducer,
}
m_fullScore = m_transScore + totalFullScore + totalOOVScore
- - (this->GetSize() * weightWP); // word penalty
+ - (this->GetSize() * weightWP); // word penalty
}
void TargetPhrase::SetScoreChart(const ScoreProducer* translationScoreProducer,
@@ -195,8 +201,13 @@ void TargetPhrase::SetScoreChart(const ScoreProducer* translationScoreProducer,
CHECK(weightT.size() == scoreVector.size());
+ const TranslationSystem& system = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT);
+ std::vector<float> weightsT = system.GetTranslationWeights();
+ cerr << "Read weightsT from translation sytem.. " << std::endl;
+
// calc average score if non-best
- m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightT.begin(), 0.0f);
+ //m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightT.begin(), 0.0f);
+ m_transScore = std::inner_product(scoreVector.begin(), scoreVector.end(), weightsT.begin(), 0.0f);
m_scoreBreakdown.PlusEquals(translationScoreProducer, scoreVector);
// Replicated from TranslationOptions.cpp
@@ -260,8 +271,12 @@ void TargetPhrase::SetWeights(const ScoreProducer* translationScoreProducer, con
addition to the usual phrase translation scaling factors) the input
weight factor as last element
*/
-
- m_transScore = m_scoreBreakdown.PartialInnerProduct(translationScoreProducer, weightT);
+
+ const TranslationSystem& system = StaticData::Instance().GetTranslationSystem(TranslationSystem::DEFAULT);
+ std::vector<float> weightsT = system.GetTranslationWeights();
+ cerr << "Read weightsT from translation sytem.. " << std::endl;
+ //m_transScore = m_scoreBreakdown.PartialInnerProduct(translationScoreProducer, weightT);
+ m_transScore = m_scoreBreakdown.PartialInnerProduct(translationScoreProducer, weightsT);
}
void TargetPhrase::ResetScore()
diff --git a/moses/src/TranslationSystem.cpp b/moses/src/TranslationSystem.cpp
index 26393fea8..a21b71134 100644
--- a/moses/src/TranslationSystem.cpp
+++ b/moses/src/TranslationSystem.cpp
@@ -173,4 +173,12 @@ namespace Moses {
return StaticData::Instance().GetWeight(m_distortionScoreProducer);
}
+ std::vector<float> TranslationSystem::GetTranslationWeights() const {
+ std::vector<float> weights = StaticData::Instance().GetWeights(GetTranslationScoreProducer());
+ cerr << "Read weightT from translation sytem.. ";
+ for (size_t i = 0; i < weights.size(); ++i)
+ std::cerr << weights[i] << " ";
+ std::cerr << std::endl;
+ return weights;
+ }
};
diff --git a/moses/src/TranslationSystem.h b/moses/src/TranslationSystem.h
index e5f0be285..615fc7d8a 100644
--- a/moses/src/TranslationSystem.h
+++ b/moses/src/TranslationSystem.h
@@ -83,9 +83,12 @@ class TranslationSystem {
const UnknownWordPenaltyProducer *GetUnknownWordPenaltyProducer() const { return m_unknownWpProducer; }
const DistortionScoreProducer* GetDistortionProducer() const {return m_distortionScoreProducer;}
+ const PhraseDictionaryFeature *GetTranslationScoreProducer() const { return GetPhraseDictionaries()[0]; }
+
float GetWeightWordPenalty() const;
float GetWeightUnknownWordPenalty() const;
float GetWeightDistortion() const;
+ std::vector<float> GetTranslationWeights() const;
//sentence (and thread) specific initialisationn and cleanup
void InitializeBeforeSentenceProcessing(const InputType& source) const;