Repository: opennlp Updated Branches: refs/heads/master 6ffdfbb8c -> 6618b2699
OPENNLP-371: Throw an exception if training data only has one outcome Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/6618b269 Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/6618b269 Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/6618b269 Branch: refs/heads/master Commit: 6618b269933a363af1b73714df8a07832cdcc2ec Parents: 6ffdfbb Author: Jörn Kottmann <[email protected]> Authored: Sun Jan 29 11:44:48 2017 +0100 Committer: Jörn Kottmann <[email protected]> Committed: Tue Jan 31 12:43:28 2017 +0100 ---------------------------------------------------------------------- .../src/main/java/opennlp/tools/ml/AbstractEventTrainer.java | 6 ++++++ 1 file changed, 6 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/opennlp/blob/6618b269/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java index b73df37..c465f88 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java @@ -25,6 +25,7 @@ import opennlp.tools.ml.model.DataIndexerFactory; import opennlp.tools.ml.model.Event; import opennlp.tools.ml.model.HashSumEventStream; import opennlp.tools.ml.model.MaxentModel; +import opennlp.tools.util.InsufficientTrainingDataException; import opennlp.tools.util.ObjectStream; import opennlp.tools.util.TrainingParameters; @@ -68,6 +69,11 @@ public abstract class AbstractEventTrainer extends AbstractTrainer implements Ev if (!isValid()) { throw new IllegalArgumentException("trainParams are not valid!"); } + + if (indexer.getOutcomeLabels().length <= 1) { + throw new InsufficientTrainingDataException("Training data must contain more than one outcome"); + } + MaxentModel model = doTrain(indexer); addToReport(AbstractTrainer.TRAINER_TYPE_PARAM, EventTrainer.EVENT_VALUE); return model;
