sort before evaluating batch

This commit is contained in:
Hieu Hoang 2015-11-25 17:35:22 +00:00
parent d5bd15bb2b
commit 9ec73a2032
8 changed files with 55 additions and 7 deletions

View File

@ -169,6 +169,11 @@ class ObjectPoolContiguous {
{
--m_size;
}
T *GetData()
{
return m_vec;
}
private:
T *m_vec;
size_t m_size, m_actualSize;

View File

@ -67,3 +67,19 @@ protected:
const PhraseImpl *m_origPhrase;
size_t m_start, m_end;
};
class PhraseOrdererLexical
{
public:
bool operator()(const Phrase &a, const Phrase &b) const {
size_t minSize = std::min(a.GetSize(), b.GetSize());
for (size_t i = 0; i < minSize; ++i) {
const Word &aWord = a[i];
const Word &bWord = b[i];
if (aWord < bWord) {
return true;
}
}
return a.GetSize() < b.GetSize();
}
};

View File

@ -4,15 +4,14 @@
* Created on: 24 Oct 2015
* Author: hieu
*/
#ifndef HYPOTHESIS_H_
#define HYPOTHESIS_H_
#pragma once
#include <iostream>
#include <cstddef>
#include "../legacy/FFState.h"
#include "../legacy/Bitmap.h"
#include "../Scores.h"
#include "../Phrase.h"
#include "../TargetPhrase.h"
#include "../legacy/Range.h"
@ -112,4 +111,13 @@ public:
}
};
#endif /* HYPOTHESIS_H_ */
class HypothesisTargetPhraseOrderer
{
public:
bool operator()(const Hypothesis* a, const Hypothesis* b) const {
PhraseOrdererLexical phraseCmp;
bool ret = phraseCmp((const Phrase&) a->GetTargetPhrase(), (const Phrase&) b->GetTargetPhrase());
return ret;
}
};

View File

@ -5,11 +5,15 @@
* Author: hieu
*/
#ifndef SEARCH_SEARCHCUBEPRUNING_H_
#define SEARCH_SEARCHCUBEPRUNING_H_
#pragma once
#include <boost/unordered_map.hpp>
#include <vector>
#include "Search.h"
class Bitmap;
class Hypothesis;
class SearchCubePruning : public Search
{
public:
@ -20,6 +24,8 @@ public:
const Hypothesis *GetBestHypothesis() const;
protected:
boost::unordered_map<const Bitmap*, std::vector<const Hypothesis*> > m_hyposPerBM;
};
#endif /* SEARCH_SEARCHCUBEPRUNING_H_ */

View File

@ -10,6 +10,7 @@
#include "SearchNormalBatch.h"
#include "Stack.h"
#include "Manager.h"
#include "Hypothesis.h"
#include "../InputPaths.h"
#include "../TargetPhrases.h"
#include "../TargetPhrase.h"
@ -39,6 +40,10 @@ void SearchNormalBatch::Decode(size_t stackInd)
Extend(*hypo);
}
std::sort(m_batchForEval->GetData(),
m_batchForEval->GetData() + m_batchForEval->size(),
HypothesisTargetPhraseOrderer());
// batch FF evaluation
const std::vector<const StatefulFeatureFunction*> &sfffs = m_mgr.system.featureFunctions.GetStatefulFeatureFunctions();
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {

View File

@ -54,3 +54,4 @@ protected:
};

View File

@ -45,6 +45,12 @@ bool Word::operator==(const Word &compare) const
return cmp == 0;
}
bool Word::operator<(const Word &compare) const
{
int cmp = memcmp(m_factors, compare.m_factors, sizeof(Factor *) * MAX_NUM_FACTORS);
return (cmp < 0);
}
std::ostream& operator<<(std::ostream &out, const Word &obj)
{
bool outputAlready = false;

View File

@ -22,6 +22,7 @@ public:
size_t hash() const;
bool operator==(const Word &compare) const;
bool operator<(const Word &compare) const;
const Factor* operator[](size_t ind) const {
return m_factors[ind];