Merge branch 'master' of github.com:moses-smt/mosesdecoder

This commit is contained in:
Hieu Hoang 2017-03-06 12:29:53 +00:00
commit e983e33180
4 changed files with 34 additions and 16 deletions

View File

@ -51,12 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "hypergraph.pb.h"
#endif
#ifdef PT_UG
#include <boost/foreach.hpp>
#include "moses/TranslationModel/UG/mmsapt.h"
#include "moses/TranslationModel/UG/generic/program_options/ug_splice_arglist.h"
#endif
using namespace std;
using namespace Moses;
@ -76,6 +70,9 @@ void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream)
/** main function of the command line version of the decoder **/
int main(int argc, char const** argv)
{
//setting in the Staticdata a link between the thread id of this process and a NULL tasksptr
// StaticData::InstanceNonConst().SetTask(); // => moved into StaticData constructor
try {
#ifdef HAVE_PROTOBUF
@ -141,11 +138,13 @@ int main(int argc, char const** argv)
}
#ifdef WITH_THREADS
#pragma message ("Compiling with Threads.")
ThreadPool pool(staticData.ThreadCount());
#endif
// main loop over set of input sentences
boost::shared_ptr<ContextScope> scope(new ContextScope);
boost::shared_ptr<InputType> source;
while ((source = ioWrapper->ReadInput()) != NULL) {
IFVERBOSE(1) {
@ -154,7 +153,7 @@ int main(int argc, char const** argv)
// set up task of training one sentence
boost::shared_ptr<TrainingTask> task;
task = TrainingTask::create(source, ioWrapper);
task = TrainingTask::create(source, ioWrapper, scope);
// execute task
#ifdef WITH_THREADS

View File

@ -39,6 +39,18 @@ public:
boost::shared_ptr<IOWrapper> const& ioWrapper) {
boost::shared_ptr<TrainingTask> ret(new TrainingTask(source, ioWrapper));
ret->m_self = ret;
ret->m_scope.reset(new ContextScope);
return ret;
}
// factory function
static boost::shared_ptr<TrainingTask>
create(boost::shared_ptr<InputType> const& source,
boost::shared_ptr<IOWrapper> const& ioWrapper,
boost::shared_ptr<ContextScope> const& scope) {
boost::shared_ptr<TrainingTask> ret(new TrainingTask(source, ioWrapper));
ret->m_self = ret;
ret->m_scope = scope;
return ret;
}

View File

@ -64,22 +64,29 @@ class BleuScore:
self.lower = None
self.upper = None
self.median = None
self.bootstrap = [
self.score([randint(0, len(hyp.snt) - 1) for s in hyp.snt])
for i in xrange(1000)]
self.bootstrap.sort()
self.actual = self.score([i for i in xrange(len(hyp.snt))])
if bootstrap:
self.bootstrap = [self.score([randint(0, len(hyp.snt) - 1)
for s in hyp.snt])
for i in xrange(bootstrap)]
self.bootstrap.sort()
else:
self.bootstrap = [self.actual]
pass
def score(self, sample):
hits = [0 for i in xrange(self.max_n)]
self.hyplen = 0
self.reflen = 0
self.total = [0 for i in hits]
for i in sample:
self.hyplen += len(self.hyp.snt[i])
self.reflen += len(self.ref.snt[i])
for n in xrange(self.max_n):
hits[n] += self.hits[i][n]
self.prec = [float(hits[n]) / (self.hyplen - n * len(sample))
self.total[n] += max(len(self.hyp.snt[i]) - n, 0)
pass
self.prec = [float(hits[n]) / self.total[n]
for n in xrange(self.max_n)]
ret = sum([math.log(x) for x in self.prec]) / self.max_n
self.BP = min(

View File

@ -6,11 +6,11 @@ boost 103600 ;
# VW
local with-vw = [ option.get "with-vw" ] ;
if $(with-vw) {
lib vw : : <search>$(with-vw)/lib ;
lib allreduce : : <search>$(with-vw)/lib ;
lib vw : : <search>$(with-vw)/vowpalwabbit ;
lib allreduce : : <search>$(with-vw)/vowpalwabbit ;
obj ClassifierFactory.o : ClassifierFactory.cpp headers : <include>$(with-vw)/include/vowpalwabbit ;
obj VWPredictor.o : VWPredictor.cpp headers : <include>$(with-vw)/include/vowpalwabbit ;
obj ClassifierFactory.o : ClassifierFactory.cpp headers : <include>$(with-vw)/vowpalwabbit ;
obj VWPredictor.o : VWPredictor.cpp headers : <include>$(with-vw)/vowpalwabbit ;
alias vw_objects : VWPredictor.o ClassifierFactory.o vw allreduce : : : <library>boost_program_options ;
lib classifier : [ glob *.cpp : VWPredictor.cpp ClassifierFactory.cpp ] vw_objects headers ;