LDC code: fixed more problems.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/chardmeier-ldc@1974 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
chardmeier 2009-01-09 11:08:19 +00:00
parent 1917e38960
commit 76c1dc149b
3 changed files with 43 additions and 6 deletions

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "StaticData.h"
#include "DummyScoreProducers.h"
#include "InputFileStream.h"
#include "LexicalDistortionCost.h"
using namespace std;
@ -305,7 +306,6 @@ void IOWrapper::OutputNBestList(const TrellisPathList &nBestList, long translati
if (labeledOutput)
*m_nBestStream << "d: ";
*m_nBestStream << path.GetScoreBreakdown().GetScoreForProducer(StaticData::Instance().GetDistortionScoreProducer()) << " ";
*m_nBestStream << path.GetScoreBreakdown().GetScoreForProducer(StaticData::Instance().GetDistortionScoreProducer2()) << " ";
// reordering
vector<LexicalReordering*> rms = StaticData::Instance().GetReorderModels();
@ -322,6 +322,23 @@ void IOWrapper::OutputNBestList(const TrellisPathList &nBestList, long translati
}
}
// lexical distortion cost
vector<LexicalDistortionCost*> ldcm = StaticData::Instance().GetLexicalDistortionCostModels();
if(ldcm.size() > 0)
{
if (labeledOutput) *m_nBestStream << "ldc: ";
vector<LexicalDistortionCost*>::iterator iter;
for(iter = ldcm.begin(); iter != ldcm.end(); ++iter)
{
vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
for (size_t j = 0; j<scores.size(); ++j)
{
*m_nBestStream << scores[j] << " ";
}
}
}
// lm
const LMList& lml = StaticData::Instance().GetAllLM();
if (lml.size() > 0) {

View File

@ -221,7 +221,6 @@ bool StaticData::LoadData(Parameter *parameter)
// score weights
const vector<string> distortionWeights = m_parameter->GetParam("weight-d");
m_weightDistortion = Scan<float>(distortionWeights[0]);
m_weightDistortion2 = Scan<float>(distortionWeights[1]);
m_weightWordPenalty = Scan<float>( m_parameter->GetParam("weight-w")[0] );
m_weightUnknownWord = 1; // do we want to let mert decide weight for this ???
@ -533,6 +532,13 @@ bool StaticData::LoadLexicalReorderingModel()
bool StaticData::LoadLexicalDistortion() {
const vector<string> fileStr = m_parameter->GetParam("lexical-distortion-cost");
const vector<string> weightsStr = m_parameter->GetParam("weight-ldc");
std::vector<float> weights;
for(size_t j = 0; j < weightsStr.size(); ++j) {
weights.push_back(Scan<float>(weightsStr[j]));
}
size_t weightIdx = 0;
for(size_t i = 0; i < fileStr.size(); ++i) {
vector<FactorType> input,output;
@ -595,8 +601,25 @@ bool StaticData::LoadLexicalDistortion() {
std::string fileName = spec[3];
LexicalDistortionCost *newmodel;
if(prior == "beta" && distribution == "binomial")
m_ldcModels.push_back(new LDCBetaBinomial(fileName, direction, condition, input, output));
newmodel = new LDCBetaBinomial(fileName, direction, condition, input, output);
else
assert(false);
m_ldcModels.push_back(newmodel);
m_scoreIndexManager.AddScoreProducer(newmodel);
std::vector<float> cur_weights;
for(size_t i = 0; i < newmodel->GetNumParameterSets() * newmodel->GetNumParameters(); i++, weightIdx++) {
if(weightIdx >= weights.size()) {
UserMessage::Add("Insufficient number of lexical distortion model weights.");
return false;
}
cur_weights.push_back(weights[weightIdx]);
}
SetWeightsForScoreProducer(newmodel, cur_weights);
}
return true;

View File

@ -49,12 +49,10 @@ class UnknownWordPenaltyProducer;
class StaticData
{
private:
typedef std::map< std::pair< std::string,std::string >,float* > _DistortionMapType;
static StaticData s_instance;
protected:
std::map<long,Phrase> m_constraints;
_DistortionMapType m_distortionTable;
std::vector<PhraseDictionary*> m_phraseDictionary;
std::vector<GenerationDictionary*> m_generationDictionary;
std::vector <DecodeGraph*> m_decodeStepVL;
@ -70,7 +68,6 @@ protected:
float
m_beamWidth,
m_weightDistortion,
m_weightDistortion2,
m_weightWordPenalty,
m_wordDeletionWeight,
m_weightUnknownWord;