mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
Can now set thetas for Lattice MBR in terms of p and r (see Tromble et al. 08)
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2855 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
b4b7a71c46
commit
4ac95fb82a
@ -186,7 +186,7 @@ void pruneLatticeFB(Lattice & connectedHyp, map < const Hypothesis*, set <const
|
||||
}
|
||||
}
|
||||
|
||||
vector<Word> calcMBRSol(Lattice & connectedHyp, map<Phrase, float>& finalNgramScores, const vector<float> & thetas) {
|
||||
vector<Word> calcMBRSol(Lattice & connectedHyp, map<Phrase, float>& finalNgramScores, const vector<float> & thetas, float p, float r) {
|
||||
vector<Word> bestHyp;
|
||||
return bestHyp;
|
||||
}
|
||||
@ -401,7 +401,22 @@ bool ascendingCoverageCmp(const Hypothesis* a, const Hypothesis* b) {
|
||||
return a->GetWordsBitmap().GetNumWordsCovered() < b->GetWordsBitmap().GetNumWordsCovered();
|
||||
}
|
||||
|
||||
vector<Word> calcMBRSol(const TrellisPathList& nBestList, map<Phrase, float>& finalNgramScores,const vector<float> & thetas){
|
||||
vector<Word> calcMBRSol(const TrellisPathList& nBestList, map<Phrase, float>& finalNgramScores, const vector<float> & thetas, float p, float r){
|
||||
|
||||
vector<float> mbrThetas = thetas;
|
||||
if (thetas.size() == 0) { //thetas not specified on the command line, use p and r instead
|
||||
mbrThetas.push_back(-1); //Theta 0
|
||||
mbrThetas.push_back(1/(4*p));
|
||||
for (size_t i = 2; i <= bleu_order; ++i){
|
||||
mbrThetas.push_back(mbrThetas[i-1] / r);
|
||||
}
|
||||
}
|
||||
|
||||
//cout << "Thetas: ";
|
||||
// for (size_t i = 0; i < mbrThetas.size(); ++i) {
|
||||
// cout << mbrThetas[i] << " ";
|
||||
// }
|
||||
// cout << endl;
|
||||
|
||||
float argmaxScore = -1e20;
|
||||
TrellisPathList::const_iterator iter;
|
||||
@ -419,16 +434,16 @@ vector<Word> calcMBRSol(const TrellisPathList& nBestList, map<Phrase, float>& f
|
||||
extract_ngrams(translation,counts);
|
||||
|
||||
//Now score this translation
|
||||
float mbrScore = thetas[0] * translation.size();
|
||||
float mbrScore = mbrThetas[0] * translation.size();
|
||||
|
||||
float ngramScore = 0;
|
||||
|
||||
for (map < Phrase, int >::iterator ngrams = counts.begin(); ngrams != counts.end(); ++ngrams) {
|
||||
if (ngramScore == 0) {
|
||||
ngramScore = log(ngrams->second) + finalNgramScores[ngrams->first] + log(thetas[(ngrams->first).GetSize()]);
|
||||
ngramScore = log(ngrams->second) + finalNgramScores[ngrams->first] + log(mbrThetas[(ngrams->first).GetSize()]);
|
||||
}
|
||||
else {
|
||||
ngramScore = log_sum(ngramScore, float(log(ngrams->second) + finalNgramScores[ngrams->first] + log(thetas[(ngrams->first).GetSize()])));
|
||||
ngramScore = log_sum(ngramScore, float(log(ngrams->second) + finalNgramScores[ngrams->first] + log(mbrThetas[(ngrams->first).GetSize()])));
|
||||
}
|
||||
//cout << "Ngram: " << ngrams->first << endl;
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ class Edge {
|
||||
void pruneLatticeFB(Lattice & connectedHyp, map < const Hypothesis*, set <const Hypothesis* > > & outgoingHyps, map<const Hypothesis*, vector<Edge> >& incomingEdges,
|
||||
const vector< float> & estimatedScores, size_t edgeDensity);
|
||||
|
||||
vector<Word> calcMBRSol(Lattice & connectedHyp, map<Phrase, float>& finalNgramScores,const vector<float> & thetas);
|
||||
vector<Word> calcMBRSol(const TrellisPathList& nBestList, map<Phrase, float>& finalNgramScores,const vector<float> & thetas);
|
||||
vector<Word> calcMBRSol(Lattice & connectedHyp, map<Phrase, float>& finalNgramScores,const vector<float> & thetas, float, float);
|
||||
vector<Word> calcMBRSol(const TrellisPathList& nBestList, map<Phrase, float>& finalNgramScores,const vector<float> & thetas, float, float);
|
||||
void calcNgramPosteriors(Lattice & connectedHyp, map<const Hypothesis*, vector<Edge> >& incomingEdges, float scale, map<Phrase, float>& finalNgramScores);
|
||||
void GetOutputFactors(const TrellisPath &path, vector <Word> &translation);
|
||||
void extract_ngrams(const vector<Word >& sentence, map < Phrase, int > & allngrams);
|
||||
|
@ -191,11 +191,11 @@ int main(int argc, char* argv[])
|
||||
manager.CalcNBest(nBestSize, nBestList,true);
|
||||
VERBOSE(2,"size of n-best: " << nBestList.GetSize() << " (" << nBestSize << ")" << endl);
|
||||
IFVERBOSE(2) { PrintUserTime("calculated n-best list for MBR decoding"); }
|
||||
mbrBestHypo = calcMBRSol(nBestList, ngramPosteriors, staticData.GetLatticeMBRThetas());
|
||||
mbrBestHypo = calcMBRSol(nBestList, ngramPosteriors, staticData.GetLatticeMBRThetas(), staticData.GetLatticeMBRPrecision(), staticData.GetLatticeMBRPRatio());
|
||||
}
|
||||
}
|
||||
else {
|
||||
mbrBestHypo = calcMBRSol(connectedList, ngramPosteriors, staticData.GetLatticeMBRThetas());
|
||||
mbrBestHypo = calcMBRSol(connectedList, ngramPosteriors, staticData.GetLatticeMBRThetas(), staticData.GetLatticeMBRPrecision(), staticData.GetLatticeMBRPRatio());
|
||||
}
|
||||
|
||||
ioWrapper->OutputBestHypo(mbrBestHypo, source->GetTranslationId(), staticData.GetReportSegmentation(),
|
||||
|
@ -94,6 +94,8 @@ Parameter::Parameter()
|
||||
AddParam("mbr-scale", "scaling factor to convert log linear score probability in MBR decoding (default 1.0)");
|
||||
AddParam("lmbr-thetas", "theta(s) for lattice mbr calculation");
|
||||
AddParam("lmbr-pruning-factor", "average number of nodes/word wanted in pruned lattice");
|
||||
AddParam("lmbr-p", "unigram precision value for lattice mbr");
|
||||
AddParam("lmbr-r", "ngram precision decay value for lattice mbr");
|
||||
AddParam("lattice-hypo-set", "to use lattice as hypo set during lattice MBR");
|
||||
AddParam("use-persistent-cache", "cache translation options across sentences (default true)");
|
||||
AddParam("persistent-cache-size", "maximum size of cache for translation options (default 10,000 input phrases)");
|
||||
|
@ -338,6 +338,10 @@ bool StaticData::LoadData(Parameter *parameter)
|
||||
Scan<size_t>(m_parameter->GetParam("lmbr-pruning-factor")[0]) : 30;
|
||||
m_lmbrThetas = Scan<float>(m_parameter->GetParam("lmbr-thetas"));
|
||||
SetBooleanParameter( &m_useLatticeHypSetForLatticeMBR, "lattice-hypo-set", false );
|
||||
m_lmbrPrecision = (m_parameter->GetParam("lmbr-p").size() > 0) ?
|
||||
Scan<float>(m_parameter->GetParam("lmbr-p")[0]) : 0.8f;
|
||||
m_lmbrPRatio = (m_parameter->GetParam("lmbr-r").size() > 0) ?
|
||||
Scan<float>(m_parameter->GetParam("lmbr-r")[0]) : 0.6f;
|
||||
|
||||
m_timeout_threshold = (m_parameter->GetParam("time-out").size() > 0) ?
|
||||
Scan<size_t>(m_parameter->GetParam("time-out")[0]) : -1;
|
||||
|
@ -147,6 +147,9 @@ protected:
|
||||
size_t m_lmbrPruning; //! average number of nodes per word wanted in pruned lattice
|
||||
vector<float> m_lmbrThetas; //! theta(s) for lattice mbr calculation
|
||||
bool m_useLatticeHypSetForLatticeMBR; //! to use nbest as hypothesis set during lattice MBR
|
||||
float m_lmbrPrecision; //! unigram precision theta - see Tromble et al 08 for more details
|
||||
float m_lmbrPRatio; //! decaying factor for ngram thetas - see Tromble et al 08 for more details
|
||||
|
||||
|
||||
bool m_timeout; //! use timeout
|
||||
size_t m_timeout_threshold; //! seconds after which time out is activated
|
||||
@ -462,7 +465,12 @@ public:
|
||||
size_t GetLatticeMBRPruningFactor() const { return m_lmbrPruning; }
|
||||
const vector<float>& GetLatticeMBRThetas() const {return m_lmbrThetas;}
|
||||
bool UseLatticeHypSetForLatticeMBR() const { return m_useLatticeHypSetForLatticeMBR;}
|
||||
|
||||
float GetLatticeMBRPrecision() const {
|
||||
return m_lmbrPrecision;
|
||||
}
|
||||
float GetLatticeMBRPRatio() const {
|
||||
return m_lmbrPRatio;
|
||||
}
|
||||
|
||||
bool UseTimeout() const { return m_timeout; }
|
||||
size_t GetTimeoutThreshold() const { return m_timeout_threshold; }
|
||||
|
Loading…
Reference in New Issue
Block a user