00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #pragma once
00020
00021 #include <vector>
00022
00023 #include <boost/scoped_ptr.hpp>
00024 #include <boost/shared_ptr.hpp>
00025
00026 #include "ForestRescore.h"
00027 #include "Hypergraph.h"
00028 #include "HypPackEnumerator.h"
00029 #include "MiraFeatureVector.h"
00030 #include "MiraWeightVector.h"
00031
00032
00033
00034
00035
00036
00037 namespace MosesTuning
00038 {
00039
00040
00042 std::pair<MiraWeightVector*,size_t>
00043 InitialiseWeights(const std::string& denseInitFile, const std::string& sparseInitFile,
00044 const std::string& type, bool verbose);
00045
00046 class Scorer;
00047
00049 struct HopeFearData {
00050 MiraFeatureVector modelFeatures;
00051 MiraFeatureVector hopeFeatures;
00052 MiraFeatureVector fearFeatures;
00053
00054 std::vector<float> modelStats;
00055 std::vector<float> hopeStats;
00056
00057 ValType hopeBleu;
00058 ValType fearBleu;
00059
00060 bool hopeFearEqual;
00061 };
00062
00063
00064 class HopeFearDecoder
00065 {
00066 public:
00067
00068 virtual void reset() = 0;
00069 virtual void next() = 0;
00070 virtual bool finished() = 0;
00071
00072 virtual ~HopeFearDecoder() {};
00073
00077 virtual void HopeFear(
00078 const std::vector<ValType>& backgroundBleu,
00079 const MiraWeightVector& wv,
00080 HopeFearData* hopeFear
00081 ) = 0;
00082
00084 virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats)
00085 = 0;
00086
00088 ValType Evaluate(const AvgWeightVector& wv);
00089
00090 protected:
00091 Scorer* scorer_;
00092 };
00093
00094
00096 class NbestHopeFearDecoder : public virtual HopeFearDecoder
00097 {
00098 public:
00099 NbestHopeFearDecoder(const std::vector<std::string>& featureFiles,
00100 const std::vector<std::string>& scoreFiles,
00101 bool streaming,
00102 bool no_shuffle,
00103 bool safe_hope,
00104 Scorer* scorer
00105 );
00106
00107 virtual void reset();
00108 virtual void next();
00109 virtual bool finished();
00110
00111 virtual void HopeFear(
00112 const std::vector<ValType>& backgroundBleu,
00113 const MiraWeightVector& wv,
00114 HopeFearData* hopeFear
00115 );
00116
00117 virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats);
00118
00119 private:
00120 boost::scoped_ptr<HypPackEnumerator> train_;
00121 bool safe_hope_;
00122
00123 };
00124
00125
00126
00128 class HypergraphHopeFearDecoder : public virtual HopeFearDecoder
00129 {
00130 public:
00131 HypergraphHopeFearDecoder(
00132 const std::string& hypergraphDir,
00133 const std::vector<std::string>& referenceFiles,
00134 size_t num_dense,
00135 bool streaming,
00136 bool no_shuffle,
00137 bool safe_hope,
00138 size_t hg_pruning,
00139 const MiraWeightVector& wv,
00140 Scorer* scorer_
00141 );
00142
00143 virtual void reset();
00144 virtual void next();
00145 virtual bool finished();
00146
00147 virtual void HopeFear(
00148 const std::vector<ValType>& backgroundBleu,
00149 const MiraWeightVector& wv,
00150 HopeFearData* hopeFear
00151 );
00152
00153 virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats);
00154
00155 private:
00156 size_t num_dense_;
00157
00158 typedef std::map<size_t, boost::shared_ptr<Graph> > GraphColl;
00159 GraphColl graphs_;
00160 std::vector<size_t> sentenceIds_;
00161 std::vector<size_t>::const_iterator sentenceIdIter_;
00162 ReferenceSet references_;
00163 Vocab vocab_;
00164 };
00165
00166 };
00167