mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-11-12 16:27:56 +03:00
states work. scores don't
This commit is contained in:
parent
74b635e42f
commit
b1ee2bd643
@ -4,11 +4,13 @@
|
||||
* Created on: 26 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/foreach.hpp>
|
||||
#include "ArcLists.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
ArcLists::ArcLists() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
@ -23,6 +25,7 @@ ArcLists::~ArcLists() {
|
||||
|
||||
void ArcLists::AddArc(bool added, const Hypothesis *currHypo,const Hypothesis *otherHypo)
|
||||
{
|
||||
//cerr << added << " " << currHypo << " " << otherHypo << endl;
|
||||
if (added) {
|
||||
// we're winners!
|
||||
ArcList *arcList;
|
||||
|
@ -63,7 +63,6 @@ size_t Hypothesis::hash() const
|
||||
|
||||
// coverage
|
||||
seed = m_sourceCompleted.hash();
|
||||
seed = rand();
|
||||
|
||||
// states
|
||||
for (size_t i = 0; i < numStatefulFFs; ++i) {
|
||||
@ -109,7 +108,9 @@ void Hypothesis::OutputToStream(std::ostream &out) const
|
||||
|
||||
std::ostream& operator<<(std::ostream &out, const Hypothesis &obj)
|
||||
{
|
||||
|
||||
obj.OutputToStream(out);
|
||||
out << " ";
|
||||
obj.GetScores().Debug(out, obj.m_mgr.GetSystem().GetFeatureFunctions());
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,13 @@ int main(int argc, char** argv)
|
||||
mgr.Decode();
|
||||
|
||||
const Hypothesis *bestHypo = mgr.GetBestHypothesis();
|
||||
bestHypo->OutputToStream(cout);
|
||||
if (bestHypo) {
|
||||
cerr << *bestHypo << endl;
|
||||
bestHypo->OutputToStream(cout);
|
||||
}
|
||||
else {
|
||||
cout << "NO TRANSLATION";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ Manager::Manager(System &system, const std::string &inputStr)
|
||||
const std::vector<const PhraseTable*> &pts = system.GetFeatureFunctions().GetPhraseTables();
|
||||
for (size_t i = 0; i < pts.size(); ++i) {
|
||||
const PhraseTable &pt = *pts[i];
|
||||
cerr << "Looking up from " << pt.GetName() << endl;
|
||||
//cerr << "Looking up from " << pt.GetName() << endl;
|
||||
pt.Lookup(*this, m_inputPaths);
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ void Scores::CreateFromString(const std::string &str, const FeatureFunction &fea
|
||||
PlusEquals(system, featureFunction, scores);
|
||||
}
|
||||
|
||||
void Scores::Debug(std::ostream &out, const FeatureFunctions &ffs)
|
||||
void Scores::Debug(std::ostream &out, const FeatureFunctions &ffs) const
|
||||
{
|
||||
out << m_total << " = ";
|
||||
size_t numScores = ffs.GetNumScores();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
void PlusEquals(const System &system,
|
||||
const Scores &scores);
|
||||
|
||||
void Debug(std::ostream &out, const FeatureFunctions &ffs);
|
||||
void Debug(std::ostream &out, const FeatureFunctions &ffs) const;
|
||||
|
||||
protected:
|
||||
SCORE *m_scores;
|
||||
|
@ -63,6 +63,7 @@ void SearchNormal::Extend(const Hypothesis &hypo, const InputPath &path)
|
||||
}
|
||||
|
||||
const Moses::Bitmap &newBitmap = m_mgr.GetBitmaps().GetBitmap(bitmap, pathRange);
|
||||
|
||||
const std::vector<TargetPhrases::shared_const_ptr> &tpsAllPt = path.GetTargetPhrases();
|
||||
|
||||
for (size_t i = 0; i < tpsAllPt.size(); ++i) {
|
||||
@ -92,7 +93,8 @@ void SearchNormal::Extend(const Hypothesis &hypo,
|
||||
newHypo->EvaluateWhenApplied();
|
||||
|
||||
size_t numWordsCovered = newBitmap.GetNumWordsCovered();
|
||||
StackAdd stackAdded = m_stacks[numWordsCovered].Add(newHypo);
|
||||
Stack &stack = m_stacks[numWordsCovered];
|
||||
StackAdd stackAdded = stack.Add(newHypo);
|
||||
|
||||
m_arcLists.AddArc(stackAdded.added, newHypo, stackAdded.other);
|
||||
}
|
||||
@ -110,7 +112,10 @@ const Hypothesis *SearchNormal::GetBestHypothesis() const
|
||||
const Stack &lastStack = m_stacks.back();
|
||||
std::vector<const Hypothesis*> sortedHypos = lastStack.GetSortedHypos();
|
||||
|
||||
const Hypothesis *best = sortedHypos[0];
|
||||
const Hypothesis *best = NULL;
|
||||
if (sortedHypos.size()) {
|
||||
best = sortedHypos[0];
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,16 @@ StackAdd Stack::Add(const Hypothesis *hypo)
|
||||
if (hypo->GetScores().GetTotalScore() > hypoExisting->GetScores().GetTotalScore()) {
|
||||
// incoming hypo is better than the one we have
|
||||
m_hypos.erase(addRet.first);
|
||||
|
||||
// re-add. It better go in
|
||||
std::pair<iterator, bool> addRet = m_hypos.insert(hypo);
|
||||
assert(addRet.second);
|
||||
|
||||
return StackAdd(true, hypoExisting);
|
||||
}
|
||||
else {
|
||||
// already storing the best hypo. discard incoming hypo
|
||||
return StackAdd(false, hypo);
|
||||
return StackAdd(false, hypoExisting);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user