mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
batch evaluate
This commit is contained in:
parent
f6e8e3aee0
commit
510c60b222
@ -13,6 +13,8 @@
|
||||
#include "StatefulFeatureFunction.h"
|
||||
#include "../PhraseBased/Hypothesis.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
@ -30,6 +32,7 @@ StatefulFeatureFunction::~StatefulFeatureFunction()
|
||||
void StatefulFeatureFunction::EvaluateWhenAppliedBatch(
|
||||
const std::vector<Hypothesis*> &batch) const
|
||||
{
|
||||
//cerr << "EvaluateWhenAppliedBatch:" << m_name << endl;
|
||||
#ifdef __linux
|
||||
/*
|
||||
pthread_t handle;
|
||||
|
@ -4,8 +4,16 @@
|
||||
* Created on: 4 Nov 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
#include <boost/foreach.hpp>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "KENLMBatch.h"
|
||||
#include "../Phrase.h"
|
||||
#include "../Scores.h"
|
||||
@ -79,7 +87,9 @@ private:
|
||||
/////////////////////////////////////////////////////////////////
|
||||
KENLMBatch::KENLMBatch(size_t startInd, const std::string &line)
|
||||
:StatefulFeatureFunction(startInd, line)
|
||||
,m_numHypos(0)
|
||||
{
|
||||
cerr << "KENLMBatch::KENLMBatch" << endl;
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
@ -90,6 +100,7 @@ KENLMBatch::~KENLMBatch()
|
||||
|
||||
void KENLMBatch::Load(System &system)
|
||||
{
|
||||
cerr << "KENLMBatch::Load" << endl;
|
||||
FactorCollection &fc = system.GetVocab();
|
||||
|
||||
m_bos = fc.AddFactor(BOS_, system, false);
|
||||
@ -331,6 +342,41 @@ void KENLMBatch::SetParameter(const std::string& key,
|
||||
//cerr << "SetParameter done" << endl;
|
||||
}
|
||||
|
||||
void KENLMBatch::EvaluateWhenAppliedBatch(
|
||||
const std::vector<Hypothesis*> &batch) const
|
||||
{
|
||||
{
|
||||
// write lock
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
|
||||
m_batches.push_back(&batch);
|
||||
m_numHypos += batch.size();
|
||||
}
|
||||
//cerr << "m_numHypos=" << m_numHypos << endl;
|
||||
|
||||
if (m_numHypos > 0) {
|
||||
// process batch
|
||||
EvaluateWhenAppliedBatch();
|
||||
|
||||
m_batches.clear();
|
||||
m_numHypos = 0;
|
||||
|
||||
m_threadNeeded.notify_all();
|
||||
}
|
||||
else {
|
||||
boost::mutex::scoped_lock lock(m_mutex);
|
||||
m_threadNeeded.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
void KENLMBatch::EvaluateWhenAppliedBatch() const
|
||||
{
|
||||
BOOST_FOREACH(const Batch *batch, m_batches) {
|
||||
//cerr << "batch=" << batch->size() << endl;
|
||||
BOOST_FOREACH(Hypothesis *hypo, *batch) {
|
||||
hypo->EvaluateWhenApplied(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../FF/StatefulFeatureFunction.h"
|
||||
#include "lm/model.hh"
|
||||
#include "../legacy/Factor.h"
|
||||
@ -50,6 +54,9 @@ public:
|
||||
const Hypothesis &hypo, const FFState &prevState, Scores &scores,
|
||||
FFState &state) const;
|
||||
|
||||
virtual void EvaluateWhenAppliedBatch(
|
||||
const std::vector<Hypothesis*> &batch) const;
|
||||
|
||||
protected:
|
||||
std::string m_path;
|
||||
FactorType m_factorType;
|
||||
@ -73,6 +80,18 @@ protected:
|
||||
|
||||
std::vector<lm::WordIndex> m_lmIdLookup;
|
||||
|
||||
// batch
|
||||
typedef std::vector<Hypothesis*> Batch;
|
||||
mutable std::vector<const Batch*> m_batches;
|
||||
mutable size_t m_numHypos;
|
||||
|
||||
mutable boost::shared_mutex m_accessLock;
|
||||
|
||||
mutable boost::mutex m_mutex;
|
||||
mutable boost::condition_variable m_threadNeeded;
|
||||
|
||||
void EvaluateWhenAppliedBatch() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -119,6 +119,7 @@ void System::IsPb()
|
||||
{
|
||||
switch (options.search.algo) {
|
||||
case Normal:
|
||||
case NormalBatch:
|
||||
case CubePruning:
|
||||
case CubePruningPerMiniStack:
|
||||
case CubePruningPerBitmap:
|
||||
|
Loading…
Reference in New Issue
Block a user