|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <vector> |
|
|
|
#include <boost/scoped_ptr.hpp> |
|
#include <boost/shared_ptr.hpp> |
|
|
|
#include "ForestRescore.h" |
|
#include "Hypergraph.h" |
|
#include "HypPackEnumerator.h" |
|
#include "MiraFeatureVector.h" |
|
#include "MiraWeightVector.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace MosesTuning |
|
{ |
|
|
|
|
|
|
|
std::pair<MiraWeightVector*,size_t> |
|
InitialiseWeights(const std::string& denseInitFile, const std::string& sparseInitFile, |
|
const std::string& type, bool verbose); |
|
|
|
class Scorer; |
|
|
|
|
|
struct HopeFearData { |
|
MiraFeatureVector modelFeatures; |
|
MiraFeatureVector hopeFeatures; |
|
MiraFeatureVector fearFeatures; |
|
|
|
std::vector<float> modelStats; |
|
std::vector<float> hopeStats; |
|
|
|
ValType hopeBleu; |
|
ValType fearBleu; |
|
|
|
bool hopeFearEqual; |
|
}; |
|
|
|
|
|
class HopeFearDecoder |
|
{ |
|
public: |
|
|
|
virtual void reset() = 0; |
|
virtual void next() = 0; |
|
virtual bool finished() = 0; |
|
|
|
virtual ~HopeFearDecoder() {}; |
|
|
|
|
|
|
|
|
|
virtual void HopeFear( |
|
const std::vector<ValType>& backgroundBleu, |
|
const MiraWeightVector& wv, |
|
HopeFearData* hopeFear |
|
) = 0; |
|
|
|
|
|
virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats) |
|
= 0; |
|
|
|
|
|
ValType Evaluate(const AvgWeightVector& wv); |
|
|
|
protected: |
|
Scorer* scorer_; |
|
}; |
|
|
|
|
|
|
|
class NbestHopeFearDecoder : public virtual HopeFearDecoder |
|
{ |
|
public: |
|
NbestHopeFearDecoder(const std::vector<std::string>& featureFiles, |
|
const std::vector<std::string>& scoreFiles, |
|
bool streaming, |
|
bool no_shuffle, |
|
bool safe_hope, |
|
Scorer* scorer |
|
); |
|
|
|
virtual void reset(); |
|
virtual void next(); |
|
virtual bool finished(); |
|
|
|
virtual void HopeFear( |
|
const std::vector<ValType>& backgroundBleu, |
|
const MiraWeightVector& wv, |
|
HopeFearData* hopeFear |
|
); |
|
|
|
virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats); |
|
|
|
private: |
|
boost::scoped_ptr<HypPackEnumerator> train_; |
|
bool safe_hope_; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class HypergraphHopeFearDecoder : public virtual HopeFearDecoder |
|
{ |
|
public: |
|
HypergraphHopeFearDecoder( |
|
const std::string& hypergraphDir, |
|
const std::vector<std::string>& referenceFiles, |
|
size_t num_dense, |
|
bool streaming, |
|
bool no_shuffle, |
|
bool safe_hope, |
|
size_t hg_pruning, |
|
const MiraWeightVector& wv, |
|
Scorer* scorer_ |
|
); |
|
|
|
virtual void reset(); |
|
virtual void next(); |
|
virtual bool finished(); |
|
|
|
virtual void HopeFear( |
|
const std::vector<ValType>& backgroundBleu, |
|
const MiraWeightVector& wv, |
|
HopeFearData* hopeFear |
|
); |
|
|
|
virtual void MaxModel(const AvgWeightVector& wv, std::vector<ValType>* stats); |
|
|
|
private: |
|
size_t num_dense_; |
|
|
|
typedef std::map<size_t, boost::shared_ptr<Graph> > GraphColl; |
|
GraphColl graphs_; |
|
std::vector<size_t> sentenceIds_; |
|
std::vector<size_t>::const_iterator sentenceIdIter_; |
|
ReferenceSet references_; |
|
Vocab vocab_; |
|
}; |
|
|
|
}; |
|
|
|
|