00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _MIRA_DECODER_H_
00020 #define _MIRA_DECODER_H_
00021
00022 #include <iostream>
00023 #include <cstring>
00024 #include <sstream>
00025
00026
00027 #include "moses/ChartTrellisPathList.h"
00028 #include "moses/Hypothesis.h"
00029 #include "moses/Parameter.h"
00030 #include "moses/SearchNormal.h"
00031 #include "moses/Sentence.h"
00032 #include "moses/StaticData.h"
00033 #include "moses/FF/BleuScoreFeature.h"
00034
00035
00036
00037
00038
00039 namespace Mira
00040 {
00041
00045 class MosesDecoder
00046 {
00047 public:
00052 MosesDecoder(const std::string& inifile, int debuglevel, int argc, std::vector<std::string> decoder_params);
00053
00054
00055 std::vector< std::vector<const Moses::Word*> > getNBest(const std::string& source,
00056 size_t sentenceid,
00057 size_t nbestSize,
00058 float bleuObjectiveweight,
00059 float bleuScoreWeight,
00060 std::vector< Moses::ScoreComponentCollection>& featureValues,
00061 std::vector< float>& bleuScores,
00062 std::vector< float>& modelScores,
00063 size_t numReturnedTranslations,
00064 bool realBleu,
00065 bool distinct,
00066 bool avgRefLength,
00067 size_t rank,
00068 size_t epoch,
00069 std::string filename);
00070 std::vector< std::vector<const Moses::Word*> > runDecoder(const std::string& source,
00071 size_t sentenceid,
00072 size_t nbestSize,
00073 float bleuObjectiveweight,
00074 float bleuScoreWeight,
00075 std::vector< Moses::ScoreComponentCollection>& featureValues,
00076 std::vector< float>& bleuScores,
00077 std::vector< float>& modelScores,
00078 size_t numReturnedTranslations,
00079 bool realBleu,
00080 bool distinct,
00081 size_t rank,
00082 size_t epoch,
00083 Moses::SearchAlgorithm& seach,
00084 std::string filename);
00085 std::vector< std::vector<const Moses::Word*> > runChartDecoder(const std::string& source,
00086 size_t sentenceid,
00087 size_t nbestSize,
00088 float bleuObjectiveweight,
00089 float bleuScoreWeight,
00090 std::vector< Moses::ScoreComponentCollection>& featureValues,
00091 std::vector< float>& bleuScores,
00092 std::vector< float>& modelScores,
00093 size_t numReturnedTranslations,
00094 bool realBleu,
00095 bool distinct,
00096 size_t rank,
00097 size_t epoch);
00098 void outputNBestList(const std::string& source,
00099 size_t sentenceid,
00100 size_t nBestSize,
00101 float bleuObjectiveWeight,
00102 float bleuScoreWeight,
00103 bool distinctNbest,
00104 bool avgRefLength,
00105 std::string filename,
00106 std::ofstream& streamOut);
00107 void initialize(Moses::StaticData& staticData, const std::string& source, size_t sentenceid,
00108 float bleuObjectiveWeight, float bleuScoreWeight, bool avgRefLength, bool chartDecoding);
00109 void updateHistory(const std::vector<const Moses::Word*>& words);
00110 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);
00111 void printBleuFeatureHistory(std::ostream& out);
00112 void printReferenceLength(const std::vector<size_t>& ref_ids);
00113 size_t getReferenceLength(size_t ref_id);
00114 size_t getClosestReferenceLength(size_t ref_id, int hypoLength);
00115 size_t getShortestReferenceIndex(size_t ref_id);
00116 void setBleuParameters(bool disable, bool sentenceBleu, bool scaleByInputLength, bool scaleByAvgInputLength,
00117 bool scaleByInverseLength, bool scaleByAvgInverseLength,
00118 float scaleByX, float historySmoothing, size_t scheme, bool simpleHistoryBleu);
00119 void setAvgInputLength (float l) {
00120 m_bleuScoreFeature->SetAvgInputLength(l);
00121 }
00122 Moses::ScoreComponentCollection getWeights();
00123 void setWeights(const Moses::ScoreComponentCollection& weights);
00124 void cleanup(bool chartDecoding);
00125
00126 float getSourceLengthHistory() {
00127 return m_bleuScoreFeature->GetSourceLengthHistory();
00128 }
00129 float getTargetLengthHistory() {
00130 return m_bleuScoreFeature->GetTargetLengthHistory();
00131 }
00132 float getAverageInputLength() {
00133 return m_bleuScoreFeature->GetAverageInputLength();
00134 }
00135
00136 private:
00137 float getBleuScore(const Moses::ScoreComponentCollection& scores);
00138 void setBleuScore(Moses::ScoreComponentCollection& scores, float bleu);
00139 Moses::Manager *m_manager;
00140 Moses::ChartManager *m_chartManager;
00141 Moses::Sentence *m_sentence;
00142 Moses::BleuScoreFeature *m_bleuScoreFeature;
00143 };
00144
00145
00146 }
00147
00148 #endif