Class NaiveBayesTrainer
java.lang.Object
opennlp.tools.ml.AbstractTrainer
opennlp.tools.ml.AbstractEventTrainer
opennlp.tools.ml.naivebayes.NaiveBayesTrainer
- All Implemented Interfaces:
Trainer, EventTrainer
Trains
models using the combination of EM algorithm
and Naive Bayes classifier which is described in:
Text Classification from Labeled and Unlabeled Documents using EM Nigam, McCallum, et al. paper of 2000
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[][]Records the array of predicates seen in each event.private static final org.slf4j.Loggerstatic final Stringprivate intNumber of events in the event set.private intNumber of outcomes.private intNumber of predicates.private int[]Records the num of times an event has been seen for each event i, in context[i].private intNumber of unique events which occurred in the event set.private String[]Stores the String names of the outcomes.private int[]List of outcomes for each event i, in context[i].private String[]Stores the String names of the predicates.The NaiveBayes only tracks predicates as ints, and so this array is needed to save the model to disk and thereby allow users to know what the outcome was in human understandable terms.private float[][]The value associates with each context.Fields inherited from class AbstractEventTrainer
DATA_INDEXER_ONE_PASS_REAL_VALUE, DATA_INDEXER_ONE_PASS_VALUE, DATA_INDEXER_PARAM, DATA_INDEXER_TWO_PASS_VALUEFields inherited from class AbstractTrainer
reportMap, trainingConfiguration, trainingParametersFields inherited from interface EventTrainer
EVENT_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates aNaiveBayesTrainerwith default training parameters.NaiveBayesTrainer(TrainingParameters parameters) Instantiates aNaiveBayesTrainerwith specificTrainingParameters. -
Method Summary
Modifier and TypeMethodDescriptiondoTrain(DataIndexer indexer) private MutableContext[]booleanprivate doubletrainingStats(EvalParameters evalParams) Trains aNaiveBayesModelwith given parameters.Methods inherited from class AbstractEventTrainer
getDataIndexer, train, train, validateMethods inherited from class AbstractTrainer
addToReport, getAlgorithm, getCutoff, getIterations, getTrainingConfiguration, init, init
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
NAIVE_BAYES_VALUE
- See Also:
-
numUniqueEvents
private int numUniqueEventsNumber of unique events which occurred in the event set. -
numEvents
private int numEventsNumber of events in the event set. -
numPreds
private int numPredsNumber of predicates. -
numOutcomes
private int numOutcomesNumber of outcomes. -
contexts
private int[][] contextsRecords the array of predicates seen in each event. -
values
private float[][] valuesThe value associates with each context. If null then context values are assumes to be 1. -
outcomeList
private int[] outcomeListList of outcomes for each event i, in context[i]. -
numTimesEventsSeen
private int[] numTimesEventsSeenRecords the num of times an event has been seen for each event i, in context[i]. -
outcomeLabels
Stores the String names of the outcomes. The NaiveBayes only tracks outcomes as ints, and so this array is needed to save the model to disk and thereby allow users to know what the outcome was in human understandable terms. -
predLabels
Stores the String names of the predicates.The NaiveBayes only tracks predicates as ints, and so this array is needed to save the model to disk and thereby allow users to know what the outcome was in human understandable terms.
-
-
Constructor Details
-
NaiveBayesTrainer
public NaiveBayesTrainer()Instantiates aNaiveBayesTrainerwith default training parameters. -
NaiveBayesTrainer
Instantiates aNaiveBayesTrainerwith specificTrainingParameters.- Parameters:
parameters- Theparameterto use.
-
-
Method Details
-
isSortAndMerge
public boolean isSortAndMerge()- Specified by:
isSortAndMergein classAbstractEventTrainer
-
doTrain
- Specified by:
doTrainin classAbstractEventTrainer- Throws:
IOException
-
trainModel
Trains aNaiveBayesModelwith given parameters.- Parameters:
di- TheDataIndexerused as data input.- Returns:
- A valid, trained
Naive Bayes model.
-
findParameters
-
trainingStats
-