35 #ifndef RERANKER_MIRA_STYLE_MODEL_H_
36 #define RERANKER_MIRA_STYLE_MODEL_H_
46 #define DEFAULT_MIRA_CLIP 0.1
67 return score_diff == 0.0 ? 0 : (score_diff < 0.0 ? -1 : 1);
114 initializers.
Add(
"mira_clip", &mira_clip_);
126 const unordered_set<int> &gold_features,
127 const unordered_set<int> &best_scoring_features,
140 double raw_step = (loss_diff + score_diff) / vector_diff.
Dot(vector_diff);
141 step_size_ = raw_step > mira_clip_ ? mira_clip_ : raw_step;
Provides the reranker::PerceptronModel reranker class.
const Candidate & GetGold() const
Model is an interface for reranking models.
const string & name() const
Returns the unique name for this model instance.
virtual void RegisterInitializers(Initializers &initializers)
Registers one additional variable that may be initialized when this object is constructed via Factory...
double score() const
Returns the reranker’s score for this candidate.
const Candidate & GetBestScoring() const
Provides the reranker::Symbols interface as well as the reranker::StaticSymbolTable implementation...
Symbols * symbols() const
Returns the symbol table for this model.
MiraStyleModel(const string &name, KernelFunction *kernel_fn)
virtual void RegisterInitializers(Initializers &initializers)
Registers several variables that may be initialized when this object is constructed via Factory::Crea...
void set_mira_clip(double mira_clip)
Sets the maximum value for a step size computed by ComputeStepSize.
This class implements a perceptron model reranker.
An inner interface specifying comparison between two Candidate instances.
virtual int Compare(const Model &model, const Candidate &c1, const Candidate &c2)
Returns 0 if the two candidates’ scores are equal, less than zero if the score of c1 is less than tha...
virtual double ComputeStepSize(const unordered_set< int > &gold_features, const unordered_set< int > &best_scoring_features, const CandidateSet &example)
Computes the step size for the next update, and, as a side effect, caches this value in step_size_...
double loss_weight() const
Returns the weight of the loss for this candidate set’s reference.
void Add(const string &name, T *member, bool required=false)
A class to do “direct loss minimization” by considering the score of a candidate to be its raw score ...
#define DEFAULT_MIRA_CLIP
FeatureVector< K, V > & AddScaledSubvector(const Collection &feature_uids, const FeatureVector< K, V > &feature_vector, V scalar)
Modifies this vector so that it equals this vector plus the scaled specified subvector.
A class to hold a set of candidates, either for training or test.
An interface specifying a converter from symbols (strings) to int indices.
virtual bool use_weighted_loss()
A class to represent a candidate in a set of candidates that constitutes a training instance for a re...
double loss() const
Returns the loss of this candidate.
double step_size_
The last value computed by the ComputeStepSize method.
V Dot(const FeatureVector< K, V > &other) const
Computes the dot product of this feature vector with the specified FeatureVector. ...
Provides the reranker::KernelFunction interface.
A subclass of PerceptronModel that differs only in the way that the ComputeStepSize method is impleme...
An interface specifying a kernel function for two FeatureVector instances.
MiraStyleModel(const string &name, KernelFunction *kernel_fn, Symbols *symbols)
A container for all the member initializers for a particular Factory-constructible instance...
MiraStyleModel(const string &name)
const FeatureVector< int, double > & features() const
Returns the feature vector for this candidate.