Class QNTrainer
- java.lang.Object
-
- opennlp.tools.ml.AbstractTrainer
-
- opennlp.tools.ml.AbstractEventTrainer
-
- opennlp.tools.ml.maxent.quasinewton.QNTrainer
-
- All Implemented Interfaces:
Trainer
,EventTrainer
public class QNTrainer extends AbstractEventTrainer
A Maxent modelTrainer
using L-BFGS algorithm.- See Also:
QNModel
,AbstractEventTrainer
-
-
Field Summary
Fields Modifier and Type Field Description static double
L1COST_DEFAULT
static String
L1COST_PARAM
static double
L2COST_DEFAULT
static String
L2COST_PARAM
static int
M_DEFAULT
static String
M_PARAM
static int
MAX_FCT_EVAL_DEFAULT
static String
MAX_FCT_EVAL_PARAM
static String
MAXENT_QN_VALUE
static int
THREADS_DEFAULT
static String
THREADS_PARAM
-
Fields inherited from class opennlp.tools.ml.AbstractEventTrainer
DATA_INDEXER_ONE_PASS_REAL_VALUE, DATA_INDEXER_ONE_PASS_VALUE, DATA_INDEXER_PARAM, DATA_INDEXER_TWO_PASS_VALUE
-
Fields inherited from class opennlp.tools.ml.AbstractTrainer
ALGORITHM_PARAM, CUTOFF_DEFAULT, CUTOFF_PARAM, ITERATIONS_DEFAULT, ITERATIONS_PARAM, TRAINER_TYPE_PARAM, VERBOSE_DEFAULT, VERBOSE_PARAM
-
Fields inherited from interface opennlp.tools.ml.EventTrainer
EVENT_VALUE
-
-
Constructor Summary
Constructors Constructor Description QNTrainer()
Initializes aQNTrainer
.QNTrainer(boolean verbose)
Initializes aQNTrainer
.QNTrainer(int m)
Initializes aQNTrainer
.QNTrainer(int m, boolean verbose)
Initializes aQNTrainer
.QNTrainer(int m, int maxFctEval, boolean verbose)
Initializes aQNTrainer
.QNTrainer(TrainingParameters parameters)
Initializes aQNTrainer
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AbstractModel
doTrain(DataIndexer indexer)
void
init(Map<String,Object> trainParams, Map<String,String> reportMap)
void
init(TrainingParameters trainingParameters, Map<String,String> reportMap)
boolean
isSortAndMerge()
boolean
isValid()
Deprecated.Usevalidate()
instead.QNModel
trainModel(int iterations, DataIndexer indexer)
Trains a model using the QN algorithm.void
validate()
Checks the configuredparameters
.-
Methods inherited from class opennlp.tools.ml.AbstractEventTrainer
getDataIndexer, train, train
-
Methods inherited from class opennlp.tools.ml.AbstractTrainer
getAlgorithm, getCutoff, getIterations
-
-
-
-
Field Detail
-
MAXENT_QN_VALUE
public static final String MAXENT_QN_VALUE
- See Also:
- Constant Field Values
-
THREADS_PARAM
public static final String THREADS_PARAM
- See Also:
- Constant Field Values
-
THREADS_DEFAULT
public static final int THREADS_DEFAULT
- See Also:
- Constant Field Values
-
L1COST_PARAM
public static final String L1COST_PARAM
- See Also:
- Constant Field Values
-
L1COST_DEFAULT
public static final double L1COST_DEFAULT
- See Also:
- Constant Field Values
-
L2COST_PARAM
public static final String L2COST_PARAM
- See Also:
- Constant Field Values
-
L2COST_DEFAULT
public static final double L2COST_DEFAULT
- See Also:
- Constant Field Values
-
M_PARAM
public static final String M_PARAM
- See Also:
- Constant Field Values
-
M_DEFAULT
public static final int M_DEFAULT
- See Also:
- Constant Field Values
-
MAX_FCT_EVAL_PARAM
public static final String MAX_FCT_EVAL_PARAM
- See Also:
- Constant Field Values
-
MAX_FCT_EVAL_DEFAULT
public static final int MAX_FCT_EVAL_DEFAULT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QNTrainer
public QNTrainer()
Initializes aQNTrainer
.Note:
The resulting instance does not print progress messages about training to STDOUT.
-
QNTrainer
public QNTrainer(TrainingParameters parameters)
Initializes aQNTrainer
.- Parameters:
parameters
- TheTrainingParameters
to use.
-
QNTrainer
public QNTrainer(boolean verbose)
Initializes aQNTrainer
.- Parameters:
verbose
- Whether to send progress messages about training to STDOUT whentrue
; trains silently otherwise.
-
QNTrainer
public QNTrainer(int m)
Initializes aQNTrainer
.- Parameters:
m
- The number of hessian updates to store.
-
QNTrainer
public QNTrainer(int m, boolean verbose)
Initializes aQNTrainer
.- Parameters:
m
- The number of hessian updates to store.verbose
- Whether to send progress messages about training to STDOUT whentrue
; trains silently otherwise.
-
QNTrainer
public QNTrainer(int m, int maxFctEval, boolean verbose)
Initializes aQNTrainer
.- Parameters:
m
- The number of hessian updates to store.verbose
- Whether to send progress messages about training to STDOUT whentrue
; trains silently otherwise.
-
-
Method Detail
-
init
public void init(TrainingParameters trainingParameters, Map<String,String> reportMap)
Description copied from class:AbstractTrainer
- Specified by:
init
in interfaceTrainer
- Overrides:
init
in classAbstractTrainer
- Parameters:
trainingParameters
- TheTrainingParameters
to use.reportMap
- TheMap
instance used as report map.
-
init
public void init(Map<String,Object> trainParams, Map<String,String> reportMap)
Description copied from class:AbstractTrainer
- Overrides:
init
in classAbstractTrainer
- Parameters:
trainParams
- TheMap
that maps training parameters on a key-value basis.reportMap
- TheMap
instance used as report map.
-
validate
public void validate()
Description copied from class:AbstractTrainer
Checks the configuredparameters
. If a subclass overrides this, it should callsuper.validate();
.- Overrides:
validate
in classAbstractEventTrainer
-
isValid
@Deprecated public boolean isValid()
Deprecated.Usevalidate()
instead.- Overrides:
isValid
in classAbstractEventTrainer
- Returns:
true
if the validation of the internal configuration succeeds,false
otherwise.
-
isSortAndMerge
public boolean isSortAndMerge()
- Specified by:
isSortAndMerge
in classAbstractEventTrainer
-
doTrain
public AbstractModel doTrain(DataIndexer indexer) throws IOException
- Specified by:
doTrain
in classAbstractEventTrainer
- Throws:
IOException
-
trainModel
public QNModel trainModel(int iterations, DataIndexer indexer)
Trains a model using the QN algorithm.- Parameters:
iterations
- The number of QN iterations to perform.indexer
- TheDataIndexer
used to compress events in memory.- Returns:
- A trained
QNModel
which can be used immediately or saved to disk using anQNModelWriter
. - Throws:
IllegalArgumentException
- Thrown if parameters were invalid.
-
-