ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1731971 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/TemporalRelationExtractorAnnotator.java eval/EvaluationOfEventTimeRelations.java
Date Tue, 23 Feb 2016 21:54:18 GMT
Author: clin
Date: Tue Feb 23 21:54:18 2016
New Revision: 1731971

URL: http://svn.apache.org/viewvc?rev=1731971&view=rev
Log:
Encode class-wise weight automatically. Use this technique for ET temporal relations

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TemporalRelationExtractorAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TemporalRelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TemporalRelationExtractorAnnotator.java?rev=1731971&r1=1731970&r2=1731971&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TemporalRelationExtractorAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/TemporalRelationExtractorAnnotator.java
Tue Feb 23 21:54:18 2016
@@ -22,6 +22,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
@@ -66,6 +67,8 @@ public abstract class TemporalRelationEx
 
   public static final String PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE =
       "ProbabilityOfKeepingANegativeExample";
+  
+  public static Map<String, Integer> category_frequency = new LinkedHashMap<>();
 
   @ConfigurationParameter(
       name = PARAM_PROBABILITY_OF_KEEPING_A_NEGATIVE_EXAMPLE,
@@ -199,6 +202,12 @@ public abstract class TemporalRelationEx
             continue;
           }
 
+          //populate category_frequency count:
+          if(category_frequency.containsKey(category)){
+        	  category_frequency.put(category, category_frequency.get(category)+1);
+          }else{
+        	  category_frequency.put(category, 1);
+          }
           // create a classification instance and write it to the training data
           this.dataWriter.write(new Instance<>(category, features));
         }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java?rev=1731971&r1=1731970&r2=1731971&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
Tue Feb 23 21:54:18 2016
@@ -37,6 +37,7 @@ import java.util.Set;
 
 import org.apache.ctakes.relationextractor.eval.RelationExtractorEvaluation.HashableArguments;
 import org.apache.ctakes.temporal.ae.EventTimeSelfRelationAnnotator;
+import org.apache.ctakes.temporal.ae.TemporalRelationExtractorAnnotator;
 //import org.apache.ctakes.temporal.ae.EventTimeSyntacticAnnotator;
 //import org.apache.ctakes.temporal.ae.EventTimeRelationAnnotator;
 //import org.apache.ctakes.temporal.ae.EventEventRelationAnnotator;
@@ -353,9 +354,23 @@ EvaluationOfTemporalRelations_ImplBase{
 				optArray[i] = "-" + optArray[i];
 			}
 		}
+		
+		//calculate class-wise weights:
+		String[] weightArray=new String[TemporalRelationExtractorAnnotator.category_frequency.size()*2+2];
+		int weight_idx = 0;
+		float baseFreq = TemporalRelationExtractorAnnotator.category_frequency.get(TemporalRelationExtractorAnnotator.NO_RELATION_CATEGORY);
+		for( Map.Entry<String, Integer> entry: TemporalRelationExtractorAnnotator.category_frequency.entrySet()){
+			weightArray[weight_idx*2] = "-w"+Integer.toString(weight_idx + 1);
+			float weight = baseFreq/entry.getValue();
+			weightArray[weight_idx*2+1] = Float.toString(weight);
+			weight_idx ++;
+			System.err.println("Category:"+entry.getKey()+"  freq:"+entry.getValue() + "   weight:"+weight);
+		}
 
+		weightArray[weight_idx*2] = "-c";
+		weightArray[weight_idx*2+1] = optArray[1];
 		//    HideOutput hider = new HideOutput();
-		JarClassifierBuilder.trainAndPackage(new File(directory,"event-time"), "-w3","2","-w4","19","-w5","13","-w6","22","-w7","96","-w8","18","-c",
optArray[1]);//"-w3","2","-w4","19","-w5","13","-w6","22","-w7","96","-w8","18","-c", optArray[1]);//"-w4","18","-w5","14","-w6","21","-w7","100","-w8","19","-c",
optArray[1]);//"0.05");//"-h","0","-c", "1000");//optArray);
+		JarClassifierBuilder.trainAndPackage(new File(directory,"event-time"), weightArray);//"-w3","2","-w4","19","-w5","13","-w6","22","-w7","96","-w8","18"//"-w3","2","-w4","19","-w5","13","-w6","22","-w7","96","-w8","18","-c",
optArray[1]);//"-w4","18","-w5","14","-w6","21","-w7","100","-w8","19","-c", optArray[1]);//"0.05");//"-h","0","-c",
"1000");//optArray);
 		//		JarClassifierBuilder.trainAndPackage(new File(directory,"event-event"), "-h","0","-c",
"1000");
 		//    hider.restoreOutput();
 		//    hider.close();



Mime
View raw message