37 #ifndef RERANKER_CANDIDATE_H_
38 #define RERANKER_CANDIDATE_H_
44 #include "../proto/data.pb.h"
76 index_(index), num_errors_(0), num_correct_(0),
77 loss_(loss), score_(0.0), baseline_score_(baseline_score),
78 num_words_(num_words), raw_data_(raw_data), compiled_(false) {
97 index_(index), num_errors_(0), num_correct_(0),
98 loss_(loss), score_(0.0), baseline_score_(baseline_score),
99 num_words_(num_words), features_(features),
100 symbolic_features_(symbolic_features), raw_data_(raw_data),
121 int index()
const {
return index_; }
129 double loss()
const {
return loss_; }
131 double score()
const {
return score_; }
140 return symbolic_features_;
143 const string &
raw_data()
const {
return raw_data_; }
190 bool clear_features =
false,
191 bool clear_symbolic_features =
true,
210 bool clear_symbolic_features =
false,
211 bool clear_features =
true,
221 os <<
"{index:" << c.
index() <<
"; loss:" << c.
loss()
225 <<
"; raw_data:\"" << c.
raw_data() <<
"\""
226 <<
"; compiled: " << (c.
compiled() ?
"true" :
"false")
233 std::ostringstream oss;
241 FeatureVector<string,double> &mutable_symbolic_features() {
242 return symbolic_features_;
267 double baseline_score_;
272 FeatureVector<int,double> features_;
274 FeatureVector<string,double> symbolic_features_;
281 #define REGISTER_NAMED_CANDIDATE_COMPARATOR(TYPE,NAME) \
282 REGISTER_NAMED(TYPE,NAME,Candidate::Comparator)
284 #define REGISTER_CANDIDATE_COMPARATOR(TYPE) \
285 REGISTER_NAMED_CANDIDATE_COMPARATOR(TYPE,TYPE)
Model is an interface for reranking models.
double score() const
Returns the reranker’s score for this candidate.
Provides the reranker::Symbols interface as well as the reranker::StaticSymbolTable implementation...
bool Compile(Symbols *symbols, bool clear_features=false, bool clear_symbolic_features=true, bool force=false)
Compiles any symbolic features in this candidate.
bool compiled() const
Returns whether this candidate’s symbolic features have been compiled.
const string & raw_data() const
Returns the raw data (typically the sentence) for this candidate.
void Decompile(Symbols *symbols, bool clear_symbolic_features=false, bool clear_features=true, bool force=false)
Decompiles any non-symbolic features in this candidate.
const FeatureVector< string, double > & symbolic_features() const
Returns the symbolic feature vector for this candidate.
void set_loss(double loss)
Sets the loss of this candidate.
double baseline_score() const
Returns the baseline model score for this candidate.
void set_baseline_score(double baseline_score)
Sets the score of this candidate.
An inner interface specifying comparison between two Candidate instances.
string to_string()
Returns a the string that would be output by operator<<.
int index() const
Returns the index of this candidate relative to the other candidates.
friend ostream & operator<<(ostream &os, const Candidate &c)
Outputs a human-readable string version of this Candidate instance to the specified ostream...
int num_words() const
Returns the number of words in this candidate.
int num_errors() const
Returns the number of word errors of this candidate relative to a reference string.
An interface specifying a converter from symbols (strings) to int indices.
Candidate(int index, double loss, double baseline_score, int num_words, const string &raw_data)
Constructor for a candidate without features.
A class to represent a candidate in a set of candidates that constitutes a training instance for a re...
void set_score(double score)
Sets the score of this candidate.
virtual ~Candidate()
Destroys this candidate.
double loss() const
Returns the loss of this candidate.
Defines the reranker::FeatureVector class, which, as it happens, is used to store feature vectors...
void set_raw_data(const string &raw_data)
Sets the raw data (typically the sentence) for this candidate).
An interface to make it easier to implement Factory-constructible types by implementing both required...
Candidate(int index, double loss, double baseline_score, int num_words, const string &raw_data, const FeatureVector< int, double > &features, const FeatureVector< string, double > &symbolic_features)
Constructor for a candidate with "compiled" features.
Provides a generic dynamic object factory.
int num_correct() const
Returns the number of correct words of this candidate relative to a reference string.
virtual int Compare(const Model &model, const Candidate &c1, const Candidate &c2)=0
Compares the two specified Candidate instances.
const FeatureVector< int, double > & features() const
Returns the feature vector for this candidate.