Browse files

updates to docs for perceptron code.

  • Loading branch information...
1 parent d1123a6 commit e79cd56495edb6e6521ccbbddcd6fa023076ea61 tsmorton committed Nov 6, 2008
Showing with 48 additions and 20 deletions.
  1. +2 −2 docs/about.html
  2. +29 −10 samples/sports/CreateModel.java
  3. +17 −8 samples/sports/Predict.java
View
4 docs/about.html
@@ -125,7 +125,7 @@
and then implementations of two interfaces in the opennlp.maxent
package, EventStream and ContextGenerator.  These have fairly
simple specifications, and example implementations can be found in the
-<a href="http://grok.sourceforge.net">OpenNLP Grok Library</a>
+<a href="http://opennlp.sourceforge.net">OpenNLP Tools</a>
preprocessing components.&nbsp; More details are given in the
opennlp.maxent <a href="howto.html">HOWTO</a>.
</p>
@@ -188,7 +188,7 @@
<HR WIDTH="100%">
<h3>
- Email: <a href="mailto:tsmorton@users.sourceforge.net">tsmorton@users.sourceforge.net</a>
+ Email: <a href="mailto:tsmorton@users.sourceforege.net">tsmorton@users.sourceforge.net</a>
<br>
<script language="JavaScript">
<!---//
View
39 samples/sports/CreateModel.java
@@ -20,21 +20,23 @@
import java.io.FileReader;
import opennlp.maxent.BasicEventStream;
-import opennlp.maxent.EventStream;
import opennlp.maxent.GIS;
-import opennlp.maxent.GISModel;
-import opennlp.maxent.OnePassRealValueDataIndexer;
import opennlp.maxent.PlainTextByLineDataStream;
import opennlp.maxent.RealBasicEventStream;
import opennlp.maxent.io.GISModelWriter;
import opennlp.maxent.io.SuffixSensitiveGISModelWriter;
+import opennlp.model.AbstractModel;
+import opennlp.model.EventStream;
+import opennlp.model.OnePassDataIndexer;
+import opennlp.model.OnePassRealValueDataIndexer;
+import opennlp.perceptron.PerceptronTrainer;
/**
* Main class which calls the GIS procedure after building the EventStream
* from the data.
*
* @author Chieu Hai Leong and Jason Baldridge
- * @version $Revision: 1.6 $, $Date: 2007/04/13 16:24:06 $
+ * @version $Revision: 1.7 $, $Date: 2008/11/06 20:00:34 $
*/
public class CreateModel {
@@ -60,10 +62,17 @@ private static void usage() {
public static void main (String[] args) {
int ai = 0;
boolean real = false;
+ String type = "maxent";
+ if(args.length == 0) {
+ usage();
+ }
while (args[ai].startsWith("-")) {
if (args[ai].equals("-real")) {
real = true;
}
+ else if (args[ai].equals("-perceptron")) {
+ type = "perceptron";
+ }
else {
System.err.println("Unknown option: "+args[ai]);
usage();
@@ -84,17 +93,27 @@ public static void main (String[] args) {
es = new RealBasicEventStream(new PlainTextByLineDataStream(datafr));
}
GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;
- GISModel model;
- if (!real) {
- model = GIS.trainModel(es,USE_SMOOTHING);
+ AbstractModel model;
+ if (type.equals("maxent")) {
+
+ if (!real) {
+ model = GIS.trainModel(es,USE_SMOOTHING);
+ }
+ else {
+ model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
+ }
+ }
+ else if (type.equals("perceptron")){
+ System.err.println("Perceptron training");
+ model = new PerceptronTrainer().trainModel(10, new OnePassDataIndexer(es,0),0);
}
else {
- model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
+ System.err.println("Unknown model type: "+type);
+ model = null;
}
File outputFile = new File(modelFileName);
- GISModelWriter writer =
- new SuffixSensitiveGISModelWriter(model, outputFile);
+ GISModelWriter writer = new SuffixSensitiveGISModelWriter(model, outputFile);
writer.persist();
} catch (Exception e) {
System.out.print("Unable to create model due to exception: ");
View
25 samples/sports/Predict.java
@@ -16,15 +16,22 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////////////
-import opennlp.maxent.*;
-import opennlp.maxent.io.*;
-import java.io.*;
+import java.io.File;
+import java.io.FileReader;
+
+import opennlp.maxent.BasicContextGenerator;
+import opennlp.maxent.ContextGenerator;
+import opennlp.maxent.DataStream;
+import opennlp.maxent.PlainTextByLineDataStream;
+import opennlp.model.GenericModelReader;
+import opennlp.model.MaxentModel;
+import opennlp.model.RealValueFileEventStream;
/**
* Test the model on some input.
*
* @author Jason Baldridge
- * @version $Revision: 1.3 $, $Date: 2007/04/13 16:24:06 $
+ * @version $Revision: 1.4 $, $Date: 2008/11/06 20:00:34 $
*/
public class Predict {
MaxentModel _model;
@@ -64,12 +71,16 @@ private static void usage() {
public static void main(String[] args) {
String dataFileName, modelFileName;
boolean real = false;
+ String type = "maxent";
int ai = 0;
if (args.length > 0) {
while (args[ai].startsWith("-")) {
if (args[ai].equals("-real")) {
real = true;
}
+ else if (args[ai].equals("-perceptron")) {
+ type = "perceptron";
+ }
else {
usage();
}
@@ -89,10 +100,8 @@ public static void main(String[] args) {
}
Predict predictor = null;
try {
- GISModel m =
- new SuffixSensitiveGISModelReader(
- new File(modelFileName)).getModel();
- predictor = new Predict(m);
+ MaxentModel m = new GenericModelReader(new File(modelFileName)).getModel();
+ predictor = new Predict(m);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);

0 comments on commit e79cd56

Please sign in to comment.