The trainer class.
More...
List of all members.
Public Member Functions |
| Trainer () |
| Construct a trainer.
|
virtual | ~Trainer () |
| Destruct a trainer.
|
void | clear () |
| Remove all instances in the data set.
|
void | append (const ItemSequence &xseq, const StringList &yseq, int group) |
| Append an instance (item/label sequence) to the data set.
|
bool | select (const std::string &algorithm, const std::string &type) |
| Initialize the training algorithm.
|
int | train (const std::string &model, int holdout) |
| Run the training algorithm.
|
StringList | params () |
| Obtain the list of parameters.
|
void | set (const std::string &name, const std::string &value) |
| Set a training parameter.
|
std::string | get (const std::string &name) |
| Get the value of a training parameter.
|
std::string | help (const std::string &name) |
| Get the description of a training parameter.
|
virtual void | message (const std::string &msg) |
| Receive messages from the training algorithm.
|
Detailed Description
The trainer class.
This class maintains a data set for training, and provides an interface to various graphical models and training algorithms. The standard procedure for implementing a trainer is:
- create a class by inheriting this class
- overwrite message() function to receive messages of training progress
- call append() to append item/label sequences to the training set
- call select() to specify a graphical model and an algorithm
- call set() to configure parameters specific to the model and algorithm
- call train() to start a training process with the current setting
Member Function Documentation
Append an instance (item/label sequence) to the data set.
- Parameters:
-
xseq | The item sequence of the instance. |
yseq | The label sequence of the instance. The number of elements in yseq must be identical to that in xseq. |
group | The group number of the instance. |
- Exceptions:
-
std::invalid_argument | Arguments xseq and yseq are invalid. |
std::runtime_error | Out of memory. |
std::string CRFSuite::Trainer::get |
( |
const std::string & |
name | ) |
|
Get the value of a training parameter.
This function gets a parameter value for the graphical model and training algorithm specified by select() function.
- Parameters:
-
- Returns:
- std::string The value of the parameter.
- Exceptions:
-
std::invalid_argument | The parameter is not found. |
std::string CRFSuite::Trainer::help |
( |
const std::string & |
name | ) |
|
Get the description of a training parameter.
This function obtains the help message for the parameter specified by the name. The graphical model and training algorithm must be selected by select() function before calling this function.
- Parameters:
-
- Returns:
- std::string The description (help message) of the parameter.
virtual void CRFSuite::Trainer::message |
( |
const std::string & |
msg | ) |
[virtual] |
Receive messages from the training algorithm.
Override this member function to receive messages of the training process.
- Parameters:
-
Obtain the list of parameters.
This function returns the list of parameter names available for the graphical model and training algorithm specified by select() function.
- Returns:
- StringList The list of parameters available for the current graphical model and training algorithm.
bool CRFSuite::Trainer::select |
( |
const std::string & |
algorithm, |
|
|
const std::string & |
type |
|
) |
| |
Initialize the training algorithm.
- Parameters:
-
algorithm | The name of the training algorithm. |
type | The name of the graphical model. |
- Returns:
- bool
true
if the training algorithm is successfully initialized, false
otherwise.
void CRFSuite::Trainer::set |
( |
const std::string & |
name, |
|
|
const std::string & |
value |
|
) |
| |
Set a training parameter.
This function sets a parameter value for the graphical model and training algorithm specified by select() function.
- Parameters:
-
name | The parameter name. |
value | The value of the parameter. |
- Exceptions:
-
std::invalid_argument | The parameter is not found. |
int CRFSuite::Trainer::train |
( |
const std::string & |
model, |
|
|
int |
holdout |
|
) |
| |
Run the training algorithm.
This function starts the training algorithm with the data set given by append() function. After starting the training process, the training algorithm invokes the virtual function message() to report the progress of the training process.
- Parameters:
-
model | The filename to which the trained model is stored. If this value is empty, this function does not write out a model file. |
holdout | The group number of holdout evaluation. The instances with this group number will not be used for training, but for holdout evaluation. Specify -1 to use all instances for training. |
- Returns:
- int The status code.