38 #ifndef RERANKER_CANDIDATE_SET_H_
39 #define RERANKER_CANDIDATE_SET_H_
51 using std::shared_ptr;
69 CandidateSet(
const string &key) : training_key_(key), compiled_(false) { }
94 size_t size()
const {
return candidates_.size(); }
102 return *(candidates_[idx]);
106 return *(candidates_[gold_index_]);
109 return *(candidates_[best_scoring_index_]);
115 return reference_string_token_count_;
123 return reference_string_token_count_;
134 candidates_.push_back(candidate);
164 bool clear_features =
false,
165 bool clear_symbolic_features =
true,
166 bool force =
false) {
167 if (!compiled_ || force) {
169 compiled_ |= (*it)->Compile(symbols, clear_features,
170 clear_symbolic_features, force);
198 bool clear_symbolic_features =
false,
199 bool clear_features =
true,
200 bool force =
false) {
201 if (compiled_ || force) {
203 (*it)->Decompile(symbols, clear_symbolic_features,
204 clear_features, force);
214 (*it)->set_raw_data(empty_string);
219 best_scoring_index_ = index;
243 <<
"\nwith " << set.
size() <<
" candidates:\n";
245 os <<
"\t" << *(*it) <<
"\n";
253 vector<shared_ptr<Candidate> > candidates_;
255 string training_key_;
259 size_t best_scoring_index_;
261 string reference_string_;
263 int reference_string_token_count_;
267 static string empty_string;
270 #define REGISTER_NAMED_CANDIDATE_SET_SCORER(TYPE,NAME) \
271 REGISTER_NAMED(TYPE,NAME,CandidateSet::Scorer)
273 #define REGISTER_CANDIDATE_SET_SCORER(TYPE) \
274 REGISTER_NAMED_CANDIDATE_SET_SCORER(TYPE,TYPE)
const string & reference_string() const
const Candidate & GetGold() const
Model is an interface for reranking models.
Provides the reranker::Candidate class for representing a candidate hypothesis from an initial model...
void set_reference_string(const string &reference_string)
friend ostream & operator<<(ostream &os, const CandidateSet &set)
const Candidate & GetBestScoring() const
bool CompileFeatures(Symbols *symbols, bool clear_features=false, bool clear_symbolic_features=true, bool force=false)
Compiles any symbolic features in this candidate set.
void ClearRawData()
Clears the raw data for all candidates in this set by setting each to be the empty string...
virtual void Score(Model *model, CandidateSet &candidates, bool training)=0
vector< shared_ptr< Candidate > >::iterator iterator
const string & training_key() const
void AddCandidate(shared_ptr< Candidate > candidate)
void DecompileFeatures(Symbols *symbols, bool clear_symbolic_features=false, bool clear_features=true, bool force=false)
Decompiles any non-symbolic features in the candidates in this candidate set.
An inner interface for a model to score a CandidateSet.
double loss_weight() const
Returns the weight of the loss for this candidate set’s reference.
void set_training_key(const string &training_key)
void set_gold_index(size_t index)
A class to hold a set of candidates, either for training or test.
An interface specifying a converter from symbols (strings) to int indices.
A class to represent a candidate in a set of candidates that constitutes a training instance for a re...
CandidateSet()
Constructs a new candidate set with no information set.
void set_reference_string_token_count(int reference_string_token_count)
bool compiled() const
Returns whether any symbolic features in any of the candidates in this candidate set were compiled by...
vector< shared_ptr< Candidate > >::const_iterator const_iterator
size_t best_scoring_index() const
Candidate & Get(size_t idx)
const_iterator begin() const
An interface to make it easier to implement Factory-constructible types by implementing both required...
int reference_string_token_count() const
void set_best_scoring_index(size_t index)
const_iterator end() const
Provides a generic dynamic object factory.
virtual ~CandidateSet()
Destroys this instance.
CandidateSet(const string &key)
Constructs a candidate set with the specified key.
size_t gold_index() const