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 {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps moses decoder.
|
|
|
|
**/
|
2010-09-17 14:17:27 +04:00
|
|
|
class MosesDecoder {
|
2010-09-15 18:36:07 +04:00
|
|
|
public:
|
2011-11-16 13:13:17 +04:00
|
|
|
/**
|
|
|
|
* Initialise moses (including StaticData) using the given ini file and debuglevel, passing through any
|
|
|
|
* other command line arguments.
|
|
|
|
**/
|
|
|
|
MosesDecoder(const std::string& inifile, int debuglevel, int argc, std::vector<std::string> decoder_params);
|
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-06-26 23:12:46 +04:00
|
|
|
size_t rank,
|
|
|
|
size_t epoch);
|
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);
|
2011-04-13 16:22:02 +04:00
|
|
|
void updateHistory(const std::vector< std::vector< const Moses::Word*> >& words, std::vector<size_t>& sourceLengths, std::vector<size_t>& ref_ids, size_t rank, size_t epoch);
|
2012-01-12 20:26:16 +04:00
|
|
|
// void loadReferenceSentences(const std::vector<std::vector<std::string> >& refs);
|
2011-04-26 23:35:06 +04:00
|
|
|
void printBleuFeatureHistory(std::ostream& out);
|
2012-01-16 15:22:58 +04:00
|
|
|
// void printReferenceLength(const std::vector<size_t>& ref_ids);
|
|
|
|
size_t getClosestReferenceLength(size_t ref_id, int hypoLength);
|
2011-11-25 19:54:32 +04:00
|
|
|
void setBleuParameters(bool scaleByInputLength, bool scaleByRefLength, bool scaleByAvgLength,
|
|
|
|
bool scaleByTargetLengthLinear, bool scaleByTargetLengthTrend,
|
2011-11-16 22:06:14 +04:00
|
|
|
float scaleByX, float historySmoothing, size_t scheme, float relax_BP);
|
2010-09-17 16:54:58 +04:00
|
|
|
Moses::ScoreComponentCollection getWeights();
|
|
|
|
void setWeights(const Moses::ScoreComponentCollection& weights);
|
2012-01-23 19:15:27 +04:00
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void setCorrection(float correction) {
|
|
|
|
m_bleuScoreFeature->SetCorrection(correction);
|
|
|
|
}
|
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);
|
2011-06-26 23:12:46 +04:00
|
|
|
Moses::Manager *m_manager;
|
|
|
|
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
|