Package cc.mallet.share.upenn
Class MaxEntShell
- java.lang.Object
-
- cc.mallet.share.upenn.MaxEntShell
-
public class MaxEntShell extends java.lang.ObjectSimple wrapper for training a MALLET maxent classifier.- Version:
- 1.0
- Author:
- Fernando Pereira
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Classificationclassify(Classifier classifier, java.lang.String[] features)Compute the maxent classification of an instance.static Classification[]classify(Classifier classifier, java.lang.String[][] features)Compute the maxent classifications of an array of instancesstatic Classification[]classify(Classifier classifier, java.util.Iterator<Instance> data)Compute the maxent classifications for unlabeled instances given by an iterator.static Classifierload(java.io.File modelFile)Load a classifier from a file.static voidmain(java.lang.String[] args)Command-line wrapper to train, test, or run a maxent classifier.static doubletest(Classifier classifier, java.lang.String[][] features, java.lang.String[] labels)Test a maxent classifier.static doubletest(Classifier classifier, java.util.Iterator<Instance> data)Test a maxent classifier.static Classifiertrain(java.lang.String[][] features, java.lang.String[] labels, double var, java.io.File save)Train a maxent classifier.static Classifiertrain(java.util.Iterator<Instance> data, double var, java.io.File save)Train a maxent classifier.
-
-
-
Method Detail
-
train
public static Classifier train(java.lang.String[][] features, java.lang.String[] labels, double var, java.io.File save) throws java.io.IOException
Train a maxent classifier. Each row offeaturesrepresents the features of a training instance. The label for that instance is in the corresponding position oflabels.- Parameters:
features- Each row gives the on features of an instancelabels- Each position gives the label of an instancevar- Gaussian prior variance for trainingsave- if non-null, save the trained model to this file- Returns:
- the maxent classifier
- Throws:
java.io.IOException- if the trained model cannot be saved
-
train
public static Classifier train(java.util.Iterator<Instance> data, double var, java.io.File save) throws java.io.IOException
Train a maxent classifier. The iteratordatareturns training instances with aTokenSequenceas data and a target object. The tokens in the instance data will be converted to features.- Parameters:
data- the iterator over training instancesvar- Gaussian prior variance for training.save- if non-null, save the trained model to this file- Returns:
- the maxent classifier
- Throws:
java.io.IOException- if the trained model cannot be saved
-
test
public static double test(Classifier classifier, java.lang.String[][] features, java.lang.String[] labels)
Test a maxent classifier. The data representation is the same as for training.- Parameters:
classifier- the classifier to testfeatures- an array of instances represented as arrays of featureslabels- corresponding labels- Returns:
- accuracy on the data
-
test
public static double test(Classifier classifier, java.util.Iterator<Instance> data)
Test a maxent classifier. The data representation is the same as for training.- Parameters:
classifier- the classifier to testdata- an iterator over labeled instances- Returns:
- accuracy on the data
-
classify
public static Classification classify(Classifier classifier, java.lang.String[] features)
Compute the maxent classification of an instance.- Parameters:
classifier- the classifierfeatures- the features that are on for this instance- Returns:
- the classification
-
classify
public static Classification[] classify(Classifier classifier, java.lang.String[][] features)
Compute the maxent classifications of an array of instances- Parameters:
classifier- the classifierfeatures- each row represents the on features for an instance- Returns:
- the array of classifications for the given instances
-
classify
public static Classification[] classify(Classifier classifier, java.util.Iterator<Instance> data)
Compute the maxent classifications for unlabeled instances given by an iterator.- Parameters:
classifier- the classifierdata- the iterator over unlabeled instances- Returns:
- the array of classifications for the given instances
-
load
public static Classifier load(java.io.File modelFile) throws java.io.IOException, java.lang.ClassNotFoundException
Load a classifier from a file.- Parameters:
modelFile- the file- Returns:
- the classifier serialized in the file
- Throws:
java.io.IOException- if the file cannot be opened or readjava.lang.ClassNotFoundException- if the file does not deserialize
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionCommand-line wrapper to train, test, or run a maxent classifier. Instances are represented as follows:- Labeled:
- label feature-1 ... feature-n
- Unlabeled:
- feature-1 ... feature-n
- Parameters:
args- the command line arguments. Options (shell and Java quoting should be added as needed):--helpboolean- Print this command line option usage information. Give
truefor longer documentation. Default isfalse. --prefix-codeJava-code- Java code you want run before any other interpreted code. Note that the text is interpreted without modification, so unlike some other Java code options, you need to include any necessary 'new's. Default is null.
--gaussian-variancepositive-number- The Gaussian prior variance used for training. Default is 1.0.
--trainfilenane- Train on labeled instances stored in filename. Default is no training.
--testfilename- Test on the labeled instances stored in filename. Default is no testing.
--classifyfilename- Classify the unlabeled instances stored in filename. Default is no classification.
--modelfilename- The filename for reading (test/classify) or saving (train) the model. Default is no model file.
- Throws:
java.lang.Exception- if an error occurs
-
-