Class SimplePerceptronSequenceTrainer
java.lang.Object
opennlp.tools.ml.AbstractTrainer
opennlp.tools.ml.AbstractEventModelSequenceTrainer
opennlp.tools.ml.perceptron.SimplePerceptronSequenceTrainer
- All Implemented Interfaces:
Trainer, EventModelSequenceTrainer<Event>
Trains
models with sequences using the perceptron algorithm.
Each outcome is represented as a binary perceptron classifier. This supports standard (integer) weighting as well average weighting.
Sequence information is used in a simplified was to that described in: Discriminative Training Methods for Hidden Markov Models: Theory and Experiments with the Perceptron Algorithm. Michael Collins, EMNLP 2002.
Specifically only updates are applied to tokens which were incorrectly tagged by a sequence tagger rather than to all feature across the sequence which differ from the training sequence.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MutableContext[]Stores the average parameter values of each predicate during iteration.private static final intprivate static final intprivate intprivate static final org.slf4j.Loggerprivate intNumber of events in the event set.private intprivate intNumber of predicates.private intprivate String[]private int[]List of outcomes for each event i, in context[i].private MutableContext[]Stores the estimated parameter value of each predicate during iteration.static final StringMapping between context and an integerprivate String[]private SequenceStream<Event> private int[][][]private booleanprivate static final intFields inherited from class AbstractTrainer
reportMap, trainingConfiguration, trainingParametersFields inherited from interface EventModelSequenceTrainer
SEQUENCE_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates aSimplePerceptronSequenceTrainerwith a default configuration of training parameters. -
Method Summary
Modifier and TypeMethodDescriptiondoTrain(SequenceStream<Event> events) private voidfindParameters(int iterations) voidnextIteration(int iteration) private voidtrainingStats(MutableContext[] params) trainModel(int iterations, SequenceStream<Event> sequenceStream, int cutoff, boolean useAverage) Trains aPerceptronModelwith given parameters.voidvalidate()Checks the configuredparameters.Methods inherited from class AbstractEventModelSequenceTrainer
trainMethods inherited from class AbstractTrainer
addToReport, getAlgorithm, getCutoff, getIterations, getTrainingConfiguration, init, init
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
PERCEPTRON_SEQUENCE_VALUE
- See Also:
-
iterations
private int iterations -
sequenceStream
-
numEvents
private int numEventsNumber of events in the event set. -
numPreds
private int numPredsNumber of predicates. -
numOutcomes
private int numOutcomes -
outcomeList
private int[] outcomeListList of outcomes for each event i, in context[i]. -
outcomeLabels
-
averageParams
Stores the average parameter values of each predicate during iteration. -
pmap
-
omap
-
params
Stores the estimated parameter value of each predicate during iteration. -
useAverage
private boolean useAverage -
updates
private int[][][] updates -
VALUE
private static final int VALUE- See Also:
-
ITER
private static final int ITER- See Also:
-
EVENT
private static final int EVENT- See Also:
-
predLabels
-
numSequences
private int numSequences
-
-
Constructor Details
-
SimplePerceptronSequenceTrainer
public SimplePerceptronSequenceTrainer()Instantiates aSimplePerceptronSequenceTrainerwith a default configuration of training parameters.
-
-
Method Details
-
validate
public void validate()Checks the configuredparameters. If a subclass overrides this, it should callsuper.validate();.- Overrides:
validatein classAbstractTrainer- Throws:
IllegalArgumentException- Thrown if the algorithm name is not equal to {PERCEPTRON_SEQUENCE_VALUE}.
-
doTrain
- Specified by:
doTrainin classAbstractEventModelSequenceTrainer- Throws:
IOException
-
trainModel
public AbstractModel trainModel(int iterations, SequenceStream<Event> sequenceStream, int cutoff, boolean useAverage) throws IOException Trains aPerceptronModelwith given parameters.- Parameters:
iterations- The number of iterations to use for training.sequenceStream- TheSequenceStream<Event>used as data input.cutoff- The {TrainingParameters.CUTOFF_PARAM} value to use for training.useAverage- Whether to use 'averaging', or not.- Returns:
- A valid, trained
perceptron model. - Throws:
IOException
-
findParameters
- Throws:
IOException
-
nextIteration
- Throws:
IOException
-
trainingStats
- Throws:
IOException
-