Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
|
A subclass of PerceptronModel that differs only in the way that the ComputeStepSize method is implemented. More...
#include <mira-style-model.H>
Public Member Functions | |
MiraStyleModel () | |
MiraStyleModel (const string &name) | |
MiraStyleModel (const string &name, KernelFunction *kernel_fn) | |
MiraStyleModel (const string &name, KernelFunction *kernel_fn, Symbols *symbols) | |
virtual void | RegisterInitializers (Initializers &initializers) |
Registers one additional variable that may be initialized when this object is constructed via Factory::CreateOrDie. More... | |
void | set_mira_clip (double mira_clip) |
Sets the maximum value for a step size computed by ComputeStepSize. More... | |
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_. More... | |
Public Member Functions inherited from reranker::PerceptronModel | |
PerceptronModel () | |
Constructs a new instance with the empty string for its name and the DotProduct kernel function. More... | |
PerceptronModel (const string &name) | |
Constructs a new perceptron model with a DotProduct kernel function. More... | |
PerceptronModel (const string &name, KernelFunction *kernel_fn) | |
Constructs a new perceptron model with the specified kernel function. More... | |
PerceptronModel (const string &name, KernelFunction *kernel_fn, Symbols *symbols) | |
Constructs a new perceptron model with the specified kernel function and symbol table. More... | |
virtual | ~PerceptronModel () |
Destroys this perceptron model and all its data members. More... | |
virtual const string & | model_spec () const |
Returns the spec string for constructing a default instance of this model so it may be properly de-serialized by its ModelProtoReader. More... | |
virtual const string & | proto_reader_spec () const |
Returns the spec string for contructing an instance of a ModelProtoReader capable of de-serializing this Model implementation. More... | |
virtual const string & | proto_writer_spec () const |
Returns the spec string for contructing an instance of a ModelProtoWriter capable of serializing this Model implementation. More... | |
virtual int | best_model_epoch () const |
Returns the epoch of the best models seen so far during training. More... | |
virtual void | Init (const Environment *env, const string &arg) |
Initializes this instance. More... | |
virtual bool | NeedToKeepTraining () |
Returns whether more training epochs are required for this model. More... | |
virtual void | Train (CandidateSetIterator &examples, CandidateSetIterator &development_test) |
Trains this model on a collection of training examples, where each training example is a set of candidates. More... | |
virtual void | NewEpoch () |
virtual void | EndOfEpoch () |
virtual void | TrainOneEpoch (CandidateSetIterator &examples) |
Trains this model for one epoch, i.e., a single pass through the specified set of training examples. More... | |
virtual void | TrainOnExample (CandidateSet &example) |
Trains this model on the specified training example. More... | |
virtual bool | NeedToUpdate (CandidateSet &example) |
Indicates whether the current model needs to be updated; the implementation here simply returns true if the best-scoring candidate is not equal to the gold or reference candidate. More... | |
virtual void | Update (CandidateSet &example) |
Updates the current model based on the specified set of candidates. More... | |
virtual double | Evaluate (CandidateSetIterator &development_test) |
Evaluates this model on the specified set of held-out development test data. More... | |
virtual void | ScoreCandidates (CandidateSet &candidates, bool training) |
Scores the specified set of candidates according to either the raw or averaged version of this perceptron model, keeping track of which candidate has the highest score and which candidate has the lowest loss with the best score. More... | |
virtual double | ScoreCandidate (Candidate &candidate, bool training) |
Scores a candidate according to either the raw or averaged version of this perceptron model. More... | |
virtual void | CompactifyFeatureUids () |
Renumbers the potentially sparse feature uid’s so that they occupy the interval [0,n-1] densely, for n non-zero features in use by this model. More... | |
void | set_max_epochs_in_decline (int max_epochs_in_decline) |
Sets the maximum number of training epochs to keep training after the model starts to degrade (i.e., has more errors than the best model so far). More... | |
virtual const TrainingVectorSet & | models () const |
Returns the set of models and statistics used by this PerceptronModel instance. More... | |
Public Member Functions inherited from reranker::Model | |
Model () | |
Constructs a new instance with the empty string for its name and a NULL kernel function. More... | |
Model (const string &name) | |
Constructs a new instance with a NULL kernel function. More... | |
Model (const string &name, KernelFunction *kernel_fn) | |
Constructs a new instance with the specified kernel function. More... | |
Model (const string &name, KernelFunction *kernel_fn, Symbols *symbols) | |
Constructs a new instance with the specified kernel function and symbol table. More... | |
virtual | ~Model () |
Destroys this model and its associated kernel function. More... | |
const string & | name () const |
Returns the unique name for this model instance. More... | |
Symbols * | symbols () const |
Returns the symbol table for this model. More... | |
const Time & | time () const |
Returns the current training time of this model: number of epochs, number of time steps in the current epoch and total number of time steps (which is equal to the total number of training examples seen). More... | |
int | num_updates () const |
Returns the number of updates made by this model. More... | |
const vector< int > & | num_training_errors_per_epoch () |
Returns the number of training errors made for each epoch. More... | |
int | num_training_errors () const |
Returns the number of training errors made by this model. More... | |
int | min_epochs () const |
Returns the minimum number of epochs to train. More... | |
int | max_epochs () const |
Returns the maximum number of epochs to train. More... | |
const vector< double > & | loss_per_epoch () |
Returns the loss per epoch for epoch of training that was evaluated. More... | |
virtual shared_ptr < Candidate::Comparator > | score_comparator () |
Returns a pointer to the score comparator used by this model. More... | |
virtual shared_ptr < Candidate::Comparator > | gold_comparator () |
Returns a pointer to the gold comparator used by this model. More... | |
virtual void | set_min_epochs (int min_epochs) |
Sets the minimum number of epochs to train. More... | |
virtual void | set_max_epochs (int max_epochs) |
Sets the maximum number of epochs to train. More... | |
virtual void | set_end_of_epoch_hook (Hook *end_of_epoch_hook) |
virtual bool | use_weighted_loss () |
virtual void | set_use_weighted_loss (bool use_weighted_loss) |
virtual void | set_symbols (Symbols *symbols) |
Sets the Symbols instance for this Model to be the specified instance. More... | |
Public Member Functions inherited from reranker::FactoryConstructible | |
virtual | ~FactoryConstructible () |
Additional Inherited Members | |
Protected Member Functions inherited from reranker::PerceptronModel | |
void | SetDefaultObjects () |
virtual void | ComputeFeaturesToUpdate (const CandidateSet &example, unordered_set< int > &gold_features_to_update, unordered_set< int > &best_scoring_features_to_update) const |
Computes the features to be updated for the gold candidate and the best-scoring candidate. More... | |
Protected Member Functions inherited from reranker::Model | |
void | set_name (const string &name) |
Sets the name of this Model instance. More... | |
void | set_kernel_fn (KernelFunction *kernel_fn) |
Sets the kernel function for this model. More... | |
void | set_score_comparator (shared_ptr< Candidate::Comparator > score_comparator) |
void | set_gold_comparator (shared_ptr< Candidate::Comparator > gold_comparator) |
void | SetDefaultObjects () |
void | SetDefaultComparators () |
void | SetDefaultCandidateSetScorer () |
shared_ptr< Candidate::Comparator > | GetComparator (const string &spec) const |
shared_ptr< CandidateSet::Scorer > | GetCandidateSetScorer (const string &spec) const |
shared_ptr< UpdatePredicate > | GetUpdatePredicate (const string &spec) const |
shared_ptr< Updater > | GetUpdater (const string &spec) const |
virtual void | CheckNumberOfTokens (const string &arg, const vector< string > &tokens, size_t min_expected_number, size_t max_expected_number, const string &class_name) const |
A helper method for implementing the Init method: throws a std::runtime_error if the number of tokens in the argument string is not the expected number. More... | |
Protected Attributes inherited from reranker::PerceptronModel | |
TrainingVectorSet | models_ |
The feature vectors representing this model. More... | |
TrainingVectorSet | best_models_ |
The best models seen so far during training, according to evaluation on the held-out development test data. More... | |
int | best_model_epoch_ |
The epoch of the best models seen so far during training. More... | |
int | max_epochs_in_decline_ |
The maximum number of training epochs to keep training after the model starts to degrade (i.e., has more errors than the best model so far). More... | |
int | num_epochs_in_decline_ |
The current number of training epochs in which the model has been degrading in development set performance (i.e., has been having more errors than best model so far). More... | |
double | step_size_ |
The last value computed by the ComputeStepSize method. More... | |
string | model_spec_ |
Protected Attributes inherited from reranker::Model | |
string | name_ |
This model’s unique name. More... | |
Time | time_ |
The tiny object that holds the "training time" for this model (epoch, index and absolute time index). More... | |
KernelFunction * | kernel_fn_ |
Yes, this is an interface, but we add the kernel function as a data member. More... | |
Symbols * | symbols_ |
The symbol table for this model (may be NULL). More... | |
shared_ptr< Candidate::Comparator > | score_comparator_ |
A comparator to provide an ordering for candidates based on score when scoring all candidates in a set. More... | |
shared_ptr< Candidate::Comparator > | gold_comparator_ |
A comparator to provide an ordering for candidates to find the gold candidate in a set. More... | |
shared_ptr< CandidateSet::Scorer > | candidate_set_scorer_ |
A scorer for CandidateSet instances. More... | |
shared_ptr< UpdatePredicate > | update_predicate_ |
The update predicate for this model. More... | |
shared_ptr< Updater > | updater_ |
The updater for this model. More... | |
vector< double > | loss_per_epoch_ |
The average loss per epoch. More... | |
vector< int > | num_testing_errors_per_epoch_ |
The number of testing errors made on held-out development test data for each epoch. More... | |
vector< int > | num_training_errors_per_epoch_ |
The number of errors made on training examples during each epoch. More... | |
int | num_training_errors_ |
The number of errors made on training examples. More... | |
int | num_updates_ |
The number of times an update was performed on this model during training. More... | |
int | min_epochs_ |
The minimum number of training epochs to execute. More... | |
int | max_epochs_ |
The maximum number of training epochs to execute. More... | |
Hook * | end_of_epoch_hook_ |
A hook to be performed at the end of every epoch. More... | |
bool | use_weighted_loss_ |
Indicates whether this model should weight each candidate’s loss by the value returned by CandidateSet::loss_weight. More... | |
Static Protected Attributes inherited from reranker::PerceptronModel | |
static string | proto_reader_spec_ |
A string that specifies to construct a PerceptronModelProtoReader, which is capable of de-serializing an instance of this class. More... | |
static string | proto_writer_spec_ |
A string that specifies to construct a PerceptronModelProtoWriter, which is capable of serializing an instance of this class. More... | |
A subclass of PerceptronModel that differs only in the way that the ComputeStepSize method is implemented.
The overridden definition here provides a “MIRA-style” update, where the step size is related to the difference in losses and scores of the gold and best-scoring candidates.
Definition at line 78 of file mira-style-model.H.
|
inline |
Definition at line 80 of file mira-style-model.H.
|
inline |
Definition at line 81 of file mira-style-model.H.
|
inline |
Definition at line 83 of file mira-style-model.H.
|
inline |
Definition at line 86 of file mira-style-model.H.
|
inlinevirtual |
Computes the step size for the next update, and, as a side effect, caches this value in step_size_.
The step size here is computed based on the loss and score difference between the best-scoring candidate and the gold candidate, to achieve a “MIRA-style” update.
Reimplemented from reranker::PerceptronModel.
Definition at line 125 of file mira-style-model.H.
|
inlinevirtual |
Registers one additional variable that may be initialized when this object is constructed via Factory::CreateOrDie.
The set of members includes all those handled by PerceptronModel::RegisterInitializers, as well as the following:
Variable name | Type | Required | Description | Default value |
---|---|---|---|---|
mira_clip | double | No | The maxmum value this model’s step size may attain. | 0.1 |
Reimplemented from reranker::PerceptronModel.
Definition at line 112 of file mira-style-model.H.
|
inline |
Sets the maximum value for a step size computed by ComputeStepSize.
Definition at line 119 of file mira-style-model.H.