Repository: opennlp Updated Branches: refs/heads/master c75bce142 -> 11bfce381
OPENNLP-166: Remove or deprecate slack parameter Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/11bfce38 Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/11bfce38 Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/11bfce38 Branch: refs/heads/master Commit: 11bfce381bfd0ea9fb854514460317156c3e9be2 Parents: c75bce1 Author: Jörn Kottmann <[email protected]> Authored: Tue Jan 17 20:05:00 2017 +0100 Committer: Jörn Kottmann <[email protected]> Committed: Tue Jan 17 21:16:55 2017 +0100 ---------------------------------------------------------------------- .../java/opennlp/tools/ml/maxent/GISModel.java | 47 +++++++++++++++----- .../opennlp/tools/ml/maxent/GISTrainer.java | 8 ++-- .../opennlp/tools/ml/model/AbstractModel.java | 3 +- .../opennlp/tools/ml/model/EvalParameters.java | 28 +++++++----- 4 files changed, 59 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/opennlp/blob/11bfce38/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISModel.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISModel.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISModel.java index 58fa6a9..d806bf8 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISModel.java @@ -46,6 +46,7 @@ public final class GISModel extends AbstractModel { * @param correctionParam * The parameter associated with the correction feature. */ + @Deprecated public GISModel(Context[] params, String[] predLabels, String[] outcomeNames, int correctionConstant, double correctionParam) { this(params, predLabels, outcomeNames, correctionConstant, correctionParam, @@ -62,6 +63,22 @@ public final class GISModel extends AbstractModel { * The names of the predicates used in this model. * @param outcomeNames * The names of the outcomes this model predicts. + */ + public GISModel(Context[] params, String[] predLabels, String[] outcomeNames) { + this(params, predLabels, outcomeNames, 1, 0, + new UniformPrior()); + } + + /** + * Creates a new model with the specified parameters, outcome names, and + * predicate/feature labels. + * + * @param params + * The parameters of the model. + * @param predLabels + * The names of the predicates used in this model. + * @param outcomeNames + * The names of the outcomes this model predicts. * @param correctionConstant * The maximum number of active features which occur in an event. * @param correctionParam @@ -69,6 +86,7 @@ public final class GISModel extends AbstractModel { * @param prior * The prior to be used with this model. */ + @Deprecated public GISModel(Context[] params, String[] predLabels, String[] outcomeNames, int correctionConstant, double correctionParam, Prior prior) { super(params, predLabels, outcomeNames, correctionConstant, correctionParam); @@ -78,6 +96,23 @@ public final class GISModel extends AbstractModel { } /** + * Creates a new model with the specified parameters, outcome names, and + * predicate/feature labels. + * + * @param params + * The parameters of the model. + * @param predLabels + * The names of the predicates used in this model. + * @param outcomeNames + * The names of the outcomes this model predicts. + * @param prior + * The prior to be used with this model. + */ + public GISModel(Context[] params, String[] predLabels, String[] outcomeNames, Prior prior) { + this(params, predLabels, outcomeNames, 1, 0, prior); + } + + /** * Use this model to evaluate a context and return an array of the likelihood * of each outcome given that context. * @@ -190,15 +225,7 @@ public final class GISModel extends AbstractModel { double normal = 0.0; for (int oid = 0; oid < model.getNumOutcomes(); oid++) { - if (model.getCorrectionParam() != 0) { - prior[oid] = Math - .exp(prior[oid] - * model.getConstantInverse() - + ((1.0 - (numfeats[oid] / model - .getCorrectionConstant())) * model.getCorrectionParam())); - } else { - prior[oid] = Math.exp(prior[oid] * model.getConstantInverse()); - } + prior[oid] = Math.exp(prior[oid]); normal += prior[oid]; } @@ -207,4 +234,4 @@ public final class GISModel extends AbstractModel { } return prior; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/opennlp/blob/11bfce38/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java index 19ea58e..52fe219 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GISTrainer.java @@ -312,7 +312,7 @@ class GISTrainer { // is only needed during training, and the correction feature is not necessary. // For compatibility reasons the model contains form now on a correction constant of 1, // and a correction param 0. - evalParams = new EvalParameters(params, 0, 1, numOutcomes); + evalParams = new EvalParameters(params, numOutcomes); int[] activeOutcomes = new int[numOutcomes]; int[] outcomePattern; int[] allOutcomesPattern = new int[numOutcomes]; @@ -369,10 +369,8 @@ class GISTrainer { findParameters(iterations, correctionConstant); - /* Create and return the model ****/ - // To be compatible with old models the correction constant is always 1 - return new GISModel(params, predLabels, outcomeLabels, 1, - evalParams.getCorrectionParam()); + // Create and return the model + return new GISModel(params, predLabels, outcomeLabels); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/11bfce38/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java index 095a6cc..fb08152 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/AbstractModel.java @@ -53,8 +53,9 @@ public abstract class AbstractModel implements MaxentModel { this.evalParams = new EvalParameters(params,outcomeNames.length); } + @Deprecated public AbstractModel(Context[] params, String[] predLabels, String[] outcomeNames, - int correctionConstant,double correctionParam) { + int correctionConstant, double correctionParam) { init(predLabels,outcomeNames); this.evalParams = new EvalParameters(params,correctionParam,correctionConstant,outcomeNames.length); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/11bfce38/opennlp-tools/src/main/java/opennlp/tools/ml/model/EvalParameters.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/EvalParameters.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/EvalParameters.java index a35ff80..e3d1d84 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/EvalParameters.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/EvalParameters.java @@ -28,18 +28,25 @@ import java.util.Objects; */ public class EvalParameters { - /** Mapping between outcomes and parameter values for each context. - * The integer representation of the context can be found using <code>pmap</code>.*/ + /** + * Mapping between outcomes and parameter values for each context. + * The integer representation of the context can be found using <code>pmap</code>. + */ private Context[] params; - /** The number of outcomes being predicted. */ + /** + * The number of outcomes being predicted. + */ private final int numOutcomes; - /** The maximum number of features fired in an event. Usually referred to as C. + /** + * The maximum number of features fired in an event. Usually referred to as C. * This is used to normalize the number of features which occur in an event. */ private double correctionConstant; /** Stores inverse of the correction constant, 1/C. */ + @Deprecated private final double constantInverse; /** The correction parameter of the model. */ + @Deprecated private double correctionParam; /** @@ -49,6 +56,7 @@ public class EvalParameters { * @param correctionConstant The correction constant. * @param numOutcomes The number of outcomes. */ + @Deprecated public EvalParameters(Context[] params, double correctionParam, double correctionConstant, int numOutcomes) { this.params = params; @@ -59,35 +67,33 @@ public class EvalParameters { } public EvalParameters(Context[] params, int numOutcomes) { - this(params,0,0,numOutcomes); + this(params, 0, 1, numOutcomes); } - /* (non-Javadoc) - * @see opennlp.tools.ml.model.EvalParameters#getParams() - */ public Context[] getParams() { return params; } - /* (non-Javadoc) - * @see opennlp.tools.ml.model.EvalParameters#getNumOutcomes() - */ public int getNumOutcomes() { return numOutcomes; } + @Deprecated public double getCorrectionConstant() { return correctionConstant; } + @Deprecated public double getConstantInverse() { return constantInverse; } + @Deprecated public double getCorrectionParam() { return correctionParam; } + @Deprecated public void setCorrectionParam(double correctionParam) { this.correctionParam = correctionParam; }
