Public Member Functions
CRFSuite::Trainer Class Reference

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:


Member Function Documentation

void CRFSuite::Trainer::append ( const ItemSequence xseq,
const StringList yseq,
int  group 
)

Append an instance (item/label sequence) to the data set.

Parameters:
xseqThe item sequence of the instance.
yseqThe label sequence of the instance. The number of elements in yseq must be identical to that in xseq.
groupThe group number of the instance.
Exceptions:
std::invalid_argumentArguments xseq and yseq are invalid.
std::runtime_errorOut 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:
nameThe parameter name.
Returns:
std::string The value of the parameter.
Exceptions:
std::invalid_argumentThe 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:
nameThe parameter name.
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:
msgThe message
StringList CRFSuite::Trainer::params ( )

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:
algorithmThe name of the training algorithm.
typeThe 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:
nameThe parameter name.
valueThe value of the parameter.
Exceptions:
std::invalid_argumentThe 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:
modelThe filename to which the trained model is stored. If this value is empty, this function does not write out a model file.
holdoutThe 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.

Copyright (c) 2002-2011 by Naoaki Okazaki
Thu Aug 11 2011 12:37:07