From be2f7b428b426b795049c5e71a2e78030a8d57ad Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 13:06:01 -0500 Subject: [PATCH 01/37] -added the Badge Example --- .../saulexamples/Badge/BadgeClassifiers.scala | 33 ++++++++ .../Badge/BadgeConstraintClassifiers.scala | 37 +++++++++ .../saulexamples/Badge/BadgeDataModel.scala | 40 ++++++++++ .../cogcomp/saulexamples/Badge/BagesApp.scala | 80 +++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala create mode 100644 saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala create mode 100644 saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala create mode 100644 saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala new file mode 100644 index 00000000..344599ab --- /dev/null +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -0,0 +1,33 @@ +package edu.illinois.cs.cogcomp.saulexamples.Badge + +import edu.illinois.cs.cogcomp.lbjava.learn.{ SparseNetworkLearner, SparsePerceptron } + +/** Created by Parisa on 9/13/16. + */ + +object BadgeClassifiers { + import BadgeDataModel._ + import edu.illinois.cs.cogcomp.saul.classifier.Learnable + object BadgeClassifier extends Learnable[String](badge) { + def label = BadgeLabel + override lazy val classifier = new SparsePerceptron() + override def feature = using(BadgeFeature1) + } + object BadgeOppositClassifier extends Learnable[String](badge) { + def label = BadgeOppositLabel + override lazy val classifier = new SparsePerceptron() + override def feature = using(BadgeFeature1) + } + + object BadgeClassifierMulti extends Learnable[String](badge) { + def label = BadgeLabel + override lazy val classifier = new SparseNetworkLearner() + override def feature = using(BadgeFeature1) + } + + object BadgeOppositClassifierMulti extends Learnable[String](badge) { + def label = BadgeOppositLabel + override lazy val classifier = new SparseNetworkLearner() + override def feature = using(BadgeFeature1) + } +} \ No newline at end of file diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala new file mode 100644 index 00000000..b613d94d --- /dev/null +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala @@ -0,0 +1,37 @@ +package edu.illinois.cs.cogcomp.saulexamples.Badge + +import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook +import edu.illinois.cs.cogcomp.saul.classifier.ConstrainedClassifier +import edu.illinois.cs.cogcomp.saul.constraint.ConstraintTypeConversion._ +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOppositClassifierMulti, BadgeClassifierMulti, BadgeClassifier, BadgeOppositClassifier } +import edu.illinois.cs.cogcomp.saulexamples.BasicClassifierWithRandomData.BinaryConstraints +/** Created by Parisa on 11/1/16. + */ +object BadgeConstraintClassifiers { + + val binaryConstraint = ConstrainedClassifier.constraint[String] { + x: String => + (BadgeClassifier on x is "negative") ==> (BadgeOppositClassifier on x is "positive") + } + + object badgeConstrainedClassifier extends ConstrainedClassifier[String, String](BadgeClassifier) { + def subjectTo = BinaryConstraints.binaryConstraint + override val solver = new OJalgoHook + } + + object oppositBadgeConstrainedClassifier extends ConstrainedClassifier[String, String](BadgeOppositClassifier) { + def subjectTo = BinaryConstraints.binaryConstraint + override val solver = new OJalgoHook + } + + object badgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeClassifierMulti) { + def subjectTo = BinaryConstraints.binaryConstraint + override val solver = new OJalgoHook + } + + object oppositBadgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeOppositClassifierMulti) { + def subjectTo = BinaryConstraints.binaryConstraint + override val solver = new OJalgoHook + } + +} diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala new file mode 100644 index 00000000..70d7a1bf --- /dev/null +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala @@ -0,0 +1,40 @@ +package edu.illinois.cs.cogcomp.saulexamples.Badge + +import edu.illinois.cs.cogcomp.saul.datamodel.DataModel + +/** Created by Parisa on 9/13/16. + */ +object BadgeDataModel extends DataModel { + + val badge = node[String] + + val BadgeFeature1 = property(badge) { + x: String => + { + val tokens = x.split(" ") + tokens(1).charAt(1).toString + } + } + + val BadgeLabel = property(badge)("true", "false") { + x: String => + { + val tokens = x.split(" ") + if (tokens(0).equals("+")) + "true" + else + "false" + } + } + + val BadgeOppositLabel = property(badge)("true", "false") { + x: String => + { + val tokens = x.split(" ") + if (tokens(0).equals("+")) + "false" + else + "true" + } + } +} diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala new file mode 100644 index 00000000..d0d37dcc --- /dev/null +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -0,0 +1,80 @@ +package edu.illinois.cs.cogcomp.saulexamples.Badge + +/** Created by Parisa on 9/13/16. + */ + +import edu.illinois.cs.cogcomp.saul.classifier.SL_model.StructuredLearning +import edu.illinois.cs.cogcomp.saul.classifier.{ClassifierUtils, JointTrain, JointTrainSparseNetwork} +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{BadgeOppositClassifier, BadgeClassifier} +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti} +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ + +import scala.collection.JavaConversions._ +object BadgesApp { + + val allNamesTrain = new BadgeReader("data/badges/badges.train").badges + val allNamesTest = new BadgeReader("data/badges/badges.test").badges + + badge.populate(allNamesTrain) + badge.populate(allNamesTest, false) + + val cls = List(badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifierMulti) + + object BadgeExperimentType extends Enumeration { + val JoinTrainSparsePerceptron, JointTrainSparseNetwork, JointTrainSparseNetworkLossAugmented, JoinTrainSL = Value + } + + def main(args: Array[String]): Unit = { + /** Choose the experiment you're interested in by changing the following line */ + val testType = BadgeExperimentType.JointTrainSparseNetworkLossAugmented + + testType match { + case BadgeExperimentType.JoinTrainSparsePerceptron => JoinTrainSparsePerceptron() + case BadgeExperimentType.JointTrainSparseNetwork => JoinTrainSparseNetwork() + case BadgeExperimentType.JointTrainSparseNetworkLossAugmented => LossAugmentedJoinTrainSparseNetwork() + case BadgeExperimentType.JoinTrainSL => JoinTrainSL() + } + } + + /*Test the join training with SparsePerceptron*/ + def JoinTrainSparsePerceptron(): Unit = { + BadgeClassifier.test() + BadgeOppositClassifier.test() + JointTrain.train(BadgeDataModel.badge, List(badgeConstrainedClassifier, oppositBadgeConstrainedClassifier), 5) + oppositBadgeConstrainedClassifier.test() + badgeConstrainedClassifier.test() + BadgeClassifier.test() + } + + /*Test the joinTraining with SparseNetwork*/ + def JoinTrainSparseNetwork(): Unit = { + + JointTrainSparseNetwork.train(badge, cls, 5, init = true) + + badgeConstrainedClassifierMulti.test() + oppositBadgeConstrainedClassifierMulti.test() + } + + /*Test the joinTraining with SparseNetwork and doing loss augmented inference*/ + def LossAugmentedJoinTrainSparseNetwork(): Unit = { + + JointTrainSparseNetwork.train(badge, cls, 5, init = true,lossAugmented = true) + + badgeConstrainedClassifierMulti.test() + oppositBadgeConstrainedClassifierMulti.test() + } + + /*Test the joinTraining with Structured output prediction in SL*/ + def JoinTrainSL(): Unit = { + + ClassifierUtils.InitializeClassifiers(badge, cls: _*) + val m = StructuredLearning(badge, cls, usePreTrained = false) + + badgeConstrainedClassifierMulti.test() + oppositBadgeConstrainedClassifier.test() + + StructuredLearning.Evaluate(badge, cls, m, "") + + } + +} \ No newline at end of file From b6acc3424fbdc6935fc405a6a7c675287c558d06 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 13:10:05 -0500 Subject: [PATCH 02/37] -added the Badge Example Reader --- .../saulexamples/Badge/BadgeReader.java | 27 +++++++++++++++++++ .../cogcomp/saulexamples/Badge/BagesApp.scala | 15 +---------- 2 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java new file mode 100644 index 00000000..6f1e0d47 --- /dev/null +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java @@ -0,0 +1,27 @@ +package edu.illinois.cs.cogcomp.saulexamples.Badge; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class BadgeReader { + public List badges; + // int currentBadge; + + public BadgeReader(String dataFile) { + badges = new ArrayList(); + + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile))); + + String str; + while ((str = br.readLine()) != null) { + badges.add(str); + } + + br.close(); + }catch (Exception e) {} + } +} \ No newline at end of file diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala index d0d37dcc..33401031 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -63,18 +63,5 @@ object BadgesApp { badgeConstrainedClassifierMulti.test() oppositBadgeConstrainedClassifierMulti.test() } - - /*Test the joinTraining with Structured output prediction in SL*/ - def JoinTrainSL(): Unit = { - - ClassifierUtils.InitializeClassifiers(badge, cls: _*) - val m = StructuredLearning(badge, cls, usePreTrained = false) - - badgeConstrainedClassifierMulti.test() - oppositBadgeConstrainedClassifier.test() - - StructuredLearning.Evaluate(badge, cls, m, "") - - } - + } \ No newline at end of file From 4d4d979da90a65762bac45d2bf56637a4b25421d Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 15:24:02 -0500 Subject: [PATCH 03/37] -added Badge example with loss augmented inference -added Bhargav's fix to the intialization --- .../classifier/JointTrainSparseNetwork.scala | 56 +++++++++++-------- .../classifier/infer/InitSparseNetwork.scala | 2 +- .../Badge/BadgeConstraintClassifiers.scala | 10 ++-- .../cogcomp/saulexamples/Badge/BagesApp.scala | 9 ++- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala index 4ac33f82..62924d19 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala @@ -18,16 +18,16 @@ object JointTrainSparseNetwork { val logger: Logger = LoggerFactory.getLogger(this.getClass) var difference = 0 - def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], init: Boolean)(implicit headTag: ClassTag[HEAD]) = { - train[HEAD](node, cls, 1, init) + def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], init: Boolean,lossAugmented: Boolean)(implicit headTag: ClassTag[HEAD]) = { + train[HEAD](node, cls, 1, init,lossAugmented) } - def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean)(implicit headTag: ClassTag[HEAD]) = { - train[HEAD](node, cls, it, init) + def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean=false)(implicit headTag: ClassTag[HEAD]) = { + train[HEAD](node, cls, it, init, lossAugmented) } @scala.annotation.tailrec - def train[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean)(implicit headTag: ClassTag[HEAD]): Unit = { + def train[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean=false)(implicit headTag: ClassTag[HEAD]): Unit = { // forall members in collection of the head (dm.t) do logger.info("Training iteration: " + it) if (init) ClassifierUtils.InitializeClassifiers(node, cls: _*) @@ -43,19 +43,24 @@ object JointTrainSparseNetwork { if (idx % 5000 == 0) logger.info(s"Training: $idx examples inferred.") - cls.foreach { - case classifier: ConstrainedClassifier[_, HEAD] => - val typedClassifier = classifier.asInstanceOf[ConstrainedClassifier[_, HEAD]] - val oracle = typedClassifier.onClassifier.getLabeler + if (lossAugmented) + cls.foreach{ cls_i => + cls_i.onClassifier.classifier.setLossFlag() + cls_i.onClassifier.classifier.setCandidates(cls_i.getCandidates(h).size * cls.size) + } - typedClassifier.getCandidates(h) foreach { + cls.foreach { + currentClassifier: ConstrainedClassifier[_, HEAD] => + val oracle = currentClassifier.onClassifier.getLabeler + val baseClassifier = currentClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner] + currentClassifier.getCandidates(h) foreach { candidate => { def trainOnce() = { - val result = typedClassifier.classifier.discreteValue(candidate) + + val result = currentClassifier.classifier.discreteValue(candidate) val trueLabel = oracle.discreteValue(candidate) - val ilearner = typedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner] - val lLexicon = typedClassifier.onClassifier.getLabelLexicon + val lLexicon = currentClassifier.onClassifier.getLabelLexicon var LTU_actual: Int = 0 var LTU_predicted: Int = 0 for (i <- 0 until lLexicon.size()) { @@ -69,26 +74,26 @@ object JointTrainSparseNetwork { // and the LTU of the predicted class should be demoted. if (!result.equals(trueLabel)) //equals("true") && trueLabel.equals("false") ) { - val a = typedClassifier.onClassifier.getExampleArray(candidate) + val a = currentClassifier.onClassifier.getExampleArray(candidate) val a0 = a(0).asInstanceOf[Array[Int]] //exampleFeatures val a1 = a(1).asInstanceOf[Array[Double]] // exampleValues val exampleLabels = a(2).asInstanceOf[Array[Int]] val label = exampleLabels(0) - var N = ilearner.getNetwork.size + var N = baseClassifier.getNetwork.size - if (label >= N || ilearner.getNetwork.get(label) == null) { - val conjugateLabels = ilearner.isUsingConjunctiveLabels | ilearner.getLabelLexicon.lookupKey(label).isConjunctive - ilearner.setConjunctiveLabels(conjugateLabels) + if (label >= N || baseClassifier.getNetwork.get(label) == null) { + val conjugateLabels = baseClassifier.isUsingConjunctiveLabels | baseClassifier.getLabelLexicon.lookupKey(label).isConjunctive + baseClassifier.setConjunctiveLabels(conjugateLabels) - val ltu: LinearThresholdUnit = ilearner.getBaseLTU - ltu.initialize(ilearner.getNumExamples, ilearner.getNumFeatures) - ilearner.getNetwork.set(label, ltu) + val ltu: LinearThresholdUnit = baseClassifier.getBaseLTU.clone().asInstanceOf[LinearThresholdUnit] + ltu.initialize(baseClassifier.getNumExamples, baseClassifier.getNumFeatures) + baseClassifier.getNetwork.set(label, ltu) N = label + 1 } // test push - val ltu_actual = ilearner.getLTU(LTU_actual).asInstanceOf[LinearThresholdUnit] - val ltu_predicted = ilearner.getLTU(LTU_predicted).asInstanceOf[LinearThresholdUnit] + val ltu_actual = baseClassifier.getLTU(LTU_actual).asInstanceOf[LinearThresholdUnit] + val ltu_predicted = baseClassifier.getLTU(LTU_predicted).asInstanceOf[LinearThresholdUnit] if (ltu_actual != null) ltu_actual.promote(a0, a1, 0.1) @@ -100,8 +105,13 @@ object JointTrainSparseNetwork { trainOnce() } } + } } + if (lossAugmented) + cls.foreach{ cls_i => + cls_i.onClassifier.classifier.unsetLossFlag() + } } train(node, cls, it - 1, false) } diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala index a9df6c4c..b96605ed 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala @@ -33,7 +33,7 @@ object InitSparseNetwork { if (label >= N || iLearner.getNetwork.get(label) == null) { val isConjunctiveLabels = iLearner.isUsingConjunctiveLabels | iLearner.getLabelLexicon.lookupKey(label).isConjunctive iLearner.setConjunctiveLabels(isConjunctiveLabels) - val ltu: LinearThresholdUnit = iLearner.getBaseLTU + val ltu: LinearThresholdUnit = iLearner.getBaseLTU.clone().asInstanceOf[LinearThresholdUnit] ltu.initialize(iLearner.getNumExamples, iLearner.getNumFeatures) iLearner.getNetwork.set(label, ltu) } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala index b613d94d..88e4f768 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala @@ -4,7 +4,7 @@ import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook import edu.illinois.cs.cogcomp.saul.classifier.ConstrainedClassifier import edu.illinois.cs.cogcomp.saul.constraint.ConstraintTypeConversion._ import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOppositClassifierMulti, BadgeClassifierMulti, BadgeClassifier, BadgeOppositClassifier } -import edu.illinois.cs.cogcomp.saulexamples.BasicClassifierWithRandomData.BinaryConstraints + /** Created by Parisa on 11/1/16. */ object BadgeConstraintClassifiers { @@ -15,22 +15,22 @@ object BadgeConstraintClassifiers { } object badgeConstrainedClassifier extends ConstrainedClassifier[String, String](BadgeClassifier) { - def subjectTo = BinaryConstraints.binaryConstraint + def subjectTo = binaryConstraint override val solver = new OJalgoHook } object oppositBadgeConstrainedClassifier extends ConstrainedClassifier[String, String](BadgeOppositClassifier) { - def subjectTo = BinaryConstraints.binaryConstraint + def subjectTo = binaryConstraint override val solver = new OJalgoHook } object badgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeClassifierMulti) { - def subjectTo = BinaryConstraints.binaryConstraint + def subjectTo = binaryConstraint override val solver = new OJalgoHook } object oppositBadgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeOppositClassifierMulti) { - def subjectTo = BinaryConstraints.binaryConstraint + def subjectTo = binaryConstraint override val solver = new OJalgoHook } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala index 33401031..0f0c81e9 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -3,8 +3,7 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge /** Created by Parisa on 9/13/16. */ -import edu.illinois.cs.cogcomp.saul.classifier.SL_model.StructuredLearning -import edu.illinois.cs.cogcomp.saul.classifier.{ClassifierUtils, JointTrain, JointTrainSparseNetwork} +import edu.illinois.cs.cogcomp.saul.classifier.{JointTrain, JointTrainSparseNetwork} import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{BadgeOppositClassifier, BadgeClassifier} import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti} import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ @@ -21,10 +20,11 @@ object BadgesApp { val cls = List(badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifierMulti) object BadgeExperimentType extends Enumeration { - val JoinTrainSparsePerceptron, JointTrainSparseNetwork, JointTrainSparseNetworkLossAugmented, JoinTrainSL = Value + val JoinTrainSparsePerceptron, JointTrainSparseNetwork, JointTrainSparseNetworkLossAugmented = Value } def main(args: Array[String]): Unit = { + /** Choose the experiment you're interested in by changing the following line */ val testType = BadgeExperimentType.JointTrainSparseNetworkLossAugmented @@ -32,8 +32,7 @@ object BadgesApp { case BadgeExperimentType.JoinTrainSparsePerceptron => JoinTrainSparsePerceptron() case BadgeExperimentType.JointTrainSparseNetwork => JoinTrainSparseNetwork() case BadgeExperimentType.JointTrainSparseNetworkLossAugmented => LossAugmentedJoinTrainSparseNetwork() - case BadgeExperimentType.JoinTrainSL => JoinTrainSL() - } + } } /*Test the join training with SparsePerceptron*/ From 75a071ee4b5e683b57262b60bea99fca647487ac Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 15:24:42 -0500 Subject: [PATCH 04/37] -format --- .../classifier/JointTrainSparseNetwork.scala | 24 +++++++++---------- .../cogcomp/saulexamples/Badge/BagesApp.scala | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala index 62924d19..7ef0d87a 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala @@ -18,16 +18,16 @@ object JointTrainSparseNetwork { val logger: Logger = LoggerFactory.getLogger(this.getClass) var difference = 0 - def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], init: Boolean,lossAugmented: Boolean)(implicit headTag: ClassTag[HEAD]) = { - train[HEAD](node, cls, 1, init,lossAugmented) + def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], init: Boolean, lossAugmented: Boolean)(implicit headTag: ClassTag[HEAD]) = { + train[HEAD](node, cls, 1, init, lossAugmented) } - def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean=false)(implicit headTag: ClassTag[HEAD]) = { + def apply[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean = false)(implicit headTag: ClassTag[HEAD]) = { train[HEAD](node, cls, it, init, lossAugmented) } @scala.annotation.tailrec - def train[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean=false)(implicit headTag: ClassTag[HEAD]): Unit = { + def train[HEAD <: AnyRef](node: Node[HEAD], cls: List[ConstrainedClassifier[_, HEAD]], it: Int, init: Boolean, lossAugmented: Boolean = false)(implicit headTag: ClassTag[HEAD]): Unit = { // forall members in collection of the head (dm.t) do logger.info("Training iteration: " + it) if (init) ClassifierUtils.InitializeClassifiers(node, cls: _*) @@ -44,10 +44,10 @@ object JointTrainSparseNetwork { logger.info(s"Training: $idx examples inferred.") if (lossAugmented) - cls.foreach{ cls_i => - cls_i.onClassifier.classifier.setLossFlag() - cls_i.onClassifier.classifier.setCandidates(cls_i.getCandidates(h).size * cls.size) - } + cls.foreach { cls_i => + cls_i.onClassifier.classifier.setLossFlag() + cls_i.onClassifier.classifier.setCandidates(cls_i.getCandidates(h).size * cls.size) + } cls.foreach { currentClassifier: ConstrainedClassifier[_, HEAD] => @@ -108,10 +108,10 @@ object JointTrainSparseNetwork { } } - if (lossAugmented) - cls.foreach{ cls_i => - cls_i.onClassifier.classifier.unsetLossFlag() - } + if (lossAugmented) + cls.foreach { cls_i => + cls_i.onClassifier.classifier.unsetLossFlag() + } } train(node, cls, it - 1, false) } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala index 0f0c81e9..3b8d129e 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -3,9 +3,9 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge /** Created by Parisa on 9/13/16. */ -import edu.illinois.cs.cogcomp.saul.classifier.{JointTrain, JointTrainSparseNetwork} -import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{BadgeOppositClassifier, BadgeClassifier} -import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti} +import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrain, JointTrainSparseNetwork } +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOppositClassifier, BadgeClassifier } +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{ badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ import scala.collection.JavaConversions._ @@ -32,7 +32,7 @@ object BadgesApp { case BadgeExperimentType.JoinTrainSparsePerceptron => JoinTrainSparsePerceptron() case BadgeExperimentType.JointTrainSparseNetwork => JoinTrainSparseNetwork() case BadgeExperimentType.JointTrainSparseNetworkLossAugmented => LossAugmentedJoinTrainSparseNetwork() - } + } } /*Test the join training with SparsePerceptron*/ @@ -57,10 +57,10 @@ object BadgesApp { /*Test the joinTraining with SparseNetwork and doing loss augmented inference*/ def LossAugmentedJoinTrainSparseNetwork(): Unit = { - JointTrainSparseNetwork.train(badge, cls, 5, init = true,lossAugmented = true) + JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true) badgeConstrainedClassifierMulti.test() oppositBadgeConstrainedClassifierMulti.test() } - + } \ No newline at end of file From e1a106ebca17796c2def470bb7c986b95759c63f Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 15:27:45 -0500 Subject: [PATCH 05/37] -fixed the test --- .../JoinTrainingTests/IntializeSparseNetwork.scala | 8 +++++++- .../cs/cogcomp/saulexamples/Badge/BadgeReader.java | 6 ++++++ .../cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala | 6 ++++++ .../saulexamples/Badge/BadgeConstraintClassifiers.scala | 6 ++++++ .../cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala | 6 ++++++ .../illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala | 6 ++++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/saul-core/src/test/scala/edu/illinois/cs/cogcomp/saul/classifier/JoinTrainingTests/IntializeSparseNetwork.scala b/saul-core/src/test/scala/edu/illinois/cs/cogcomp/saul/classifier/JoinTrainingTests/IntializeSparseNetwork.scala index 605d03ba..cc284619 100644 --- a/saul-core/src/test/scala/edu/illinois/cs/cogcomp/saul/classifier/JoinTrainingTests/IntializeSparseNetwork.scala +++ b/saul-core/src/test/scala/edu/illinois/cs/cogcomp/saul/classifier/JoinTrainingTests/IntializeSparseNetwork.scala @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saul.classifier.JoinTrainingTests import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook @@ -71,7 +77,7 @@ class InitializeSparseNetwork extends FlatSpec with Matchers { val wv1After = clNet1.getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector val wv2After = clNet2.getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector - wv1After.size() should be(5) + wv1After.size() should be(6) wv2After.size() should be(12) } diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java index 6f1e0d47..d016e802 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge; import java.io.BufferedReader; diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index 344599ab..ea6252f2 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge import edu.illinois.cs.cogcomp.lbjava.learn.{ SparseNetworkLearner, SparsePerceptron } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala index 88e4f768..fcd59d5f 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala index 70d7a1bf..19420d98 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge import edu.illinois.cs.cogcomp.saul.datamodel.DataModel diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala index 3b8d129e..1d2bf51b 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -1,3 +1,9 @@ +/** This software is released under the University of Illinois/Research and Academic Use License. See + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge /** Created by Parisa on 9/13/16. From 9f40b241e8b9dfceea199e136bb53ae491871efa Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 15:57:36 -0500 Subject: [PATCH 06/37] -fixed the tests due to the fix in initialization --- .../saulexamples/nlp/EntityRelation/EntityRelationTests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala b/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala index 298fe7eb..522b6dff 100644 --- a/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala +++ b/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala @@ -92,14 +92,14 @@ class EntityRelationTests extends FlatSpec with Matchers { ClassifierUtils.TrainClassifiers(1, cls_base) - PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(1660) + PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(1654) val jointTrainIteration = 1 JointTrainSparseNetwork.train[ConllRelation]( pairs, cls, jointTrainIteration, init = true ) - PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(50) + PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(81) } } \ No newline at end of file From 4a578c468bc23eb8f324c19ce9b39c58a83b82de Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 17:18:53 -0500 Subject: [PATCH 07/37] -test size of weights --- .../nlp/EntityRelation/EntityRelationTests.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala b/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala index 522b6dff..3ce4f58a 100644 --- a/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala +++ b/saul-examples/src/test/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/EntityRelation/EntityRelationTests.scala @@ -94,10 +94,8 @@ class EntityRelationTests extends FlatSpec with Matchers { PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(1654) - val jointTrainIteration = 1 - JointTrainSparseNetwork.train[ConllRelation]( - pairs, cls, jointTrainIteration, init = true - ) + val jointTrainIteration = 2 + JointTrainSparseNetwork.train[ConllRelation](pairs, cls, jointTrainIteration, init = true) PerConstrainedClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner].getNetwork.get(0).asInstanceOf[LinearThresholdUnit].getWeightVector.size() should be(81) From cd57748c4f2c17fccaa5f2e214a6d8782ffffde4 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 4 Nov 2016 19:10:46 -0500 Subject: [PATCH 08/37] learning configuration --- README.md | 1 - saul-core/doc/MODELS.md | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9dad706e..a4b05394 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ Visit each link for its content 5. [Data modeling and feature extraction](saul-core/doc/DATAMODELING.md) 6. [Learners and constraints](saul-core/doc/SAULLANGUAGE.md) 7. [Model configurations](saul-core/doc/MODELS.md) - 8. [Saul library](saul-core/doc/LBJLIBRARY.md) The api docs are included [here](http://cogcomp.cs.illinois.edu/software/doc/saul/). diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index cfdacadf..83b43e50 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -1,6 +1,15 @@ -* Designing flexible learning models including various configurations such as: +Designing flexible learning models including various configurations such as: - * Local models i.e. single classifiers. (Learning only models (LO)). - * Constrained conditional models (CCM)[1] for training independent classifiers and using them jointly for global decision making in prediction time. (Learning+Inference (L+I)). - * Global models for joint training and joint inference (Inference-Based-Training (IBT)). - * Pipeline models for complex problems where the output of each layer is used as the input of the next layer. + * [Local models](#local) i.e. single classifiers. (Learning only models (LO)). + * [Constrained conditional models (CCM)](#L+I)[1] for training independent classifiers and using them jointly for global decision making in prediction time. (Learning+Inference (L+I)). + * [Global models](#IBT) for joint training and joint inference (Inference-Based-Training (IBT)). + * [Pipeline models](#pipeline) for complex problems where the output of each layer is used as the input of the next layer. + + +##Local models. + +##Learning+Inference models. + +##Inference-based Learning. + +##Pipelines. \ No newline at end of file From 09f4aaa8ee787661baebc3cce2bcf3c667c353b6 Mon Sep 17 00:00:00 2001 From: kordjam Date: Sat, 5 Nov 2016 09:54:45 -0500 Subject: [PATCH 09/37] -added documentation -fixed some indentation -one renaming --- saul-core/doc/MODELS.md | 88 ++++++++++++++++++- ...scala => JointTrainSparsePerceptron.scala} | 2 +- .../saulexamples/Badge/BadgeReader.java | 35 ++++---- .../saulexamples/Badge/BadgeClassifiers.scala | 8 +- .../cogcomp/saulexamples/Badge/BagesApp.scala | 4 +- .../cs/cogcomp/saulexamples/Badge/README.md | 4 + 6 files changed, 115 insertions(+), 26 deletions(-) rename saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/{JointTrain.scala => JointTrainSparsePerceptron.scala} (99%) create mode 100644 saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 83b43e50..9ae4eab5 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -1,3 +1,6 @@ + +//Documented by Parisa Kordjamshidi + Designing flexible learning models including various configurations such as: * [Local models](#local) i.e. single classifiers. (Learning only models (LO)). @@ -5,11 +8,94 @@ Designing flexible learning models including various configurations such as: * [Global models](#IBT) for joint training and joint inference (Inference-Based-Training (IBT)). * [Pipeline models](#pipeline) for complex problems where the output of each layer is used as the input of the next layer. +The above mentioned paradigms can be tested using this simple badge classifier example, [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala). ##Local models. +These models are classic classifiers. They are defined with the `Learnable` construct. This construct requires specifying + the name of a single output variable, that is, a label which is itself a property in the data model, and the features which is also a + comma separated list of properties. + + ```scala + object ClassifierName extends Learnable (node) { + def label = property1 + def feature = using(property2,property3,...) + //a comma separated list of properties + } + ``` + + For the details about the `Learnable` construct see [here](SAULLANGUAGE.md). + ##Learning+Inference models. +These models are useful for when we need to consider the global relations between the outputs of a bunch of classifiers during the +prediction time. Each classifier is defined with the same `Learnable` construct as a local model. In addition to the Learnable definitions, the programmer +has the possibility to define a number of logical constraints between the output of the classifiers. +Having the constraint definitions in place (see [here](SAULLANGUAGE.md) for syntax details), the programmer is able to define +new constraint classifiers that use the Learnables and constraints. + +```scala +object ConstraintClassifierName extends ConstraintClassifier[local_node,global_node](DataModelName, localClassifier_Name) + { + def subjectTo = constraintExpression + // Logical constraint expression comes here, it defines the relations between the + // localClassifier_Name and other Learnables defined before + } + ``` +When we use the above `ConstraintClassifierName` to call test or make predictions, the `localClassifier_Name` is used +but the predictions are made in way that `constraintExpression` is hold. There is no limitation for the type of local classifiers. +They can be SVMs, decision trees or any other learning models available in Saul, [here](https://github.com/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) + and [here](https://github.com/IllinoisCogComp/saul/blob/master/saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md). + ##Inference-based Learning. + +For the inference based models the basic definitions are exactly similar to the L+I models. In other words, the programmer +just needs to define the `Learnables` and `ConstrainedClassifiers`. However, to train the ConstrainedClassifiers jointly, instead of +training local classifiers independently, there are a couple of joint training functions that can be called. +These functions receive the list of constrained classifiers as input and train their parameters jointly. In contrast to +L+I models here the local classifiers can be defined as `SparsePerceptrons` or `SparseNetworks` only. This is because the +joint training should have its own strategy for the wight updates of the involved variables (those variables come down to be the outputs of the local classifiers here). +For the two cases the programmer can use + +```scala + JointTrainSparseNetwork.train(param1,param2,...) /* a list of parameters go here*/ + JointTrainSparsePerceptron.train(param1,param2,...) /*a list of parameters here*/ +``` + + JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true) + +The list of parameters are the following: + +-param1: The name of a global node in the data model that itself or the connected nodes to it are used by the involved `Learnable`s. + +-param2: The list of ConstainedClassifiers + +-param3: The number of iterations over the training data. + +-param4: If the local classifiers should be cleaned from the possibly pre-trained values and initialized by zero weights, this parameter should be true. + +-param5: If the approach uses the loss augmented objective for making inference, see below for description. + +###Basic approach + +The Basic approach for training the models jointly is to do a global prediction at each step of the training and if the +predictions are wrong update the weights of the related variables. + +###Loss augmented + +The loss-augmented approach adds the loss of the prediction explicitly to the objective of the training and finds the most violated output; +it updates the weights of the model according to the errors made in the most violated output. +This is an approach that is used in structured SVMs and Structured Perceptrons. However, considering an arbitrary loss in the objective +will make complexities in the optimization, therefore in the implemented version, here, we assume the loss is decomposed similar to +feature function. That is, the loss is a hamming loss defined per classifier. The loss of the whole output will be the weighted sum of + the all predicted components of the output structure. + In Saul, the programmer can indicate if he/she needs to consider this global hamming loss in the objective or not. And this can be done by passing + the above mentioned `param5` as true in the `JointTrainingSparseNetwork` algorithm. + -##Pipelines. \ No newline at end of file +##Pipelines. +Building pipelines is naturally granted in Saul. The programmer can simply define properties that are the predictions of +the classifiers and use those outputs as the input of other classifiers by mentioning them in the list of the features. + + + diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrain.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparsePerceptron.scala similarity index 99% rename from saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrain.scala rename to saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparsePerceptron.scala index 2f046380..4b70d89e 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrain.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparsePerceptron.scala @@ -14,7 +14,7 @@ import scala.reflect.ClassTag /** Created by parisakordjamshidi on 29/01/15. */ -object JointTrain { +object JointTrainSparsePerceptron { def testClassifiers(cls: Classifier, oracle: Classifier, ds: List[AnyRef]): Unit = { val results = ds.map({ diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java index d016e802..184d2c85 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java @@ -1,9 +1,9 @@ /** This software is released under the University of Illinois/Research and Academic Use License. See - * the LICENSE file in the root folder for details. Copyright (c) 2016 - * - * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign - * http://cogcomp.cs.illinois.edu/ - */ + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge; import java.io.BufferedReader; @@ -13,21 +13,20 @@ import java.util.List; public class BadgeReader { - public List badges; - // int currentBadge; + public List badges; - public BadgeReader(String dataFile) { - badges = new ArrayList(); + public BadgeReader(String dataFile) { + badges = new ArrayList(); - try { - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile))); + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile))); - String str; - while ((str = br.readLine()) != null) { - badges.add(str); - } + String str; + while ((str = br.readLine()) != null) { + badges.add(str); + } - br.close(); - }catch (Exception e) {} - } + br.close(); + }catch (Exception e) {} + } } \ No newline at end of file diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index ea6252f2..c5b073b2 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -6,14 +6,14 @@ */ package edu.illinois.cs.cogcomp.saulexamples.Badge -import edu.illinois.cs.cogcomp.lbjava.learn.{ SparseNetworkLearner, SparsePerceptron } - +import edu.illinois.cs.cogcomp.lbjava.learn.{SparseNetworkLearner, SparsePerceptron} +import edu.illinois.cs.cogcomp.saul.classifier.Learnable +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ /** Created by Parisa on 9/13/16. */ object BadgeClassifiers { - import BadgeDataModel._ - import edu.illinois.cs.cogcomp.saul.classifier.Learnable + object BadgeClassifier extends Learnable[String](badge) { def label = BadgeLabel override lazy val classifier = new SparsePerceptron() diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala index 1d2bf51b..36949bfc 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala @@ -9,7 +9,7 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge /** Created by Parisa on 9/13/16. */ -import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrain, JointTrainSparseNetwork } +import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrainSparsePerceptron, JointTrainSparseNetwork } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOppositClassifier, BadgeClassifier } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{ badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ @@ -45,7 +45,7 @@ object BadgesApp { def JoinTrainSparsePerceptron(): Unit = { BadgeClassifier.test() BadgeOppositClassifier.test() - JointTrain.train(BadgeDataModel.badge, List(badgeConstrainedClassifier, oppositBadgeConstrainedClassifier), 5) + JointTrainSparsePerceptron.train(BadgeDataModel.badge, List(badgeConstrainedClassifier, oppositBadgeConstrainedClassifier), 5) oppositBadgeConstrainedClassifier.test() badgeConstrainedClassifier.test() BadgeClassifier.test() diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md new file mode 100644 index 00000000..1ceb9151 --- /dev/null +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md @@ -0,0 +1,4 @@ + +This example is a simple model, that receives names of people and assigns a label either positive or negative to them. +It uses the second character of the first names as an input feature. This is a gold feature that can distinguish 100% between +the positive and negative class. From bca4262226347ba7eec871629c4a239e134c6e1a Mon Sep 17 00:00:00 2001 From: kordjam Date: Sat, 5 Nov 2016 10:20:58 -0500 Subject: [PATCH 10/37] -modified and documented the badge example --- .../cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala | 9 ++++++--- .../saulexamples/Badge/BadgeConstraintClassifiers.scala | 8 ++++++-- .../edu/illinois/cs/cogcomp/saulexamples/Badge/README.md | 5 +++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index c5b073b2..a13601f4 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -6,7 +6,7 @@ */ package edu.illinois.cs.cogcomp.saulexamples.Badge -import edu.illinois.cs.cogcomp.lbjava.learn.{SparseNetworkLearner, SparsePerceptron} +import edu.illinois.cs.cogcomp.lbjava.learn.{ SparseNetworkLearner, SparsePerceptron } import edu.illinois.cs.cogcomp.saul.classifier.Learnable import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ /** Created by Parisa on 9/13/16. @@ -14,23 +14,26 @@ import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ object BadgeClassifiers { + /*a binary classifier that predicts the badge label*/ object BadgeClassifier extends Learnable[String](badge) { def label = BadgeLabel override lazy val classifier = new SparsePerceptron() override def feature = using(BadgeFeature1) } + /*a binary classifier that predicts a lable that is exactly the opposite of the badge label of the BadgeClassifier*/ object BadgeOppositClassifier extends Learnable[String](badge) { def label = BadgeOppositLabel override lazy val classifier = new SparsePerceptron() override def feature = using(BadgeFeature1) } - + /*This is a multi-class classifier version of the above binary BadgeClassifier, +it uses SparseNetworks instead of SparsePerceptrons*/ object BadgeClassifierMulti extends Learnable[String](badge) { def label = BadgeLabel override lazy val classifier = new SparseNetworkLearner() override def feature = using(BadgeFeature1) } - + /*This is the opposite multi-class classifier of the BadgeClassifierMulti */ object BadgeOppositClassifierMulti extends Learnable[String](badge) { def label = BadgeOppositLabel override lazy val classifier = new SparseNetworkLearner() diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala index fcd59d5f..62fa6638 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala @@ -20,6 +20,10 @@ object BadgeConstraintClassifiers { (BadgeClassifier on x is "negative") ==> (BadgeOppositClassifier on x is "positive") } + val binaryConstraintOverMultiClassifiers = ConstrainedClassifier.constraint[String] { + x: String => + (BadgeClassifierMulti on x is "negative") ==> (BadgeOppositClassifierMulti on x is "positive") + } object badgeConstrainedClassifier extends ConstrainedClassifier[String, String](BadgeClassifier) { def subjectTo = binaryConstraint override val solver = new OJalgoHook @@ -31,12 +35,12 @@ object BadgeConstraintClassifiers { } object badgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeClassifierMulti) { - def subjectTo = binaryConstraint + def subjectTo = binaryConstraintOverMultiClassifiers override val solver = new OJalgoHook } object oppositBadgeConstrainedClassifierMulti extends ConstrainedClassifier[String, String](BadgeOppositClassifierMulti) { - def subjectTo = binaryConstraint + def subjectTo = binaryConstraintOverMultiClassifiers override val solver = new OJalgoHook } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md index 1ceb9151..71a0d5be 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/README.md @@ -2,3 +2,8 @@ This example is a simple model, that receives names of people and assigns a label either positive or negative to them. It uses the second character of the first names as an input feature. This is a gold feature that can distinguish 100% between the positive and negative class. +We show the usage of binary classifiers as well as multi-class classifiers in [here](BadgeClassifiers.scala). +In this file you could see we define two type of the classifiers that they take opposite labels. The goal is to simply show +how a simple constraint can impose the predictions of these two classifiers to be opposite. +The constrained versions of all these classifiers can be found [here](BadgeConstraintClassifiers.scala). +Using a simple constraint we train various joint models that train the two opposite classifiers jointly in [here](BadgesApp.scala). \ No newline at end of file From ea0198b3de8e60066a0d77c8daf74cb5e776ad1a Mon Sep 17 00:00:00 2001 From: kordjam Date: Sat, 5 Nov 2016 22:19:58 -0500 Subject: [PATCH 11/37] -assert the type -remove redundant assignment --- .../saul/classifier/JointTrainSparseNetwork.scala | 6 +++--- .../saul/classifier/infer/InitSparseNetwork.scala | 3 +++ .../cs/cogcomp/saulexamples/Badge/BadgeReader.java | 10 +++++----- .../cogcomp/saulexamples/Badge/BadgeClassifiers.scala | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala index 7ef0d87a..e114fadf 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/JointTrainSparseNetwork.scala @@ -9,7 +9,7 @@ package edu.illinois.cs.cogcomp.saul.classifier import edu.illinois.cs.cogcomp.lbjava.learn.{ LinearThresholdUnit, SparseNetworkLearner } import edu.illinois.cs.cogcomp.saul.datamodel.node.Node import org.slf4j.{ Logger, LoggerFactory } - +import Predef._ import scala.reflect.ClassTag /** Created by Parisa on 5/22/15. @@ -51,6 +51,7 @@ object JointTrainSparseNetwork { cls.foreach { currentClassifier: ConstrainedClassifier[_, HEAD] => + assert(currentClassifier.onClassifier.classifier.getClass.getName.contains("SparseNetworkLearner"), "The classifier should be of type SparseNetworkLearner!") val oracle = currentClassifier.onClassifier.getLabeler val baseClassifier = currentClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner] currentClassifier.getCandidates(h) foreach { @@ -79,7 +80,7 @@ object JointTrainSparseNetwork { val a1 = a(1).asInstanceOf[Array[Double]] // exampleValues val exampleLabels = a(2).asInstanceOf[Array[Int]] val label = exampleLabels(0) - var N = baseClassifier.getNetwork.size + val N = baseClassifier.getNetwork.size if (label >= N || baseClassifier.getNetwork.get(label) == null) { val conjugateLabels = baseClassifier.isUsingConjunctiveLabels | baseClassifier.getLabelLexicon.lookupKey(label).isConjunctive @@ -88,7 +89,6 @@ object JointTrainSparseNetwork { val ltu: LinearThresholdUnit = baseClassifier.getBaseLTU.clone().asInstanceOf[LinearThresholdUnit] ltu.initialize(baseClassifier.getNumExamples, baseClassifier.getNumFeatures) baseClassifier.getNetwork.set(label, ltu) - N = label + 1 } // test push diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala index b96605ed..d1f738fe 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/infer/InitSparseNetwork.scala @@ -18,7 +18,10 @@ object InitSparseNetwork { //this means we are not reading any model into the SparseNetworks // but we forget all the models and go over the data to build the right // size for the lexicon and the right number of the ltu s + cClassifier.onClassifier.classifier.forget() + assert(cClassifier.onClassifier.classifier.getClass.getName.contains("SparseNetworkLearner"), "The classifier should be of type SparseNetworkLearner!") + val iLearner = cClassifier.onClassifier.classifier.asInstanceOf[SparseNetworkLearner] allHeads.foreach { head => diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java index 184d2c85..456f5e6f 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeReader.java @@ -1,9 +1,9 @@ /** This software is released under the University of Illinois/Research and Academic Use License. See - * the LICENSE file in the root folder for details. Copyright (c) 2016 - * - * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign - * http://cogcomp.cs.illinois.edu/ - */ + * the LICENSE file in the root folder for details. Copyright (c) 2016 + * + * Developed by: The Cognitive Computations Group, University of Illinois at Urbana-Champaign + * http://cogcomp.cs.illinois.edu/ + */ package edu.illinois.cs.cogcomp.saulexamples.Badge; import java.io.BufferedReader; diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index a13601f4..a582b6c2 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -30,7 +30,7 @@ object BadgeClassifiers { it uses SparseNetworks instead of SparsePerceptrons*/ object BadgeClassifierMulti extends Learnable[String](badge) { def label = BadgeLabel - override lazy val classifier = new SparseNetworkLearner() + override lazy val classifier = new SparsePerceptron() override def feature = using(BadgeFeature1) } /*This is the opposite multi-class classifier of the BadgeClassifierMulti */ From ed706a36fe194f37bbad92849a1ee858107c704e Mon Sep 17 00:00:00 2001 From: kordjam Date: Sat, 5 Nov 2016 22:20:48 -0500 Subject: [PATCH 12/37] -minor --- .../cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index a582b6c2..a13601f4 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -30,7 +30,7 @@ object BadgeClassifiers { it uses SparseNetworks instead of SparsePerceptrons*/ object BadgeClassifierMulti extends Learnable[String](badge) { def label = BadgeLabel - override lazy val classifier = new SparsePerceptron() + override lazy val classifier = new SparseNetworkLearner() override def feature = using(BadgeFeature1) } /*This is the opposite multi-class classifier of the BadgeClassifierMulti */ From da9b768b892452d96ed2c57f6df92fb0bd3434fa Mon Sep 17 00:00:00 2001 From: kordjam Date: Thu, 10 Nov 2016 17:29:55 -0600 Subject: [PATCH 13/37] -added pipeline example with Badge - Improved documentation. --- saul-core/doc/MODELS.md | 25 +++++++++++++------ .../saulexamples/Badge/BadgeClassifiers.scala | 6 +++++ .../saulexamples/Badge/BadgeDataModel.scala | 8 ++++++ .../Badge/{BagesApp.scala => BadgesApp.scala} | 16 +++++++++--- 4 files changed, 44 insertions(+), 11 deletions(-) rename saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/{BagesApp.scala => BadgesApp.scala} (84%) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 9ae4eab5..f61daf92 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -78,24 +78,33 @@ The list of parameters are the following: ###Basic approach -The Basic approach for training the models jointly is to do a global prediction at each step of the training and if the +The basic approach for training the models jointly is to do a global prediction at each step of the training and if the predictions are wrong update the weights of the related variables. ###Loss augmented -The loss-augmented approach adds the loss of the prediction explicitly to the objective of the training and finds the most violated output; -it updates the weights of the model according to the errors made in the most violated output. -This is an approach that is used in structured SVMs and Structured Perceptrons. However, considering an arbitrary loss in the objective -will make complexities in the optimization, therefore in the implemented version, here, we assume the loss is decomposed similar to -feature function. That is, the loss is a hamming loss defined per classifier. The loss of the whole output will be the weighted sum of - the all predicted components of the output structure. +The loss-augmented approach adds the loss of the prediction explicitly to the objective of the training and finds the most violated output per each training example; +it updates the weights of the model according to the errors made in the prediction of the most violated output. +This approach minimizes a convex upper bound of the loss function and has been used in structured SVMs and Structured Perceptrons. + However, considering an arbitrary loss in the objective will make complexities in the optimization, therefore in the implemented version, here, we assume the loss is decomposed similar to +feature function. That is, the loss is a hamming loss defined per classifier. The loss of the whole structured output is computed by the weighted sum of + the loss of its components. In Saul, the programmer can indicate if he/she needs to consider this global hamming loss in the objective or not. And this can be done by passing the above mentioned `param5` as true in the `JointTrainingSparseNetwork` algorithm. + An example of this usage can be seen [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala) at line #64. ##Pipelines. Building pipelines is naturally granted in Saul. The programmer can simply define properties that are the predictions of -the classifiers and use those outputs as the input of other classifiers by mentioning them in the list of the features. +the classifiers and use those outputs as the input of other classifiers by mentioning them in the list of the properties in the below construct when defining the +pipeline classifiers, + +```scala +def feature = using(/*list of properties including the prediction of other classifiers.*/) +``` +. +See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala), at line #43, for an example. + diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala index a13601f4..d9febc2b 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala @@ -39,4 +39,10 @@ it uses SparseNetworks instead of SparsePerceptrons*/ override lazy val classifier = new SparseNetworkLearner() override def feature = using(BadgeFeature1) } + /* */ + object BadgeOppositPipeline extends Learnable[String](badge) { + def label = BadgeOppositLabel + override lazy val classifier = new SparsePerceptron() + override def feature = using(BadgePrediction) + } } \ No newline at end of file diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala index 19420d98..b161dbcb 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala @@ -7,6 +7,7 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge import edu.illinois.cs.cogcomp.saul.datamodel.DataModel +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.BadgeClassifier /** Created by Parisa on 9/13/16. */ @@ -43,4 +44,11 @@ object BadgeDataModel extends DataModel { "true" } } + + val BadgePrediction = property(badge)("true", "false") { + x: String => + { + BadgeClassifier(x) + } + } } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala similarity index 84% rename from saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala rename to saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala index 36949bfc..965b90a4 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala @@ -10,7 +10,7 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge */ import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrainSparsePerceptron, JointTrainSparseNetwork } -import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOppositClassifier, BadgeClassifier } +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers._ import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{ badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ @@ -26,18 +26,19 @@ object BadgesApp { val cls = List(badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifierMulti) object BadgeExperimentType extends Enumeration { - val JoinTrainSparsePerceptron, JointTrainSparseNetwork, JointTrainSparseNetworkLossAugmented = Value + val JoinTrainSparsePerceptron, JointTrainSparseNetwork, JointTrainSparseNetworkLossAugmented, Pipeline = Value } def main(args: Array[String]): Unit = { /** Choose the experiment you're interested in by changing the following line */ - val testType = BadgeExperimentType.JointTrainSparseNetworkLossAugmented + val testType = BadgeExperimentType.Pipeline testType match { case BadgeExperimentType.JoinTrainSparsePerceptron => JoinTrainSparsePerceptron() case BadgeExperimentType.JointTrainSparseNetwork => JoinTrainSparseNetwork() case BadgeExperimentType.JointTrainSparseNetworkLossAugmented => LossAugmentedJoinTrainSparseNetwork() + case BadgeExperimentType.Pipeline => Pipeline() } } @@ -69,4 +70,13 @@ object BadgesApp { oppositBadgeConstrainedClassifierMulti.test() } + /* This model trains the BadgeClassifier and then it takes the prediction of the BadgeClassifier as the only input + feature and trains a pipeline function to predict the opposite label*/ + def Pipeline(): Unit = { + BadgeClassifier.learn(5) + BadgeClassifier.test() + BadgeOppositPipeline.learn(5) + BadgeOppositPipeline.test() + } + } \ No newline at end of file From b15189ef716b8b0f4599888d8b4b5c0510453afb Mon Sep 17 00:00:00 2001 From: kordjam Date: Thu, 10 Nov 2016 20:40:17 -0600 Subject: [PATCH 14/37] -improved documentation -a renaming --- saul-core/doc/MODELS.md | 52 +++++++++++-------- ...cala => BadgeConstrainedClassifiers.scala} | 2 +- .../saulexamples/Badge/BadgesApp.scala | 4 +- 3 files changed, 32 insertions(+), 26 deletions(-) rename saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/{BadgeConstraintClassifiers.scala => BadgeConstrainedClassifiers.scala} (98%) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index f61daf92..81daa966 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -1,18 +1,23 @@ -//Documented by Parisa Kordjamshidi -Designing flexible learning models including various configurations such as: +#Learning Paradigms - * [Local models](#local) i.e. single classifiers. (Learning only models (LO)). +/*Documented by Parisa Kordjamshidi*/ + +Saul facilitates the flexible design of complex learning models with various configurations. +By complex models we mean the models that aim at prediction of more than one output variable where these outputs might have relationships to each other. +Such models can be designed using the following paradigms, + + * [Local models](#local) trains single classifiers (Learning only models (LO)) each of which learns and predicts a single variable in the output independently. * [Constrained conditional models (CCM)](#L+I)[1] for training independent classifiers and using them jointly for global decision making in prediction time. (Learning+Inference (L+I)). * [Global models](#IBT) for joint training and joint inference (Inference-Based-Training (IBT)). - * [Pipeline models](#pipeline) for complex problems where the output of each layer is used as the input of the next layer. + * [Pipeline models](#pipeline) for complex problems where the output of each model is used as the input of the next model (these models are different layers in a pipeline). The above mentioned paradigms can be tested using this simple badge classifier example, [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala). + -##Local models. -These models are classic classifiers. They are defined with the `Learnable` construct. This construct requires specifying - the name of a single output variable, that is, a label which is itself a property in the data model, and the features which is also a +##Local models +These models are classic classifiers. They are defined with the `Learnable` construct. This construct requires specifying a single output variable, that is, a label which is itself a property in the data model, and the features which is also a comma separated list of properties. ```scala @@ -26,29 +31,28 @@ These models are classic classifiers. They are defined with the `Learnable` cons For the details about the `Learnable` construct see [here](SAULLANGUAGE.md). -##Learning+Inference models. +##Learning+Inference models These models are useful for when we need to consider the global relations between the outputs of a bunch of classifiers during the prediction time. Each classifier is defined with the same `Learnable` construct as a local model. In addition to the Learnable definitions, the programmer -has the possibility to define a number of logical constraints between the output of the classifiers. +has the possibility to define a number of logical constraints between the output of the Learnables (classifiers). Having the constraint definitions in place (see [here](SAULLANGUAGE.md) for syntax details), the programmer is able to define -new constraint classifiers that use the Learnables and constraints. +new constrained classifiers that use the Learnables and constraints. ```scala -object ConstraintClassifierName extends ConstraintClassifier[local_node,global_node](DataModelName, localClassifier_Name) +object ConstrainedClassifierName extends ConstrainedClassifier[local_node_type,global_node_type](LocalClassifier) { def subjectTo = constraintExpression // Logical constraint expression comes here, it defines the relations between the - // localClassifier_Name and other Learnables defined before + // LocalClassifier and other Learnables defined before } ``` -When we use the above `ConstraintClassifierName` to call test or make predictions, the `localClassifier_Name` is used +When we use the above `ConstrainedClassifierName` to call test or make predictions, the `LocalClassifier` is used but the predictions are made in way that `constraintExpression` is hold. There is no limitation for the type of local classifiers. They can be SVMs, decision trees or any other learning models available in Saul, [here](https://github.com/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) and [here](https://github.com/IllinoisCogComp/saul/blob/master/saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md). -##Inference-based Learning. - +##Inference-based Learning For the inference based models the basic definitions are exactly similar to the L+I models. In other words, the programmer just needs to define the `Learnables` and `ConstrainedClassifiers`. However, to train the ConstrainedClassifiers jointly, instead of training local classifiers independently, there are a couple of joint training functions that can be called. @@ -62,19 +66,21 @@ For the two cases the programmer can use JointTrainSparsePerceptron.train(param1,param2,...) /*a list of parameters here*/ ``` - JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true) +For example, + + ```scala JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true)``` The list of parameters are the following: --param1: The name of a global node in the data model that itself or the connected nodes to it are used by the involved `Learnable`s. +- param1: The name of a global node in the data model that itself or the connected nodes to it are used by the involved `Learnable`s. --param2: The list of ConstainedClassifiers +- param2: The collection of ```ConstainedClassifier```s --param3: The number of iterations over the training data. +- param3: The number of iterations over the training data. --param4: If the local classifiers should be cleaned from the possibly pre-trained values and initialized by zero weights, this parameter should be true. +- param4: If the local classifiers should be cleaned from the possibly pre-trained values and initialized by zero weights, this parameter should be true. --param5: If the approach uses the loss augmented objective for making inference, see below for description. +- param5: If the approach uses the loss augmented objective for making inference, see below for description. ###Basic approach @@ -94,13 +100,13 @@ feature function. That is, the loss is a hamming loss defined per classifier. Th An example of this usage can be seen [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala) at line #64. -##Pipelines. +##Pipelines Building pipelines is naturally granted in Saul. The programmer can simply define properties that are the predictions of the classifiers and use those outputs as the input of other classifiers by mentioning them in the list of the properties in the below construct when defining the pipeline classifiers, ```scala -def feature = using(/*list of properties including the prediction of other classifiers.*/) + def feature = using(/*list of properties including the prediction of other classifiers.*/) ``` . See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala), at line #43, for an example. diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstrainedClassifiers.scala similarity index 98% rename from saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala rename to saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstrainedClassifiers.scala index 62fa6638..b5587d9d 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstraintClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeConstrainedClassifiers.scala @@ -13,7 +13,7 @@ import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers.{ BadgeOpposi /** Created by Parisa on 11/1/16. */ -object BadgeConstraintClassifiers { +object BadgeConstrainedClassifiers { val binaryConstraint = ConstrainedClassifier.constraint[String] { x: String => diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala index 965b90a4..87c93b72 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgesApp.scala @@ -9,9 +9,9 @@ package edu.illinois.cs.cogcomp.saulexamples.Badge /** Created by Parisa on 9/13/16. */ -import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrainSparsePerceptron, JointTrainSparseNetwork } +import edu.illinois.cs.cogcomp.saul.classifier.{ JointTrainSparseNetwork, JointTrainSparsePerceptron } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeClassifiers._ -import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstraintClassifiers.{ badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti } +import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeConstrainedClassifiers.{ badgeConstrainedClassifier, badgeConstrainedClassifierMulti, oppositBadgeConstrainedClassifier, oppositBadgeConstrainedClassifierMulti } import edu.illinois.cs.cogcomp.saulexamples.Badge.BadgeDataModel._ import scala.collection.JavaConversions._ From 0776234715e8b9503c916ef3b00b26a709024dd9 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 11 Nov 2016 16:15:02 -0600 Subject: [PATCH 15/37] -improved documentation --- saul-core/doc/MODELS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 81daa966..93fd5492 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -9,7 +9,7 @@ By complex models we mean the models that aim at prediction of more than one out Such models can be designed using the following paradigms, * [Local models](#local) trains single classifiers (Learning only models (LO)) each of which learns and predicts a single variable in the output independently. - * [Constrained conditional models (CCM)](#L+I)[1] for training independent classifiers and using them jointly for global decision making in prediction time. (Learning+Inference (L+I)). + * [Constrained conditional models (CCM)](#L+I) for training independent classifiers and using them jointly for global decision making in prediction time. (Learning+Inference (L+I)). * [Global models](#IBT) for joint training and joint inference (Inference-Based-Training (IBT)). * [Pipeline models](#pipeline) for complex problems where the output of each model is used as the input of the next model (these models are different layers in a pipeline). @@ -17,7 +17,8 @@ The above mentioned paradigms can be tested using this simple badge classifier e ##Local models -These models are classic classifiers. They are defined with the `Learnable` construct. This construct requires specifying a single output variable, that is, a label which is itself a property in the data model, and the features which is also a +These models are a set of single classifiers. Each classifier is defined with the `Learnable` construct and is trained and makes prediction independent from other classifiers. + The `Learnable` construct requires specifying a single output variable, that is, a label which is itself a property in the data model, and the features which is also a comma separated list of properties. ```scala @@ -57,7 +58,7 @@ For the inference based models the basic definitions are exactly similar to the just needs to define the `Learnables` and `ConstrainedClassifiers`. However, to train the ConstrainedClassifiers jointly, instead of training local classifiers independently, there are a couple of joint training functions that can be called. These functions receive the list of constrained classifiers as input and train their parameters jointly. In contrast to -L+I models here the local classifiers can be defined as `SparsePerceptrons` or `SparseNetworks` only. This is because the +L+I models here the local classifiers can be defined as `SparsePerceptron`s or `SparseNetworkLearner`s only. This is because the joint training should have its own strategy for the wight updates of the involved variables (those variables come down to be the outputs of the local classifiers here). For the two cases the programmer can use From 053f96545e7498c68f9560d3e26afbc601db2971 Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 14 Nov 2016 11:21:01 -0600 Subject: [PATCH 16/37] -relative path works for java folder?! --- saul-core/doc/SAULLANGUAGE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saul-core/doc/SAULLANGUAGE.md b/saul-core/doc/SAULLANGUAGE.md index ec022301..fd74eb4f 100644 --- a/saul-core/doc/SAULLANGUAGE.md +++ b/saul-core/doc/SAULLANGUAGE.md @@ -35,8 +35,8 @@ OrgClassifier.test() ### Availale algorithms Here is a list of available algorithms in Saul: - - [LBJava learning algorithms](https://github.com/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) - - [Weka learning algorithms](https://github.com/IllinoisCogComp/saul/blob/master/saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md) + - [LBJava learning algorithms](https://githu/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) + - [Weka learning algorithms](saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md) ### Saving and loading classifiers From 77b0a131be912f3781da7b4a5a18144a33ad552c Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 14 Nov 2016 11:53:52 -0600 Subject: [PATCH 17/37] -relative path works for java folder?! --- saul-core/doc/MODELS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 93fd5492..69b295b9 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -49,8 +49,8 @@ object ConstrainedClassifierName extends ConstrainedClassifier[local_node_type,g ``` When we use the above `ConstrainedClassifierName` to call test or make predictions, the `LocalClassifier` is used but the predictions are made in way that `constraintExpression` is hold. There is no limitation for the type of local classifiers. -They can be SVMs, decision trees or any other learning models available in Saul, [here](https://github.com/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) - and [here](https://github.com/IllinoisCogComp/saul/blob/master/saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md). +They can be SVMs, decision trees or any other learning models available in Saul, [here](lbjava/blob/master/lbjava/doc/ALGORITHMS.md) + and [here](saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md). ##Inference-based Learning From 73c67a089f0dc3745ae9795e6a4d69e16b6d9509 Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 14 Nov 2016 12:25:02 -0600 Subject: [PATCH 18/37] -improved documentation -added example -relative address -weighted loss description --- saul-core/doc/MODELS.md | 34 +++++++++++++++---- .../saulexamples/Badge/BadgeDataModel.scala | 7 +--- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 69b295b9..857d8c4c 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -57,7 +57,7 @@ They can be SVMs, decision trees or any other learning models available in Saul, For the inference based models the basic definitions are exactly similar to the L+I models. In other words, the programmer just needs to define the `Learnables` and `ConstrainedClassifiers`. However, to train the ConstrainedClassifiers jointly, instead of training local classifiers independently, there are a couple of joint training functions that can be called. -These functions receive the list of constrained classifiers as input and train their parameters jointly. In contrast to +These functions receive the list of ConstrainedClassifiers as input and train their parameters jointly. In contrast to L+I models here the local classifiers can be defined as `SparsePerceptron`s or `SparseNetworkLearner`s only. This is because the joint training should have its own strategy for the wight updates of the involved variables (those variables come down to be the outputs of the local classifiers here). For the two cases the programmer can use @@ -69,7 +69,9 @@ For the two cases the programmer can use For example, - ```scala JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true)``` + ```scala + JointTrainSparseNetwork.train(badge, cls, 5, init = true, lossAugmented = true) + ``` The list of parameters are the following: @@ -95,10 +97,12 @@ it updates the weights of the model according to the errors made in the predicti This approach minimizes a convex upper bound of the loss function and has been used in structured SVMs and Structured Perceptrons. However, considering an arbitrary loss in the objective will make complexities in the optimization, therefore in the implemented version, here, we assume the loss is decomposed similar to feature function. That is, the loss is a hamming loss defined per classifier. The loss of the whole structured output is computed by the weighted sum of - the loss of its components. + the loss of its components. For exmaple if there are two variables `c1` and `c2` in the output with corresponding predictions `cp1` and `cp2` then the loss will be + `[hamming(c1,cp1)/2+hamming(c2,cp2)/2]`. The weight of each component's loss is `1/numberOfOutputVariables` by default. + In Saul, the programmer can indicate if he/she needs to consider this global hamming loss in the objective or not. And this can be done by passing the above mentioned `param5` as true in the `JointTrainingSparseNetwork` algorithm. - An example of this usage can be seen [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala) at line #64. + An example of this usage can be seen [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BagesApp.scala#L64). ##Pipelines @@ -109,8 +113,26 @@ pipeline classifiers, ```scala def feature = using(/*list of properties including the prediction of other classifiers.*/) ``` -. -See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala), at line #43, for an example. +Here is a more complete example which passes the output of the `ClassifierLayer1` to the input of the `ClassifierLayer2`: + + ```scala + + object ClassifierLayer1 extends Learnable (node) { + def label = labelProperty1 + def feature = using(property2, property3,...) + } + + object ClassifierLayer2 extends Learnable (node) { + def label = labelProperty2 + def feature = using(classifier1Labels, ,...) // using the prediction of the classifier in the previous layer + } + + // defined in data-model object + val classifier1Labels = new Property(node){ x: Type => ClassifierLayer1(x) } + + ``` + +See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala#L43), for a working example. diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala index b161dbcb..fbb288f7 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala @@ -45,10 +45,5 @@ object BadgeDataModel extends DataModel { } } - val BadgePrediction = property(badge)("true", "false") { - x: String => - { - BadgeClassifier(x) - } - } + val BadgePrediction = property(badge)("true", "false") { x: String => BadgeClassifier(x) } } From 4ad58406252ae49498a7e12fb3cc8162489dc738 Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 14 Nov 2016 12:25:40 -0600 Subject: [PATCH 19/37] format --- .../illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala index fbb288f7..3d1e9366 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeDataModel.scala @@ -45,5 +45,5 @@ object BadgeDataModel extends DataModel { } } - val BadgePrediction = property(badge)("true", "false") { x: String => BadgeClassifier(x) } + val BadgePrediction = property(badge)("true", "false") { x: String => BadgeClassifier(x) } } From c104fffac1109a08714a1e03b81f834ad39fa598 Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 09:30:09 -0600 Subject: [PATCH 20/37] SRL join-training --- .../SemanticRoleLabeling/SRLConfigurator.java | 6 +++--- .../nlp/SemanticRoleLabeling/SRLApps.scala | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java index f006e1af..d9a22611 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java @@ -19,10 +19,10 @@ */ public class SRLConfigurator extends Configurator { - public static final Property TREEBANK_HOME = new Property("treebankHome", "../saul-examples/src/test/resources/SRLToy/treebank"); - public static final Property PROPBANK_HOME = new Property("propbankHome","../saul-examples/src/test/resources/SRLToy/propbank"); + public static final Property TREEBANK_HOME = new Property("treebankHome", "../data/treebank"); + public static final Property PROPBANK_HOME = new Property("propbankHome","../data/propbank"); - public static final Property TEST_SECTION = new Property("testSection","00"); + public static final Property TEST_SECTION = new Property("testSection","23"); public static final Property MODELS_DIR = new Property("modelsDir", "../models"); public static final Property USE_CURATOR = new Property("useCurator", Configurator.FALSE); diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index b6c81203..71eb0d49 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -30,7 +30,7 @@ object SRLApps extends Logging { val modelDir = properties.getString(MODELS_DIR) + File.separator + properties.getString(SRLConfigurator.SRL_MODEL_DIR) + File.separator val srlPredictionsFile = properties.getString(SRLConfigurator.SRL_OUTPUT_FILE) - val runningMode = properties.getBoolean(SRLConfigurator.RUN_MODE) + val testingMode = properties.getBoolean(SRLConfigurator.RUN_MODE) val trainingMode = properties.getString(SRLConfigurator.TRAINING_MODE) // Training parameters @@ -65,7 +65,7 @@ object SRLApps extends Logging { logger.info("population starts.") // Here, the data is loaded into the graph - val srlDataModelObject = PopulateSRLDataModel(testOnly = runningMode, useGoldPredicate, useGoldBoundaries) + val srlDataModelObject = PopulateSRLDataModel(testOnly = testingMode, useGoldPredicate, useGoldBoundaries) import srlDataModelObject._ @@ -80,7 +80,7 @@ object RunningApps extends App with Logging { import SRLApps._ import SRLApps.srlDataModelObject._ // TRAINING - if (!runningMode) { + if (!testingMode) { expName match { case "aTr" => @@ -148,14 +148,23 @@ object RunningApps extends App with Logging { argumentTypeLearner.modelDir = modelDir + expName val outputFile = modelDir + srlPredictionsFile logger.info("Global training... ") - JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 100, true) + JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 100, init = true) + argumentTypeLearner.save() + argTypeConstraintClassifier.test(relations.getTestingInstances, outputFile, 200, exclude = "candidate") + + case "lTr" => + argumentTypeLearner.modelDir = modelDir + expName + val outputFile = modelDir + srlPredictionsFile + logger.info("Global training using loss augmented inference... ") + JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 100, init = true, lossAugmented = true) argumentTypeLearner.save() argTypeConstraintClassifier.test(relations.getTestingInstances, outputFile, 200, exclude = "candidate") } + } // TESTING - if (runningMode) { + if (testingMode) { (testWithPipeline, testWithConstraints) match { case (true, true) => From e668bdd60876e7a67b7091880ca3bc660d94d8e2 Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 09:48:51 -0600 Subject: [PATCH 21/37] Fixed the RunningApps name in the documentation --- .../nlp/SemanticRoleLabeling/README.md | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md index d27abf74..8d499c5d 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md @@ -5,13 +5,13 @@ This task is to annotate natural language sentences with semantic roles. To run the main app with default properties: ``` -sbt "project saulExamples" "run-main edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.srlApp" +sbt "project saulExamples" "run-main edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.RunningApps" ``` -To use a custom configuration file (containing the property keys of `ExamplesConfigurator`): +To use a custom configuration file (containing the property keys of `ExamplesConfigurator`), also extending memory to 4G: ``` - sbt "project saulExamples" "run-main edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.srlApp config/saul-srl.properties" + sbt -mem 4000 "project saulExamples" "run-main edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.RunningApps config/saul-srl.properties" ``` ## Example @@ -586,11 +586,3 @@ In the following lines `Pred.` stands for "Predicate" and `Cand.` stands for "C - [ ] **[aTsJ]** Test the **cTs** of the second phase for joint models. -The defaul configuration when running the sprlApp will run only the test for pretrained cTr model while it uses srl global constraints during prediction. -You can run it from command line by: - -```scala - -sbt -mem 4000 "project saulExamples" "run-main edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLApps" - -``` From dce32e9cc760b5f0cd01df33298c97cad0034503 Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 11:13:53 -0600 Subject: [PATCH 22/37] temporarily removed joinnodes populate for SRL experiments --- .../edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala index 46f6b4b8..0783e2df 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala @@ -127,7 +127,7 @@ class Node[T <: AnyRef](val keyFunc: T => Any = (x: T) => x, val tag: ClassTag[T } // TODO: Populating join nodes takes significant amount of time on large graphs. Investigate. - joinNodes.foreach(_.addFromChild(this, instance, train, populateEdge)) + //joinNodes.foreach(_.addFromChild(this, instance, train, populateEdge)) } } From 8059746a9605af3a8796d3f16733b629a2752565 Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 11:20:18 -0600 Subject: [PATCH 23/37] -train mode --- .../saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java index d9a22611..533d57ae 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java @@ -28,7 +28,7 @@ public class SRLConfigurator extends Configurator { public static final Property USE_CURATOR = new Property("useCurator", Configurator.FALSE); // The running mode of the program. Can be "true" for only testing, or "false" for training - public static final Property RUN_MODE = new Property("runMode", Configurator.TRUE); + public static final Property RUN_MODE = new Property("runMode", Configurator.FALSE); // The training mode for the examples. Can be "pipeline", "joint", or "other" public static final Property TRAINING_MODE = new Property("trainingMode", "joint"); From f91e18d2a3dfccc35939f31af1bd082c0238e1fc Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 11:26:59 -0600 Subject: [PATCH 24/37] -use Gurobi --- .../SemanticRoleLabeling/SRLConstrainedClassifiers.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala index cab81f68..bf5b5ac4 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala @@ -6,17 +6,17 @@ */ package edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling -import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{ Relation, TextAnnotation } -import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook +import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{Relation, TextAnnotation} +import edu.illinois.cs.cogcomp.infer.ilp.GurobiHook import edu.illinois.cs.cogcomp.saul.classifier.ConstrainedClassifier -import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers.{ argumentTypeLearner, argumentXuIdentifierGivenApredicate } +import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers.{argumentTypeLearner, argumentXuIdentifierGivenApredicate} import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstraints._ /** Created by Parisa on 12/27/15. */ object SRLConstrainedClassifiers { import SRLApps.srlDataModelObject._ - val erSolver = new OJalgoHook + val erSolver = new GurobiHook object argTypeConstraintClassifier extends ConstrainedClassifier[Relation, TextAnnotation](argumentTypeLearner) { def subjectTo = r_and_c_args From e006bb998442f1d793b9248bdb1aebd181924c98 Mon Sep 17 00:00:00 2001 From: kordjam Date: Wed, 16 Nov 2016 13:18:10 -0600 Subject: [PATCH 25/37] -remove logger messages -smaller iterations --- .../saul/classifier/ConstrainedClassifier.scala | 12 ++++++------ .../nlp/SemanticRoleLabeling/SRLApps.scala | 4 ++-- .../SRLConstrainedClassifiers.scala | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala index 337956f6..9b5716a6 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala @@ -69,13 +69,13 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi val l = pathToHead.get.forward.neighborsOf(x).toSet.toList if (l.isEmpty) { - logger.error("Warning: Failed to find head") + //logger.error("Warning: Failed to find head") None } else if (l.size != 1) { - logger.warn("Find too many heads") + //logger.warn("Find too many heads") Some(l.head) } else { - logger.info(s"Found head ${l.head} for child $x") + //logger.info(s"Found head ${l.head} for child $x") Some(l.head) } } @@ -88,7 +88,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi val l = pathToHead.get.backward.neighborsOf(head) if (l.isEmpty) { - logger.error("Failed to find part") + //logger.error("Failed to find part") Seq.empty[T] } else { l.filter(filter(_, head)).toSeq @@ -103,7 +103,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi var inference = InferenceManager.get(name, head) if (inference == null) { inference = infer(head) - logger.warn(s"Inference ${name} has not been cached; running inference . . . ") + // logger.warn(s"Inference ${name} has not been cached; running inference . . . ") InferenceManager.put(name, inference) } inference.valueOf(cls, t) @@ -141,7 +141,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi .orElse({ onClassifier match { case clf: Learnable[T] => Some(clf.node) - case _ => logger.error("pathToHead is not provided and the onClassifier is not a Learnable!"); None + case _ => None //logger.error("pathToHead is not provided and the onClassifier is not a Learnable!"); None } }) .map(node => node.getTestingInstances) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index 71eb0d49..fc0ec8ea 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -148,7 +148,7 @@ object RunningApps extends App with Logging { argumentTypeLearner.modelDir = modelDir + expName val outputFile = modelDir + srlPredictionsFile logger.info("Global training... ") - JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 100, init = true) + JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 30, init = true) argumentTypeLearner.save() argTypeConstraintClassifier.test(relations.getTestingInstances, outputFile, 200, exclude = "candidate") @@ -156,7 +156,7 @@ object RunningApps extends App with Logging { argumentTypeLearner.modelDir = modelDir + expName val outputFile = modelDir + srlPredictionsFile logger.info("Global training using loss augmented inference... ") - JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 100, init = true, lossAugmented = true) + JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 30, init = true, lossAugmented = true) argumentTypeLearner.save() argTypeConstraintClassifier.test(relations.getTestingInstances, outputFile, 200, exclude = "candidate") } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala index bf5b5ac4..2c1fbf80 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala @@ -6,10 +6,10 @@ */ package edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling -import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{Relation, TextAnnotation} +import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{ Relation, TextAnnotation } import edu.illinois.cs.cogcomp.infer.ilp.GurobiHook import edu.illinois.cs.cogcomp.saul.classifier.ConstrainedClassifier -import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers.{argumentTypeLearner, argumentXuIdentifierGivenApredicate} +import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers.{ argumentTypeLearner, argumentXuIdentifierGivenApredicate } import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstraints._ /** Created by Parisa on 12/27/15. From ff5c9f34e6dc50339d433a0c6d3203e60cce17f9 Mon Sep 17 00:00:00 2001 From: kordjam Date: Thu, 17 Nov 2016 22:17:24 -0600 Subject: [PATCH 26/37] -jointTrain setting -add loss option to SRL runnables --- .../nlp/SemanticRoleLabeling/SRLConfigurator.java | 4 ++-- .../SemanticRoleLabeling/PopulateSRLDataModel.scala | 2 +- .../nlp/SemanticRoleLabeling/SRLApps.scala | 1 + .../nlp/SpatialRoleLabeling/SpRLDataModel.scala | 11 +++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java index 533d57ae..db4952e1 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java @@ -30,8 +30,8 @@ public class SRLConfigurator extends Configurator { // The running mode of the program. Can be "true" for only testing, or "false" for training public static final Property RUN_MODE = new Property("runMode", Configurator.FALSE); - // The training mode for the examples. Can be "pipeline", "joint", or "other" - public static final Property TRAINING_MODE = new Property("trainingMode", "joint"); + // The training mode for the examples. Can be "pipeline", "joint", "jointLoss" or "other" + public static final Property TRAINING_MODE = new Property("trainingMode", "jointLoss"); /*********** SRL PROPERTIES ***********/ // The (sub)directory to store and retrieve the trained SRL models (to be used with MODELS_DIR) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala index 6ed49e04..044b2b99 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala @@ -87,7 +87,7 @@ object PopulateSRLDataModel extends Logging { } val trainingFromSection = 2 - val trainingToSection = 2 + val trainingToSection = 21 var gr: SRLMultiGraphDataModel = null if (!testOnly) { logger.info(s"Reading training data from sections $trainingFromSection to $trainingToSection") diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index fc0ec8ea..9151a1d0 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -58,6 +58,7 @@ object SRLApps extends Logging { else "" else if (trainingMode.equals("pipeline")) "pTr" else if (trainingMode.equals("joint")) "jTr" + else if (trainingMode.equals("jointLoss")) "lTr" else "" } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala index 3167cccc..c451a353 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala @@ -10,11 +10,10 @@ import edu.illinois.cs.cogcomp.core.datastructures.ViewNames import edu.illinois.cs.cogcomp.edison.features.factory.WordNetFeatureExtractor import edu.illinois.cs.cogcomp.saul.datamodel.DataModel import edu.illinois.cs.cogcomp.saulexamples.nlp.CommonSensors._ -import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.Triplet.{ SpRelation, SpRoleTypes } import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.SpRLSensors._ +import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.Triplet.{SpRelation, SpRoleTypes} import scala.collection.JavaConverters._ -import scala.collection.immutable.HashSet import scala.collection.mutable.ListBuffer /** Created by taher on 8/10/16. @@ -60,13 +59,13 @@ object SpRLDataModel extends DataModel { val BF6 = property(relations) { x: SpRelation => { - val t = x.getTrajector.getFirstConstituent.getStartSpan + val trStart = x.getTrajector.getFirstConstituent.getStartSpan val spStart = x.getSpatialIndicator.getFirstConstituent.getStartSpan val spEnd = x.getSpatialIndicator.getLastConstituent.getStartSpan - if (t < spStart) - getDependencyPath(x.getTextAnnotation, t, spStart) + if (trStart < spStart) + getDependencyPath(x.getTextAnnotation, trStart, spStart) else - getDependencyPath(x.getTextAnnotation, t, spEnd) + getDependencyPath(x.getTextAnnotation, trStart, spEnd) } } From 754d6943c1a8d07daaba54b888c27e04c4c3e7d9 Mon Sep 17 00:00:00 2001 From: kordjam Date: Thu, 17 Nov 2016 22:17:56 -0600 Subject: [PATCH 27/37] format --- .../cs/cogcomp/saul/classifier/ConstrainedClassifier.scala | 2 +- .../saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala index 9b5716a6..69a1009d 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala @@ -103,7 +103,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi var inference = InferenceManager.get(name, head) if (inference == null) { inference = infer(head) - // logger.warn(s"Inference ${name} has not been cached; running inference . . . ") + // logger.warn(s"Inference ${name} has not been cached; running inference . . . ") InferenceManager.put(name, inference) } inference.valueOf(cls, t) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala index c451a353..b84ce932 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SpatialRoleLabeling/SpRLDataModel.scala @@ -11,7 +11,7 @@ import edu.illinois.cs.cogcomp.edison.features.factory.WordNetFeatureExtractor import edu.illinois.cs.cogcomp.saul.datamodel.DataModel import edu.illinois.cs.cogcomp.saulexamples.nlp.CommonSensors._ import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.SpRLSensors._ -import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.Triplet.{SpRelation, SpRoleTypes} +import edu.illinois.cs.cogcomp.saulexamples.nlp.SpatialRoleLabeling.Triplet.{ SpRelation, SpRoleTypes } import scala.collection.JavaConverters._ import scala.collection.mutable.ListBuffer From 92de79629b78e052edb3b5a11d3df6a4293d286e Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 18 Nov 2016 12:06:44 -0600 Subject: [PATCH 28/37] -fixed the test units path for SRL - added scala configurator for SRL - removed the redundant configurations from the SRL app - set the defaults to train aTR --- .../SemanticRoleLabeling/SRLConfigurator.java | 7 +- .../PopulateSRLDataModel.scala | 11 +- .../nlp/SemanticRoleLabeling/SRLApps.scala | 121 +++++++++++------- 3 files changed, 83 insertions(+), 56 deletions(-) diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java index db4952e1..fa81be41 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java @@ -19,10 +19,9 @@ */ public class SRLConfigurator extends Configurator { - public static final Property TREEBANK_HOME = new Property("treebankHome", "../data/treebank"); - public static final Property PROPBANK_HOME = new Property("propbankHome","../data/propbank"); - - public static final Property TEST_SECTION = new Property("testSection","23"); + public static final Property TREEBANK_HOME = new Property("treebankHome", "../saul-examples/src/test/resources/SRLToy/treebank"); + public static final Property PROPBANK_HOME = new Property("propbankHome","../saul-examples/src/test/resources/SRLToy/propbank"); + public static final Property TEST_SECTION = new Property("testSection","00"); public static final Property MODELS_DIR = new Property("modelsDir", "../models"); public static final Property USE_CURATOR = new Property("useCurator", Configurator.FALSE); diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala index 044b2b99..4229f87e 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala @@ -19,10 +19,10 @@ import edu.illinois.cs.cogcomp.nlp.common.PipelineConfigurator._ import edu.illinois.cs.cogcomp.nlp.utilities.ParseUtils import edu.illinois.cs.cogcomp.saul.util.Logging import edu.illinois.cs.cogcomp.saulexamples.data.{ SRLDataReader, SRLFrameManager } -import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLSensors._ import edu.illinois.cs.cogcomp.saulexamples.nlp.CommonSensors._ +import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLSensors._ import edu.illinois.cs.cogcomp.saulexamples.nlp.TextAnnotationFactory - +import SRLscalaConfigurator._ import scala.collection.JavaConversions._ /** Created by Parisa on 1/17/16. @@ -85,9 +85,8 @@ object PopulateSRLDataModel extends Logging { logger.debug(s"Number of $readerType data predicates: $numPredicates") logger.debug(s"Number of $readerType data arguments: $numArguments") } - - val trainingFromSection = 2 - val trainingToSection = 21 + val trainingFromSection = TRAIN_SECTION_S + val trainingToSection = TRAIN_SECTION_E var gr: SRLMultiGraphDataModel = null if (!testOnly) { logger.info(s"Reading training data from sections $trainingFromSection to $trainingToSection") @@ -124,7 +123,7 @@ object PopulateSRLDataModel extends Logging { if (graphs.sentences().size % 1000 == 0) logger.info("loaded graphs in memory:" + graphs.sentences().size) } } - val testSection = rm.getInt(SRLConfigurator.TEST_SECTION) + val testSection = SRLscalaConfigurator.TEST_SECTION val testReader = new SRLDataReader( rm.getString(SRLConfigurator.TREEBANK_HOME.key), rm.getString(SRLConfigurator.PROPBANK_HOME.key), diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index 9151a1d0..cc34e703 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -8,57 +8,85 @@ package edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling import java.io.File -import edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager +import edu.illinois.cs.cogcomp.core.datastructures.ViewNames import edu.illinois.cs.cogcomp.saul.classifier.{ ClassifierUtils, JointTrainSparseNetwork } import edu.illinois.cs.cogcomp.saul.util.Logging import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers._ import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstrainedClassifiers.argTypeConstraintClassifier -object SRLApps extends Logging { - import SRLConfigurator._ - - val properties: ResourceManager = { - // Load the default properties if the user hasn't entered a file as an argument - //if (args.length == 0) { - logger.info("Loading default configuration parameters") - new SRLConfigurator().getDefaultConfig - //} else { - // logger.info("Loading parameters from {}", args(0)) - //new SRLConfigurator().getConfig(new ResourceManager(args(0))) - // } - } - val modelDir = properties.getString(MODELS_DIR) + - File.separator + properties.getString(SRLConfigurator.SRL_MODEL_DIR) + File.separator - val srlPredictionsFile = properties.getString(SRLConfigurator.SRL_OUTPUT_FILE) - val testingMode = properties.getBoolean(SRLConfigurator.RUN_MODE) - val trainingMode = properties.getString(SRLConfigurator.TRAINING_MODE) +object SRLscalaConfigurator { + + val TREEBANK_HOME = "../data/treebank" + val PROPBANK_HOME = "../data/propbank" + + val TEST_SECTION = 23 + val TRAIN_SECTION_S = 2 + val TRAIN_SECTION_E = 21 + + val MODELS_DIR = "../models" + val USE_CURATOR = false + + // The running mode of the program. Can be "true" for only testing, or "false" for training + val RUN_MODE: Boolean = false + + // The training mode for the examples. Can be "pipeline", "joint", "jointLoss" or "other" + val TRAINING_MODE = "other" + + /*********** SRL PROPERTIES ***********/ + // The (sub)directory to store and retrieve the trained SRL models (to be used with MODELS_DIR) + val SRL_MODEL_DIR = "srl" + val SRL_JAR_MODEL_PATH = "models" + + // This is used to determine the parse view in SRL experiments (can be ViewNames.GOLD or ViewNames.STANFORD) + // For replicating the published experiments this needs to be GOLD + val SRL_PARSE_VIEW = ViewNames.PARSE_GOLD - // Training parameters - val trainPredicates = properties.getBoolean(SRLConfigurator.SRL_TRAIN_PREDICATES) - val trainArgIdentifier = properties.getBoolean(SRLConfigurator.SRL_TRAIN_ARG_IDENTIFIERS) - val trainArgType = properties.getBoolean(SRLConfigurator.SRL_TRAIN_ARG_TYPE) + // A file to store the predictions of the SRL classifier (for argument types only) + val SRL_OUTPUT_FILE = "srl-predictions.txt" - // Testing parameters - val testWithConstraints = properties.getBoolean(SRLConfigurator.SRL_TEST_CONSTRAINTS) - val testWithPipeline = properties.getBoolean(SRLConfigurator.SRL_TEST_PIPELINE) + // Whether to use gold predicates (if FALSE, predicateClassifier will be used instead) + val SRL_GOLD_PREDICATES = true + + // Whether to use gold argument boundaries (if FALSE, argumentXuIdentifierGivenApredicate will be used instead) + val SRL_GOLD_ARG_BOUNDARIES = true + + /*Testing parameters*/ + + // Should we use the pipeline during testing + val SRL_TEST_PIPELINE = false + // Should we use constraints during testing + val SRL_TEST_CONSTRAINTS = false + + /*Training parameters*/ + + // Should we train a predicate classifier given predicate candidates + val SRL_TRAIN_PREDICATES = false + // Should we train an argument identifier given the XuPalmer argument candidates + val SRL_TRAIN_ARG_IDENTIFIERS = false + // Should we train an argument type classifier + val SRL_TRAIN_ARG_TYPE = true + +} + +object SRLApps extends Logging { - val useGoldPredicate = properties.getBoolean(SRLConfigurator.SRL_GOLD_PREDICATES) - val useGoldBoundaries = properties.getBoolean(SRLConfigurator.SRL_GOLD_ARG_BOUNDARIES) + import SRLscalaConfigurator._ - val modelJars = properties.getString(SRLConfigurator.SRL_JAR_MODEL_PATH) + val modelDir = (MODELS_DIR) + + File.separator + SRL_MODEL_DIR + File.separator val expName: String = { - if (trainingMode.equals("other")) - if (trainArgType && useGoldBoundaries && useGoldPredicate && trainingMode.equals("other")) "aTr" - else if (trainArgIdentifier && useGoldPredicate && useGoldPredicate) "bTr" - else if (trainArgType && useGoldPredicate && !useGoldBoundaries) "cTr" - else if (trainPredicates && useGoldPredicate) "dTr" - else if (trainArgIdentifier && !useGoldPredicate) "eTr" - else if (trainArgType && !useGoldPredicate) "fTr" + if (TRAINING_MODE.equals("other")) + if (SRL_TRAIN_ARG_TYPE && SRL_GOLD_ARG_BOUNDARIES && SRL_GOLD_PREDICATES && TRAINING_MODE.equals("other")) "aTr" + else if (SRL_TRAIN_ARG_IDENTIFIERS && SRL_GOLD_PREDICATES && SRL_GOLD_PREDICATES) "bTr" + else if (SRL_TRAIN_ARG_TYPE && SRL_GOLD_PREDICATES && !SRL_GOLD_ARG_BOUNDARIES) "cTr" + else if (SRL_TRAIN_PREDICATES && SRL_GOLD_PREDICATES) "dTr" + else if (SRL_TRAIN_ARG_IDENTIFIERS && !SRL_GOLD_PREDICATES) "eTr" + else if (SRL_TRAIN_ARG_TYPE && !SRL_GOLD_PREDICATES) "fTr" else "" - else if (trainingMode.equals("pipeline")) "pTr" - else if (trainingMode.equals("joint")) "jTr" - else if (trainingMode.equals("jointLoss")) "lTr" + else if (TRAINING_MODE.equals("pipeline")) "pTr" + else if (TRAINING_MODE.equals("joint")) "jTr" + else if (TRAINING_MODE.equals("jointLoss")) "lTr" else "" } @@ -66,7 +94,7 @@ object SRLApps extends Logging { logger.info("population starts.") // Here, the data is loaded into the graph - val srlDataModelObject = PopulateSRLDataModel(testOnly = testingMode, useGoldPredicate, useGoldBoundaries) + val srlDataModelObject = PopulateSRLDataModel(testOnly = RUN_MODE, SRL_GOLD_PREDICATES, SRL_GOLD_ARG_BOUNDARIES) import srlDataModelObject._ @@ -80,13 +108,14 @@ object SRLApps extends Logging { object RunningApps extends App with Logging { import SRLApps._ import SRLApps.srlDataModelObject._ + import SRLscalaConfigurator._ // TRAINING - if (!testingMode) { + if (!RUN_MODE) { expName match { case "aTr" => argumentTypeLearner.modelDir = modelDir + expName - argumentTypeLearner.learn(100, relations.getTrainingInstances) + argumentTypeLearner.learn(30, relations.getTrainingInstances) argumentTypeLearner.test() argumentTypeLearner.save() @@ -147,7 +176,7 @@ object RunningApps extends App with Logging { case "jTr" => argumentTypeLearner.modelDir = modelDir + expName - val outputFile = modelDir + srlPredictionsFile + val outputFile = modelDir + SRL_OUTPUT_FILE logger.info("Global training... ") JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 30, init = true) argumentTypeLearner.save() @@ -155,7 +184,7 @@ object RunningApps extends App with Logging { case "lTr" => argumentTypeLearner.modelDir = modelDir + expName - val outputFile = modelDir + srlPredictionsFile + val outputFile = modelDir + SRL_OUTPUT_FILE logger.info("Global training using loss augmented inference... ") JointTrainSparseNetwork(sentences, argTypeConstraintClassifier :: Nil, 30, init = true, lossAugmented = true) argumentTypeLearner.save() @@ -165,8 +194,8 @@ object RunningApps extends App with Logging { } // TESTING - if (testingMode) { - (testWithPipeline, testWithConstraints) match { + if (RUN_MODE) { + (SRL_TEST_PIPELINE, SRL_TEST_CONSTRAINTS) match { case (true, true) => ClassifierUtils.LoadClassifier(SRLConfigurator.SRL_JAR_MODEL_PATH.value + "/models_bTr/", argumentXuIdentifierGivenApredicate) From 9cf1f25e9d51ebdae34f4e25086c09485ccc5bb2 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 18 Nov 2016 12:07:34 -0600 Subject: [PATCH 29/37] -format --- .../saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index cc34e703..28249663 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -72,8 +72,7 @@ object SRLApps extends Logging { import SRLscalaConfigurator._ - val modelDir = (MODELS_DIR) + - File.separator + SRL_MODEL_DIR + File.separator + val modelDir = MODELS_DIR + File.separator + SRL_MODEL_DIR + File.separator val expName: String = { if (TRAINING_MODE.equals("other")) From 51862511790122e3e31b755488611ef1904d33a8 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 18 Nov 2016 17:36:38 -0600 Subject: [PATCH 30/37] -replaced configuration parameters --- .../PopulateSRLDataModel.scala | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala index 4229f87e..438b09f4 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala @@ -22,7 +22,7 @@ import edu.illinois.cs.cogcomp.saulexamples.data.{ SRLDataReader, SRLFrameManage import edu.illinois.cs.cogcomp.saulexamples.nlp.CommonSensors._ import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLSensors._ import edu.illinois.cs.cogcomp.saulexamples.nlp.TextAnnotationFactory -import SRLscalaConfigurator._ +import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLscalaConfigurator._ import scala.collection.JavaConversions._ /** Created by Parisa on 1/17/16. @@ -34,7 +34,7 @@ object PopulateSRLDataModel extends Logging { useGoldArgBoundaries: Boolean = false, rm: ResourceManager = new SRLConfigurator().getDefaultConfig ): SRLMultiGraphDataModel = { - val frameManager: SRLFrameManager = new SRLFrameManager(rm.getString(SRLConfigurator.PROPBANK_HOME.key)) + val frameManager: SRLFrameManager = new SRLFrameManager(PROPBANK_HOME) val useCurator = rm.getBoolean(SRLConfigurator.USE_CURATOR) val parseViewName = rm.getString(SRLConfigurator.SRL_PARSE_VIEW) val graphs = new SRLMultiGraphDataModel(parseViewName, frameManager) @@ -85,16 +85,12 @@ object PopulateSRLDataModel extends Logging { logger.debug(s"Number of $readerType data predicates: $numPredicates") logger.debug(s"Number of $readerType data arguments: $numArguments") } - val trainingFromSection = TRAIN_SECTION_S - val trainingToSection = TRAIN_SECTION_E + var gr: SRLMultiGraphDataModel = null if (!testOnly) { - logger.info(s"Reading training data from sections $trainingFromSection to $trainingToSection") - val trainReader = new SRLDataReader( - rm.getString(SRLConfigurator.TREEBANK_HOME.key), - rm.getString(SRLConfigurator.PROPBANK_HOME.key), - trainingFromSection, trainingToSection - ) + logger.info(s"Reading training data from sections $TRAIN_SECTION_S to $TRAIN_SECTION_E") + val trainReader = new SRLDataReader(TREEBANK_HOME, PROPBANK_HOME, + TRAIN_SECTION_S, TRAIN_SECTION_E) trainReader.readData() logger.info(s"Annotating ${trainReader.textAnnotations.size} training sentences") val filteredTa = addViewAndFilter(trainReader.textAnnotations.toList) @@ -124,11 +120,7 @@ object PopulateSRLDataModel extends Logging { } } val testSection = SRLscalaConfigurator.TEST_SECTION - val testReader = new SRLDataReader( - rm.getString(SRLConfigurator.TREEBANK_HOME.key), - rm.getString(SRLConfigurator.PROPBANK_HOME.key), - testSection, testSection - ) + val testReader = new SRLDataReader(TREEBANK_HOME, PROPBANK_HOME, testSection, testSection) logger.info(s"Reading test data from section $testSection") testReader.readData() From e1ea9a40a148377c180a80be65b1329c522f67c2 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 18 Nov 2016 17:38:16 -0600 Subject: [PATCH 31/37] -replaced configuration parameters --- .../nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala index 438b09f4..9796653b 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/PopulateSRLDataModel.scala @@ -119,9 +119,9 @@ object PopulateSRLDataModel extends Logging { if (graphs.sentences().size % 1000 == 0) logger.info("loaded graphs in memory:" + graphs.sentences().size) } } - val testSection = SRLscalaConfigurator.TEST_SECTION - val testReader = new SRLDataReader(TREEBANK_HOME, PROPBANK_HOME, testSection, testSection) - logger.info(s"Reading test data from section $testSection") + + val testReader = new SRLDataReader(TREEBANK_HOME, PROPBANK_HOME, TEST_SECTION, TEST_SECTION) + logger.info(s"Reading test data from section $TEST_SECTION") testReader.readData() logger.info(s"Annotating ${testReader.textAnnotations.size} test sentences") From aba475bb5a63e47af683d0b684698ceaef7f6d50 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 2 Dec 2016 18:09:02 -0600 Subject: [PATCH 32/37] -added results of join training (IBT) with SRL ArgTypeClassifier -added results of joint training with loss-augmented inference -removed redundant property symbols --- .../saulexamples/DrugResponse/myApp.scala | 1 + .../nlp/SemanticRoleLabeling/README.md | 123 +++++++++++++++++- .../nlp/SemanticRoleLabeling/SRLApps.scala | 10 +- .../SRLMultiGraphDataModel.scala | 76 +++++------ .../nlp/TextAnnotationFactory.scala | 9 +- 5 files changed, 167 insertions(+), 52 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/DrugResponse/myApp.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/DrugResponse/myApp.scala index 5c5ca870..5b93d1c8 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/DrugResponse/myApp.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/DrugResponse/myApp.scala @@ -75,6 +75,7 @@ object myApp extends Logging { //dResponseClassifier.testContinuos(patient_drug_data) //DrugResponseRegressor.learn(1) + //DrugResponseRegressor.testContinuos(patientDrug.getTrainingInstances) logger.info("finished!") } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md index 8d499c5d..20daf583 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md @@ -29,6 +29,7 @@ Similar to other applications in Saul, here also we have a datamodel in file `SR classifier definitions in file `SRLClassifires`, a bunch of constraints to be used by global models during either training or test in file `SRLConstraints`, a bunch of constrained classifiers in file `SRLConstrainedClassifiers` and the running configurations that are all placed in one file called `SRLApp`. + For using the reader and populating data there is a program in file `PopulateSRLDataModel`. In contrast to other Saul applications this data model has been defined as a class instead of as an object. The reason is the efficiency of the population of the data model, we skip the details of this implementation choice. @@ -40,7 +41,7 @@ the properties which use the FrameNet frames can receive it as a parameter. We refer the reader to see an example of defining such parametrized properties along with `Learnable` classes and contrast it with the `Learnable` objects in `DrugResponse` example of `KnowEng` data model. -There are various machine learning configurations to solve this including pipelines, learning only models (LO), +There are various machine learning configurations to solve SRL including pipelines, learning only models (LO), learning plus inference models (L+I) and Joint Learning models (IBT). The test units and SRLApp are runnable on a sample toy dataset located in `resources/SRLToy` folder. Accessing the full dataset needs proper licenses. If you have access to the PropBank data, you could @@ -61,13 +62,12 @@ In the following lines `Pred.` stands for "Predicate" and `Cand.` stands for "C | Predicate | Argument | Model | Name | | -----------| -------------------- | ------------------------ | ---- | -| Gold Pred. | Gold Boundaries | Argument Type Classifier | aTr | +| Gold Pred. | Gold Boundaries | Argument Type Classifier | aTr,jTr,lTr | | Gold Pred. | XuPalmer Candidates | Argument identifier | bTr | | Gold Pred. | XuPalmer Candidates | Argument Type Classifier | cTr | | Predicted Cand. | NA | Predicate Classifier | dTr | | Predicted Cand. | XuPalmer Candidates | Argument identifier | eTr | | Predicted Cand. | XuPalmer Candidates | Argument Type Classifier | fTr | -| Gold Pred. | Gold Boundries | Argument Type Classifier | jTr | | Gold Pred. | Argument Identifier | Argument Type Classifier | pTr | @@ -577,6 +577,123 @@ In the following lines `Pred.` stands for "Predicate" and `Cand.` stands for "C * Add constraints gradually and test. #### Third phase: training joint models + - [x] **[lTr]** Train aTr jointly using hamming loss; test using constraints + + + Average evaluation time: 0.04143100828729282 seconds + + Label Precision Recall F1 LCount PCount + ---------------------------------------------- + A0 96.585 91.699 94.079 3578 3397 + A1 90.352 93.517 91.907 4967 5141 + A2 78.791 64.711 71.060 1108 910 + A3 61.176 60.465 60.819 172 170 + A4 28.525 85.294 42.752 102 305 + A5 57.143 80.000 66.667 5 7 + AA 0.000 0.000 0.000 0 2 + AM-ADV 75.987 45.652 57.037 506 304 + AM-CAU 73.333 43.421 54.545 76 45 + AM-DIR 42.308 51.765 46.561 85 104 + AM-DIS 75.833 85.313 80.294 320 360 + AM-EXT 50.000 50.000 50.000 32 32 + AM-LOC 59.244 38.525 46.689 366 238 + AM-MNR 34.126 70.115 45.908 348 715 + AM-MOD 97.513 99.637 98.564 551 563 + AM-NEG 97.854 99.130 98.488 230 233 + AM-PNC 57.333 37.391 45.263 115 75 + AM-PRD 0.000 0.000 0.000 5 11 + AM-REC 0.000 0.000 0.000 2 0 + AM-TMP 75.690 76.097 75.893 1117 1123 + C-A0 83.333 27.778 41.667 18 6 + C-A1 68.465 72.052 70.213 229 241 + C-A2 14.286 40.000 21.053 5 14 + C-A3 0.000 0.000 0.000 3 11 + C-A4 0.000 0.000 0.000 0 7 + C-A5 0.000 0.000 0.000 0 1 + C-AM-ADV 0.000 0.000 0.000 0 1 + C-AM-DIR 0.000 0.000 0.000 0 3 + C-AM-EXT 0.000 0.000 0.000 0 1 + C-AM-LOC 0.000 0.000 0.000 0 1 + C-AM-MNR 0.000 0.000 0.000 0 7 + C-AM-NEG 0.000 0.000 0.000 0 3 + C-AM-PNC 0.000 0.000 0.000 0 1 + C-V 0.000 0.000 0.000 141 31 + R-A0 85.388 88.208 86.775 212 219 + R-A1 68.919 77.863 73.118 131 148 + R-A2 62.500 38.462 47.619 13 8 + R-A3 0.000 0.000 0.000 1 0 + R-A4 0.000 0.000 0.000 1 7 + R-AM-ADV 0.000 0.000 0.000 2 1 + R-AM-CAU 0.000 0.000 0.000 1 3 + R-AM-EXT 0.000 0.000 0.000 1 3 + R-AM-LOC 69.231 56.250 62.069 16 13 + R-AM-MNR 0.000 0.000 0.000 2 5 + R-AM-PNC 0.000 0.000 0.000 0 3 + ---------------------------------------------- + R-AM-TMP 16.667 5.556 8.333 18 6 + ---------------------------------------------- + Overall 82.644 82.644 82.644 14479 14479 + Accuracy 82.644 - - - 14479 + + Total time: 244961 s, completed Dec 2, 2016 11:08:22 AM + + - [x] **[jTr]** Train aTr jointly without considering the loss explicitly; test using constraints + + Label Precision Recall F1 LCount PCount + ---------------------------------------------- + A0 96.425 93.488 94.934 3578 3469 + A1 91.531 94.000 92.749 4967 5101 + A2 67.846 76.173 71.769 1108 1244 + A3 78.652 40.698 53.640 172 89 + A4 83.951 66.667 74.317 102 81 + A5 57.143 80.000 66.667 5 7 + AA 0.000 0.000 0.000 0 2 + AM-ADV 68.623 60.079 64.067 506 443 + AM-CAU 80.952 44.737 57.627 76 42 + AM-DIR 43.220 60.000 50.246 85 118 + AM-DIS 81.250 81.250 81.250 320 320 + AM-EXT 33.333 68.750 44.898 32 66 + AM-LOC 83.969 30.055 44.266 366 131 + AM-MNR 51.940 50.000 50.952 348 335 + AM-MOD 97.340 99.637 98.475 551 564 + AM-NEG 96.624 99.565 98.073 230 237 + AM-PNC 22.118 81.739 34.815 115 425 + AM-PRD 16.667 20.000 18.182 5 6 + AM-REC 0.000 0.000 0.000 2 6 + AM-TMP 84.706 70.904 77.193 1117 935 + C-A0 21.154 61.111 31.429 18 52 + C-A1 60.067 78.166 67.932 229 298 + C-A2 0.000 0.000 0.000 5 11 + C-A3 0.000 0.000 0.000 3 4 + C-A4 0.000 0.000 0.000 0 3 + C-A5 0.000 0.000 0.000 0 1 + C-AM-DIR 0.000 0.000 0.000 0 3 + C-AM-EXT 0.000 0.000 0.000 0 3 + C-AM-LOC 0.000 0.000 0.000 0 1 + C-AM-MNR 0.000 0.000 0.000 0 2 + C-AM-NEG 0.000 0.000 0.000 0 8 + C-AM-PNC 0.000 0.000 0.000 0 6 + C-AM-TMP 0.000 0.000 0.000 0 1 + C-V 0.000 0.000 0.000 141 31 + R-A0 82.427 92.925 87.361 212 239 + R-A1 79.612 62.595 70.085 131 103 + R-A2 21.875 53.846 31.111 13 32 + R-A3 0.000 0.000 0.000 1 0 + R-A4 0.000 0.000 0.000 1 1 + R-AM-ADV 0.000 0.000 0.000 2 1 + R-AM-CAU 0.000 0.000 0.000 1 2 + R-AM-EXT 0.000 0.000 0.000 1 7 + R-AM-LOC 78.571 68.750 73.333 16 14 + R-AM-MNR 0.000 0.000 0.000 2 1 + R-AM-PNC 0.000 0.000 0.000 0 6 + ---------------------------------------------- + R-AM-TMP 28.571 44.444 34.783 18 28 + ---------------------------------------------- + Overall 83.673 83.673 83.673 14479 14479 + Accuracy 83.673 - - - 14479 + Total time: 214836 s, completed Nov 20, 2016 9:15:22 AM + + - [ ] **[aTrJ]** Train **dTr, eTr, fTr** jointly * Add constraints gradually and train various models considering subsets of constraints diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index 28249663..f9eb5467 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -27,7 +27,7 @@ object SRLscalaConfigurator { val USE_CURATOR = false // The running mode of the program. Can be "true" for only testing, or "false" for training - val RUN_MODE: Boolean = false + val TEST_MODE: Boolean = true // The training mode for the examples. Can be "pipeline", "joint", "jointLoss" or "other" val TRAINING_MODE = "other" @@ -55,7 +55,7 @@ object SRLscalaConfigurator { // Should we use the pipeline during testing val SRL_TEST_PIPELINE = false // Should we use constraints during testing - val SRL_TEST_CONSTRAINTS = false + val SRL_TEST_CONSTRAINTS = true /*Training parameters*/ @@ -93,7 +93,7 @@ object SRLApps extends Logging { logger.info("population starts.") // Here, the data is loaded into the graph - val srlDataModelObject = PopulateSRLDataModel(testOnly = RUN_MODE, SRL_GOLD_PREDICATES, SRL_GOLD_ARG_BOUNDARIES) + val srlDataModelObject = PopulateSRLDataModel(testOnly = TEST_MODE, SRL_GOLD_PREDICATES, SRL_GOLD_ARG_BOUNDARIES) import srlDataModelObject._ @@ -109,7 +109,7 @@ object RunningApps extends App with Logging { import SRLApps.srlDataModelObject._ import SRLscalaConfigurator._ // TRAINING - if (!RUN_MODE) { + if (!TEST_MODE) { expName match { case "aTr" => @@ -193,7 +193,7 @@ object RunningApps extends App with Logging { } // TESTING - if (RUN_MODE) { + if (TEST_MODE) { (SRL_TEST_PIPELINE, SRL_TEST_CONSTRAINTS) match { case (true, true) => diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala index 6ce4c391..adc1d5fd 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala @@ -54,46 +54,46 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram sentencesToStringTree.addSensor(textAnnotationToStringTree _) /** This can be applied to both predicates and arguments */ - val address = property(predicates, "add") { + val address = property(predicates) { x: Constituent => x.getTextAnnotation.getCorpusId + ":" + x.getTextAnnotation.getId + ":" + x.getSpan } // Classification labels - val isPredicateGold = property(predicates, "p") { + val isPredicateGold = property(predicates) { x: Constituent => x.getLabel.equals("Predicate") } - val predicateSenseGold = property(predicates, "s") { + val predicateSenseGold = property(predicates) { x: Constituent => x.getAttribute(AbstractSRLAnnotationReader.SenseIdentifier) } - val isArgumentXuGold = property(relations, "aX") { + val isArgumentXuGold = property(relations) { x: Relation => !x.getRelationName.equals("candidate") } - val argumentLabelGold = property(relations, "l") { + val argumentLabelGold = property(relations) { r: Relation => r.getRelationName } // Features properties - val posTag = property(predicates, "posC") { + val posTag = property(predicates) { x: Constituent => getPOS(x) } - val subcategorization = property(predicates, "subcatC") { + val subcategorization = property(predicates) { x: Constituent => fexFeatureExtractor(x, new SubcategorizationFrame(parseViewName)) } - val phraseType = property(predicates, "phraseTypeC") { + val phraseType = property(predicates) { x: Constituent => fexFeatureExtractor(x, new ParsePhraseType(parseViewName)) } - val headword = property(predicates, "headC") { + val headword = property(predicates) { x: Constituent => fexFeatureExtractor(x, new ParseHeadWordPOS(parseViewName)) } - val syntacticFrame = property(predicates, "synFrameC") { + val syntacticFrame = property(predicates) { x: Constituent => fexFeatureExtractor(x, new SyntacticFrame(parseViewName)) } - val path = property(predicates, "pathC") { + val path = property(predicates) { x: Constituent => fexFeatureExtractor(x, new ParsePath(parseViewName)) } @@ -101,113 +101,113 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram // x: Relation => fexFeatureExtractor(x.getTarget, new SubcategorizationFrame(parseViewName)) // } - val phraseTypeRelation = property(relations, "phraseType") { + val phraseTypeRelation = property(relations) { x: Relation => fexFeatureExtractor(x.getTarget, new ParsePhraseType(parseViewName)) } - val headwordRelation = property(relations, "head") { + val headwordRelation = property(relations) { x: Relation => fexFeatureExtractor(x.getTarget, new ParseHeadWordPOS(parseViewName)) } - val syntacticFrameRelation = property(relations, "synFrame") { + val syntacticFrameRelation = property(relations) { x: Relation => fexFeatureExtractor(x.getTarget, new SyntacticFrame(parseViewName)) } - val pathRelation = property(relations, "path") { + val pathRelation = property(relations) { x: Relation => fexFeatureExtractor(x.getTarget, new ParsePath(parseViewName)) } - val predPosTag = property(relations, "pPos") { + val predPosTag = property(relations) { x: Relation => getPOS(x.getSource) } - val predLemmaR = property(relations, "pLem") { + val predLemmaR = property(relations) { x: Relation => getLemma(x.getSource) } - val predLemmaP = property(predicates, "pLem") { + val predLemmaP = property(predicates) { x: Constituent => getLemma(x) } - val linearPosition = property(relations, "position") { + val linearPosition = property(relations) { x: Relation => fexFeatureExtractor(x.getTarget, new LinearPosition()) } - val voice = property(predicates, "voice") { + val voice = property(predicates) { x: Constituent => fexFeatureExtractor(x, new VerbVoiceIndicator(parseViewName)) } - val predWordWindow = property(predicates, "predWordWindow") { + val predWordWindow = property(predicates) { x: Constituent => fexContextFeats(x, WordFeatureExtractorFactory.word) } - val predPOSWindow = property(predicates, "predPOSWindow") { + val predPOSWindow = property(predicates) { x: Constituent => fexContextFeats(x, WordFeatureExtractorFactory.pos) } - val argWordWindow = property(relations, "argWordWindow") { + val argWordWindow = property(relations) { rel: Relation => fexContextFeats(rel.getTarget, WordFeatureExtractorFactory.word) } - val argPOSWindow = property(relations, "argPOSWindow") { + val argPOSWindow = property(relations) { rel: Relation => fexContextFeats(rel.getTarget, WordFeatureExtractorFactory.pos) } - val verbClass = property(predicates, "verbClass") { + val verbClass = property(predicates) { x: Constituent => frameManager.getAllClasses(getLemma(x)).toList } - val constituentLength = property(relations, "constLength") { + val constituentLength = property(relations) { rel: Relation => rel.getTarget.getEndSpan - rel.getTarget.getStartSpan } - val chunkLength = property(relations, "chunkLength") { + val chunkLength = property(relations) { rel: Relation => rel.getTarget.getTextAnnotation.getView(ViewNames.SHALLOW_PARSE).getConstituentsCovering(rel.getTarget).length } - val chunkEmbedding = property(relations, "chunkEmbedding") { + val chunkEmbedding = property(relations) { rel: Relation => fexFeatureExtractor(rel.getTarget, new ChunkEmbedding(ViewNames.SHALLOW_PARSE)) } - val chunkPathPattern = property(relations, "chunkPath") { + val chunkPathPattern = property(relations) { rel: Relation => fexFeatureExtractor(rel.getTarget, new ChunkPathPattern(ViewNames.SHALLOW_PARSE)) } /** Combines clause relative position and clause coverage */ - val clauseFeatures = property(relations, "clauseFeats") { + val clauseFeatures = property(relations) { rel: Relation => val clauseViewName = if (parseViewName.equals(ViewNames.PARSE_GOLD)) "CLAUSES_GOLD" else ViewNames.CLAUSES_STANFORD fexFeatureExtractor(rel.getTarget, new ClauseFeatureExtractor(parseViewName, clauseViewName)) } - val containsNEG = property(relations, "containsNEG") { + val containsNEG = property(relations) { rel: Relation => fexFeatureExtractor(rel.getTarget, ChunkPropertyFeatureFactory.isNegated) } - val containsMOD = property(relations, "containsMOD") { + val containsMOD = property(relations) { rel: Relation => fexFeatureExtractor(rel.getTarget, ChunkPropertyFeatureFactory.hasModalVerb) } // Frame properties - val legalSenses = property(relations, "legalSens") { + val legalSenses = property(relations) { x: Relation => frameManager.getLegalSenses(predLemmaR(x)).toList } - val legalArguments = property(predicates, "legalArgs") { + val legalArguments = property(predicates) { x: Constituent => frameManager.getLegalArguments(predLemmaP(x)).toList } // Classifiers as properties - val isPredicatePrediction = property(predicates, "isPredicatePrediction") { + val isPredicatePrediction = property(predicates) { x: Constituent => predicateClassifier(x) } - val isArgumentPrediction = property(relations, "isArgumentPrediction") { + val isArgumentPrediction = property(relations) { x: Relation => argumentXuIdentifierGivenApredicate(x) } - val isArgumentPipePrediction = property(relations, "isArgumentPipePrediction") { + val isArgumentPipePrediction = property(relations) { x: Relation => predicateClassifier(x.getSource) match { case "false" => "false" @@ -216,7 +216,7 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram } } - val typeArgumentPrediction = property(relations, "typeArgumentPrediction") { + val typeArgumentPrediction = property(relations) { x: Relation => argumentTypeLearner(x) } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala index 1602d462..2ad282cb 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala @@ -9,12 +9,9 @@ package edu.illinois.cs.cogcomp.saulexamples.nlp import java.util.Properties import edu.illinois.cs.cogcomp.annotation.AnnotatorService -import edu.illinois.cs.cogcomp.core.datastructures.ViewNames -import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{ TextAnnotation, TokenLabelView } -import edu.illinois.cs.cogcomp.core.utilities.configuration.{ Configurator, Property, ResourceManager } -import edu.illinois.cs.cogcomp.curator.{ CuratorConfigurator, CuratorFactory } -import edu.illinois.cs.cogcomp.curator.CuratorConfigurator._ -import edu.illinois.cs.cogcomp.nlp.common.PipelineConfigurator._ +import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{TextAnnotation, TokenLabelView} +import edu.illinois.cs.cogcomp.core.utilities.configuration.{Configurator, Property, ResourceManager} +import edu.illinois.cs.cogcomp.curator.{CuratorConfigurator, CuratorFactory} import edu.illinois.cs.cogcomp.nlp.pipeline.IllinoisPipelineFactory /** Created by taher on 7/30/16. From a65cd4ed8be85feb2bda88fee5f40e37f692fb63 Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 2 Dec 2016 19:34:21 -0600 Subject: [PATCH 33/37] -brought the logger messages back -SRL configuration back to its original -some more documentation - returned the symbol names back because of existing trained models! - --- .../classifier/ConstrainedClassifier.scala | 12 +-- .../SemanticRoleLabeling/SRLConfigurator.java | 4 +- .../nlp/SemanticRoleLabeling/README.md | 5 +- .../SRLMultiGraphDataModel.scala | 76 +++++++++---------- .../nlp/TextAnnotationFactory.scala | 6 +- 5 files changed, 53 insertions(+), 50 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala index 69a1009d..337956f6 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/classifier/ConstrainedClassifier.scala @@ -69,13 +69,13 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi val l = pathToHead.get.forward.neighborsOf(x).toSet.toList if (l.isEmpty) { - //logger.error("Warning: Failed to find head") + logger.error("Warning: Failed to find head") None } else if (l.size != 1) { - //logger.warn("Find too many heads") + logger.warn("Find too many heads") Some(l.head) } else { - //logger.info(s"Found head ${l.head} for child $x") + logger.info(s"Found head ${l.head} for child $x") Some(l.head) } } @@ -88,7 +88,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi val l = pathToHead.get.backward.neighborsOf(head) if (l.isEmpty) { - //logger.error("Failed to find part") + logger.error("Failed to find part") Seq.empty[T] } else { l.filter(filter(_, head)).toSeq @@ -103,7 +103,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi var inference = InferenceManager.get(name, head) if (inference == null) { inference = infer(head) - // logger.warn(s"Inference ${name} has not been cached; running inference . . . ") + logger.warn(s"Inference ${name} has not been cached; running inference . . . ") InferenceManager.put(name, inference) } inference.valueOf(cls, t) @@ -141,7 +141,7 @@ abstract class ConstrainedClassifier[T <: AnyRef, HEAD <: AnyRef](val onClassifi .orElse({ onClassifier match { case clf: Learnable[T] => Some(clf.node) - case _ => None //logger.error("pathToHead is not provided and the onClassifier is not a Learnable!"); None + case _ => logger.error("pathToHead is not provided and the onClassifier is not a Learnable!"); None } }) .map(node => node.getTestingInstances) diff --git a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java index fa81be41..a1ad3b03 100644 --- a/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java +++ b/saul-examples/src/main/java/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConfigurator.java @@ -27,10 +27,10 @@ public class SRLConfigurator extends Configurator { public static final Property USE_CURATOR = new Property("useCurator", Configurator.FALSE); // The running mode of the program. Can be "true" for only testing, or "false" for training - public static final Property RUN_MODE = new Property("runMode", Configurator.FALSE); + public static final Property RUN_MODE = new Property("runMode", Configurator.TRUE); // The training mode for the examples. Can be "pipeline", "joint", "jointLoss" or "other" - public static final Property TRAINING_MODE = new Property("trainingMode", "jointLoss"); + public static final Property TRAINING_MODE = new Property("trainingMode", "joint"); /*********** SRL PROPERTIES ***********/ // The (sub)directory to store and retrieve the trained SRL models (to be used with MODELS_DIR) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md index 20daf583..43fafeaf 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/README.md @@ -694,7 +694,6 @@ In the following lines `Pred.` stands for "Predicate" and `Cand.` stands for "C  Total time: 214836 s, completed Nov 20, 2016 9:15:22 AM - - [ ] **[aTrJ]** Train **dTr, eTr, fTr** jointly * Add constraints gradually and train various models considering subsets of constraints - [ ] **[aTr]** @@ -703,3 +702,7 @@ In the following lines `Pred.` stands for "Predicate" and `Cand.` stands for "C - [ ] **[aTsJ]** Test the **cTs** of the second phase for joint models. +The training results of independent models are after 100 iterations of training, however, since joinnTraining is computationally much more +complex, we stopped the training after 30 iterations. +The overall results were similar to running independent models after 30 iterations, no improvment observed. +However, there was a per class variation in results and the results for some of the lables improved. \ No newline at end of file diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala index adc1d5fd..6ce4c391 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLMultiGraphDataModel.scala @@ -54,46 +54,46 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram sentencesToStringTree.addSensor(textAnnotationToStringTree _) /** This can be applied to both predicates and arguments */ - val address = property(predicates) { + val address = property(predicates, "add") { x: Constituent => x.getTextAnnotation.getCorpusId + ":" + x.getTextAnnotation.getId + ":" + x.getSpan } // Classification labels - val isPredicateGold = property(predicates) { + val isPredicateGold = property(predicates, "p") { x: Constituent => x.getLabel.equals("Predicate") } - val predicateSenseGold = property(predicates) { + val predicateSenseGold = property(predicates, "s") { x: Constituent => x.getAttribute(AbstractSRLAnnotationReader.SenseIdentifier) } - val isArgumentXuGold = property(relations) { + val isArgumentXuGold = property(relations, "aX") { x: Relation => !x.getRelationName.equals("candidate") } - val argumentLabelGold = property(relations) { + val argumentLabelGold = property(relations, "l") { r: Relation => r.getRelationName } // Features properties - val posTag = property(predicates) { + val posTag = property(predicates, "posC") { x: Constituent => getPOS(x) } - val subcategorization = property(predicates) { + val subcategorization = property(predicates, "subcatC") { x: Constituent => fexFeatureExtractor(x, new SubcategorizationFrame(parseViewName)) } - val phraseType = property(predicates) { + val phraseType = property(predicates, "phraseTypeC") { x: Constituent => fexFeatureExtractor(x, new ParsePhraseType(parseViewName)) } - val headword = property(predicates) { + val headword = property(predicates, "headC") { x: Constituent => fexFeatureExtractor(x, new ParseHeadWordPOS(parseViewName)) } - val syntacticFrame = property(predicates) { + val syntacticFrame = property(predicates, "synFrameC") { x: Constituent => fexFeatureExtractor(x, new SyntacticFrame(parseViewName)) } - val path = property(predicates) { + val path = property(predicates, "pathC") { x: Constituent => fexFeatureExtractor(x, new ParsePath(parseViewName)) } @@ -101,113 +101,113 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram // x: Relation => fexFeatureExtractor(x.getTarget, new SubcategorizationFrame(parseViewName)) // } - val phraseTypeRelation = property(relations) { + val phraseTypeRelation = property(relations, "phraseType") { x: Relation => fexFeatureExtractor(x.getTarget, new ParsePhraseType(parseViewName)) } - val headwordRelation = property(relations) { + val headwordRelation = property(relations, "head") { x: Relation => fexFeatureExtractor(x.getTarget, new ParseHeadWordPOS(parseViewName)) } - val syntacticFrameRelation = property(relations) { + val syntacticFrameRelation = property(relations, "synFrame") { x: Relation => fexFeatureExtractor(x.getTarget, new SyntacticFrame(parseViewName)) } - val pathRelation = property(relations) { + val pathRelation = property(relations, "path") { x: Relation => fexFeatureExtractor(x.getTarget, new ParsePath(parseViewName)) } - val predPosTag = property(relations) { + val predPosTag = property(relations, "pPos") { x: Relation => getPOS(x.getSource) } - val predLemmaR = property(relations) { + val predLemmaR = property(relations, "pLem") { x: Relation => getLemma(x.getSource) } - val predLemmaP = property(predicates) { + val predLemmaP = property(predicates, "pLem") { x: Constituent => getLemma(x) } - val linearPosition = property(relations) { + val linearPosition = property(relations, "position") { x: Relation => fexFeatureExtractor(x.getTarget, new LinearPosition()) } - val voice = property(predicates) { + val voice = property(predicates, "voice") { x: Constituent => fexFeatureExtractor(x, new VerbVoiceIndicator(parseViewName)) } - val predWordWindow = property(predicates) { + val predWordWindow = property(predicates, "predWordWindow") { x: Constituent => fexContextFeats(x, WordFeatureExtractorFactory.word) } - val predPOSWindow = property(predicates) { + val predPOSWindow = property(predicates, "predPOSWindow") { x: Constituent => fexContextFeats(x, WordFeatureExtractorFactory.pos) } - val argWordWindow = property(relations) { + val argWordWindow = property(relations, "argWordWindow") { rel: Relation => fexContextFeats(rel.getTarget, WordFeatureExtractorFactory.word) } - val argPOSWindow = property(relations) { + val argPOSWindow = property(relations, "argPOSWindow") { rel: Relation => fexContextFeats(rel.getTarget, WordFeatureExtractorFactory.pos) } - val verbClass = property(predicates) { + val verbClass = property(predicates, "verbClass") { x: Constituent => frameManager.getAllClasses(getLemma(x)).toList } - val constituentLength = property(relations) { + val constituentLength = property(relations, "constLength") { rel: Relation => rel.getTarget.getEndSpan - rel.getTarget.getStartSpan } - val chunkLength = property(relations) { + val chunkLength = property(relations, "chunkLength") { rel: Relation => rel.getTarget.getTextAnnotation.getView(ViewNames.SHALLOW_PARSE).getConstituentsCovering(rel.getTarget).length } - val chunkEmbedding = property(relations) { + val chunkEmbedding = property(relations, "chunkEmbedding") { rel: Relation => fexFeatureExtractor(rel.getTarget, new ChunkEmbedding(ViewNames.SHALLOW_PARSE)) } - val chunkPathPattern = property(relations) { + val chunkPathPattern = property(relations, "chunkPath") { rel: Relation => fexFeatureExtractor(rel.getTarget, new ChunkPathPattern(ViewNames.SHALLOW_PARSE)) } /** Combines clause relative position and clause coverage */ - val clauseFeatures = property(relations) { + val clauseFeatures = property(relations, "clauseFeats") { rel: Relation => val clauseViewName = if (parseViewName.equals(ViewNames.PARSE_GOLD)) "CLAUSES_GOLD" else ViewNames.CLAUSES_STANFORD fexFeatureExtractor(rel.getTarget, new ClauseFeatureExtractor(parseViewName, clauseViewName)) } - val containsNEG = property(relations) { + val containsNEG = property(relations, "containsNEG") { rel: Relation => fexFeatureExtractor(rel.getTarget, ChunkPropertyFeatureFactory.isNegated) } - val containsMOD = property(relations) { + val containsMOD = property(relations, "containsMOD") { rel: Relation => fexFeatureExtractor(rel.getTarget, ChunkPropertyFeatureFactory.hasModalVerb) } // Frame properties - val legalSenses = property(relations) { + val legalSenses = property(relations, "legalSens") { x: Relation => frameManager.getLegalSenses(predLemmaR(x)).toList } - val legalArguments = property(predicates) { + val legalArguments = property(predicates, "legalArgs") { x: Constituent => frameManager.getLegalArguments(predLemmaP(x)).toList } // Classifiers as properties - val isPredicatePrediction = property(predicates) { + val isPredicatePrediction = property(predicates, "isPredicatePrediction") { x: Constituent => predicateClassifier(x) } - val isArgumentPrediction = property(relations) { + val isArgumentPrediction = property(relations, "isArgumentPrediction") { x: Relation => argumentXuIdentifierGivenApredicate(x) } - val isArgumentPipePrediction = property(relations) { + val isArgumentPipePrediction = property(relations, "isArgumentPipePrediction") { x: Relation => predicateClassifier(x.getSource) match { case "false" => "false" @@ -216,7 +216,7 @@ class SRLMultiGraphDataModel(parseViewName: String = null, frameManager: SRLFram } } - val typeArgumentPrediction = property(relations) { + val typeArgumentPrediction = property(relations, "typeArgumentPrediction") { x: Relation => argumentTypeLearner(x) } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala index 2ad282cb..2620b50a 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/TextAnnotationFactory.scala @@ -9,9 +9,9 @@ package edu.illinois.cs.cogcomp.saulexamples.nlp import java.util.Properties import edu.illinois.cs.cogcomp.annotation.AnnotatorService -import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{TextAnnotation, TokenLabelView} -import edu.illinois.cs.cogcomp.core.utilities.configuration.{Configurator, Property, ResourceManager} -import edu.illinois.cs.cogcomp.curator.{CuratorConfigurator, CuratorFactory} +import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{ TextAnnotation, TokenLabelView } +import edu.illinois.cs.cogcomp.core.utilities.configuration.{ Configurator, Property, ResourceManager } +import edu.illinois.cs.cogcomp.curator.{ CuratorConfigurator, CuratorFactory } import edu.illinois.cs.cogcomp.nlp.pipeline.IllinoisPipelineFactory /** Created by taher on 7/30/16. From bcdba7e65b2b111fef55979236c3060ecfdf50ff Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 2 Dec 2016 21:18:37 -0600 Subject: [PATCH 34/37] -changed back the solver for tests --- .../nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala index 2c1fbf80..cab81f68 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLConstrainedClassifiers.scala @@ -7,7 +7,7 @@ package edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling import edu.illinois.cs.cogcomp.core.datastructures.textannotation.{ Relation, TextAnnotation } -import edu.illinois.cs.cogcomp.infer.ilp.GurobiHook +import edu.illinois.cs.cogcomp.infer.ilp.OJalgoHook import edu.illinois.cs.cogcomp.saul.classifier.ConstrainedClassifier import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLClassifiers.{ argumentTypeLearner, argumentXuIdentifierGivenApredicate } import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstraints._ @@ -16,7 +16,7 @@ import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstrai */ object SRLConstrainedClassifiers { import SRLApps.srlDataModelObject._ - val erSolver = new GurobiHook + val erSolver = new OJalgoHook object argTypeConstraintClassifier extends ConstrainedClassifier[Relation, TextAnnotation](argumentTypeLearner) { def subjectTo = r_and_c_args From dab55f1a9cdcd50e8b60363150770f47a72dfdcc Mon Sep 17 00:00:00 2001 From: kordjam Date: Fri, 2 Dec 2016 21:49:27 -0600 Subject: [PATCH 35/37] -changed back the commented out join node population -changed back all paths and config to SRL toy --- .../illinois/cs/cogcomp/saul/datamodel/node/Node.scala | 2 +- .../nlp/SemanticRoleLabeling/SRLApps.scala | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala index 0783e2df..46f6b4b8 100644 --- a/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala +++ b/saul-core/src/main/scala/edu/illinois/cs/cogcomp/saul/datamodel/node/Node.scala @@ -127,7 +127,7 @@ class Node[T <: AnyRef](val keyFunc: T => Any = (x: T) => x, val tag: ClassTag[T } // TODO: Populating join nodes takes significant amount of time on large graphs. Investigate. - //joinNodes.foreach(_.addFromChild(this, instance, train, populateEdge)) + joinNodes.foreach(_.addFromChild(this, instance, train, populateEdge)) } } diff --git a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala index f9eb5467..9970b93b 100644 --- a/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala +++ b/saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/nlp/SemanticRoleLabeling/SRLApps.scala @@ -16,10 +16,10 @@ import edu.illinois.cs.cogcomp.saulexamples.nlp.SemanticRoleLabeling.SRLConstrai object SRLscalaConfigurator { - val TREEBANK_HOME = "../data/treebank" - val PROPBANK_HOME = "../data/propbank" + val TREEBANK_HOME = "../saul-examples/src/test/resources/SRLToy/treebank" + val PROPBANK_HOME = "../saul-examples/src/test/resources/SRLToy/propbank" - val TEST_SECTION = 23 + val TEST_SECTION = 0 val TRAIN_SECTION_S = 2 val TRAIN_SECTION_E = 21 @@ -30,7 +30,7 @@ object SRLscalaConfigurator { val TEST_MODE: Boolean = true // The training mode for the examples. Can be "pipeline", "joint", "jointLoss" or "other" - val TRAINING_MODE = "other" + val TRAINING_MODE = "joint" /*********** SRL PROPERTIES ***********/ // The (sub)directory to store and retrieve the trained SRL models (to be used with MODELS_DIR) @@ -55,7 +55,7 @@ object SRLscalaConfigurator { // Should we use the pipeline during testing val SRL_TEST_PIPELINE = false // Should we use constraints during testing - val SRL_TEST_CONSTRAINTS = true + val SRL_TEST_CONSTRAINTS = false /*Training parameters*/ From 4d8f361f07cf4814d76903513d48d6d0280af793 Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 5 Dec 2016 15:08:57 -0600 Subject: [PATCH 36/37] -fixed typos in blocking -fixed url --- saul-core/doc/MODELS.md | 24 +++++++++++++----------- saul-core/doc/SAULLANGUAGE.md | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index 857d8c4c..d8e53835 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -106,6 +106,7 @@ feature function. That is, the loss is a hamming loss defined per classifier. Th ##Pipelines + Building pipelines is naturally granted in Saul. The programmer can simply define properties that are the predictions of the classifiers and use those outputs as the input of other classifiers by mentioning them in the list of the properties in the below construct when defining the pipeline classifiers, @@ -113,24 +114,25 @@ pipeline classifiers, ```scala def feature = using(/*list of properties including the prediction of other classifiers.*/) ``` + Here is a more complete example which passes the output of the `ClassifierLayer1` to the input of the `ClassifierLayer2`: ```scala - - object ClassifierLayer1 extends Learnable (node) { - def label = labelProperty1 - def feature = using(property2, property3,...) + object ClassifierLayer1 extends Learnable (node) { + def label = labelProperty1 + def feature = using(property2, property3,...) } - - object ClassifierLayer2 extends Learnable (node) { - def label = labelProperty2 - def feature = using(classifier1Labels, ,...) // using the prediction of the classifier in the previous layer + object ClassifierLayer2 extends Learnable (node) { + def label = labelProperty2 + def feature = using(classifier1Labels, ,...) // using the prediction of the classifier in the previous layer } + ``` - // defined in data-model object - val classifier1Labels = new Property(node){ x: Type => ClassifierLayer1(x) } + This will be defined in data-model object: - ``` + ```scala + val classifier1Labels = new Property(node){ x: Type => ClassifierLayer1(x) } + ``` See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala#L43), for a working example. diff --git a/saul-core/doc/SAULLANGUAGE.md b/saul-core/doc/SAULLANGUAGE.md index fd74eb4f..f4cab89a 100644 --- a/saul-core/doc/SAULLANGUAGE.md +++ b/saul-core/doc/SAULLANGUAGE.md @@ -35,7 +35,7 @@ OrgClassifier.test() ### Availale algorithms Here is a list of available algorithms in Saul: - - [LBJava learning algorithms](https://githu/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) + - [LBJava learning algorithms](https://github.com/IllinoisCogComp/lbjava/blob/master/lbjava/doc/ALGORITHMS.md) - [Weka learning algorithms](saul-core/src/main/java/edu/illinois/cs/cogcomp/saul/learn/SaulWekaWrapper.md) From b0baf944903a44302b45f9ba5096f10b6e307f29 Mon Sep 17 00:00:00 2001 From: kordjam Date: Mon, 5 Dec 2016 15:12:32 -0600 Subject: [PATCH 37/37] -fixed typos in blocking --- saul-core/doc/MODELS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/saul-core/doc/MODELS.md b/saul-core/doc/MODELS.md index d8e53835..10df04df 100644 --- a/saul-core/doc/MODELS.md +++ b/saul-core/doc/MODELS.md @@ -126,15 +126,15 @@ Here is a more complete example which passes the output of the `ClassifierLayer1 def label = labelProperty2 def feature = using(classifier1Labels, ,...) // using the prediction of the classifier in the previous layer } - ``` + ``` - This will be defined in data-model object: +This will be defined in data-model object: ```scala val classifier1Labels = new Property(node){ x: Type => ClassifierLayer1(x) } ``` -See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala#L43), for a working example. +See [here](saul-examples/src/main/scala/edu/illinois/cs/cogcomp/saulexamples/Badge/BadgeClassifiers.scala#L43) for a working example.