2010-09-15 18:36:07 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
2010-09-15 19:38:46 +04:00
|
|
|
Copyright (C) 2010 University of Edinburgh
|
2010-09-15 18:36:07 +04:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
2010-09-15 19:38:46 +04:00
|
|
|
#ifndef _MIRA_DECODER_H_
|
|
|
|
#define _MIRA_DECODER_H_
|
2010-09-15 18:36:07 +04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
2010-09-17 14:17:27 +04:00
|
|
|
#include "BleuScoreFeature.h"
|
|
|
|
#include "ChartTrellisPathList.h"
|
2010-09-15 18:36:07 +04:00
|
|
|
#include "Hypothesis.h"
|
|
|
|
#include "Parameter.h"
|
|
|
|
#include "SearchNormal.h"
|
2010-09-17 14:17:27 +04:00
|
|
|
#include "Sentence.h"
|
2010-09-15 18:36:07 +04:00
|
|
|
#include "StaticData.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Wrapper functions and objects for the decoder.
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace Mira {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise moses (including StaticData) using the given ini file and debuglevel, passing through any
|
2010-09-17 14:17:27 +04:00
|
|
|
* other command line arguments.
|
2010-09-15 18:36:07 +04:00
|
|
|
**/
|
2011-02-24 13:54:16 +03:00
|
|
|
void initMoses(const std::string& inifile, int debuglevel, int argc, std::vector<std::string> decoder_params);
|
2010-09-15 18:36:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps moses decoder.
|
|
|
|
**/
|
2010-09-17 14:17:27 +04:00
|
|
|
class MosesDecoder {
|
2010-09-15 18:36:07 +04:00
|
|
|
public:
|
2010-12-10 19:34:43 +03:00
|
|
|
MosesDecoder(const std::vector<std::vector<std::string> >& refs, bool useScaledReference, bool scaleByInputLength, float BPfactor, float historySmoothing);
|
2010-09-16 20:23:52 +04:00
|
|
|
|
2010-09-17 19:17:33 +04:00
|
|
|
//returns the best sentence
|
|
|
|
std::vector<const Moses::Word*> getNBest(const std::string& source,
|
|
|
|
size_t sentenceid,
|
2010-09-17 14:17:27 +04:00
|
|
|
size_t count,
|
2010-09-17 18:32:27 +04:00
|
|
|
float bleuObjectiveweight, //weight of bleu in objective
|
|
|
|
float bleuScoreWeight, //weight of bleu in score
|
2010-11-24 20:06:54 +03:00
|
|
|
std::vector< Moses::ScoreComponentCollection>& featureValues,
|
|
|
|
std::vector< float>& scores,
|
2010-11-29 17:11:19 +03:00
|
|
|
bool oracle,
|
2010-12-14 17:51:04 +03:00
|
|
|
bool distinct,
|
2011-01-07 21:57:38 +03:00
|
|
|
size_t rank);
|
2011-04-08 14:59:41 +04:00
|
|
|
std::vector<float> getBleuAndScore(const std::string& source,
|
|
|
|
size_t sentenceid,
|
|
|
|
float bleuObjectiveWeight,
|
|
|
|
bool distinct);
|
2010-11-24 20:06:54 +03:00
|
|
|
size_t getCurrentInputLength();
|
2010-09-17 19:17:33 +04:00
|
|
|
void updateHistory(const std::vector<const Moses::Word*>& words);
|
2010-11-24 20:06:54 +03:00
|
|
|
void updateHistory(const std::vector< std::vector< const Moses::Word*> >& words, std::vector<size_t>& sourceLengths, std::vector<size_t>& ref_ids);
|
2011-03-17 14:25:01 +03:00
|
|
|
std::vector<float> calculateBleuOfCorpus(const std::vector< std::vector< const Moses::Word*> >& words, std::vector<size_t>& ref_ids, size_t epoch, size_t rank);
|
|
|
|
void setBPfactor(float factor);
|
2010-09-17 16:54:58 +04:00
|
|
|
Moses::ScoreComponentCollection getWeights();
|
|
|
|
void setWeights(const Moses::ScoreComponentCollection& weights);
|
|
|
|
void cleanup();
|
2010-09-16 20:23:52 +04:00
|
|
|
|
|
|
|
private:
|
2010-09-17 18:32:27 +04:00
|
|
|
float getBleuScore(const Moses::ScoreComponentCollection& scores);
|
|
|
|
void setBleuScore(Moses::ScoreComponentCollection& scores, float bleu);
|
2010-09-17 14:17:27 +04:00
|
|
|
Moses::Manager *m_manager;
|
2010-09-16 20:23:52 +04:00
|
|
|
Moses::Sentence *m_sentence;
|
2010-09-17 14:17:27 +04:00
|
|
|
Moses::BleuScoreFeature *m_bleuScoreFeature;
|
2010-09-16 20:23:52 +04:00
|
|
|
|
|
|
|
|
2010-09-15 18:36:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} //namespace
|
|
|
|
|
2010-09-15 19:38:46 +04:00
|
|
|
#endif
|