incubator-ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chen...@apache.org
Subject svn commit: r1387176 - /incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Date Tue, 18 Sep 2012 14:14:26 GMT
Author: chenpei
Date: Tue Sep 18 14:14:25 2012
New Revision: 1387176

URL: http://svn.apache.org/viewvc?rev=1387176&view=rev
Log:
This was a changed checked by dima to the SourceForge branch after the dump was taken on 7/31/2012.
 Adding this change back to the SHARPn Branch on ASF.
Revision: 1053
Author:   dimdym
Date:     2012-07-31 12:43:26 +0000 (Tue, 31 Jul 2012)
Log Message:
-----------
Added an option to test on a heldout test set

Modified:
    incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java

Modified: incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java?rev=1387176&r1=1387175&r2=1387176&view=diff
==============================================================================
--- incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
(original)
+++ incubator/ctakes/branches/SHARPn-cTAKES/relation-extractor/src/org/chboston/cnlp/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Tue Sep 18 14:14:25 2012
@@ -88,6 +88,12 @@ public class RelationExtractorEvaluation
         required = true)
     public File trainDirectory;
 
+    @Option(
+        name = "--test-dir",
+        usage = "specify the directory contraining the XMI testing files (for example, /NLP/Corpus/Relations/mipacq/xmi/test)",
+        required = false)
+    public File testDirectory;
+    
     @Option(name = "--grid-search", usage = "run a grid search to select the best parameters")
     public boolean gridSearch = false;
 
@@ -105,7 +111,7 @@ public class RelationExtractorEvaluation
     Options options = new Options();
     options.parseOptions(args);
     List<File> trainFiles = Arrays.asList(options.trainDirectory.listFiles());
-
+    
     // define the output directory for models
     File modelsDir = options.runDegreeOf
         ? new File("models/degree_of")
@@ -155,16 +161,30 @@ public class RelationExtractorEvaluation
           dataWriterFactoryClass,
           additionalParameters,
           trainingArguments);
-      List<AnnotationStatistics> foldStats = evaluation.crossValidation(trainFiles,
2);
-      params.stats = AnnotationStatistics.addAll(foldStats);
-
-      System.err.println("overall:");
-      System.err.print(params.stats);
-      System.err.println(params.stats.confusions());
-      System.err.println();
-
-      // store these parameter settings
-      scoredParams.put(params, params.stats.f1());
+      
+      if(options.testDirectory == null) {
+      	// run n-fold cross-validation
+      	List<AnnotationStatistics> foldStats = evaluation.crossValidation(trainFiles,
2);
+      	params.stats = AnnotationStatistics.addAll(foldStats);
+        
+      	System.err.println("overall:");
+        System.err.print(params.stats);
+        System.err.println(params.stats.confusions());
+        System.err.println();
+
+        // store these parameter settings
+        scoredParams.put(params, params.stats.f1());
+      } else {
+      	// train on the entire training set and evaluate on the test set
+      	List<File> testFiles = Arrays.asList(options.testDirectory.listFiles());
+      	
+      	CollectionReader trainCollectionReader = evaluation.getCollectionReader(trainFiles);
+      	evaluation.train(trainCollectionReader, modelsDir);
+      	
+      	CollectionReader testCollectionReader = evaluation.getCollectionReader(testFiles);
+      	AnnotationStatistics stats = evaluation.test(testCollectionReader, modelsDir);
+      	return;
+      }
     }
 
     // print parameters sorted by F1



Mime
View raw message