Skip to content

Instantly share code, notes, and snippets.

@alextp
Created January 27, 2013 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextp/4650028 to your computer and use it in GitHub Desktop.
Save alextp/4650028 to your computer and use it in GitHub Desktop.
serialize(modelFile+"-iter-"+trainer.iteration)
val other = ClassifierPos.load(modelFile+"-iter-"+trainer.iteration)
val od = other.ClassifierPosFeatureDomain.dimensionDomain
val s0 = testDocs.head.sentences.head
val sd0 = new SentenceData(s0)
val sd1 = new other.SentenceData(s0)
sd0.lemmas.zipWithIndex.foreach(l => assert(sd1.lemmas(l._2) == l._1))
val f0 = new SparseBinaryTensor1(ClassifierPosFeatureDomain.dimensionDomain.size)
val f1 = new SparseBinaryTensor1(other.ClassifierPosFeatureDomain.dimensionDomain.size)
assert(ClassifierPosFeatureDomain.dimensionDomain.size == other.ClassifierPosFeatureDomain.dimensionDomain.size)
for (t <- 0 until s0.length) {
addFeatures(sd0, t, f0)
other.addFeatures(sd1, t, f1)
val p00 = model.evidenceTemplate.weights * f0
val p01 = model.evidenceTemplate.weights * f1
val p10 = other.model.evidenceTemplate.weights * f0
val p11 = other.model.evidenceTemplate.weights * f1
for (i <- 0 until p00.length) {
assert(p00(i) == p01(i), "values " + p00 + " " + p01)
assert(p00(i) == p10(i), "values " + p00 + " " + p10)
assert(p00(i) == p11(i), "values " + p00 + " " + p11)
}
assert(p00.maxIndex == p01.maxIndex)
assert(p00.maxIndex == p10.maxIndex)
assert(p00.maxIndex == p11.maxIndex)
s0.tokens(t).posLabel.set(p00.maxIndex)(null)
}
testDocs.foreach(other.process(_))
println("Other accuracy: " + HammingObjective.accuracy(testDocs.flatMap(t => t.tokens).map(t => t.attr[PosLabel])))
testDocs.foreach(process(_))
println("This accuracy: " + HammingObjective.accuracy(testDocs.flatMap(t => t.tokens).map(t => t.attr[PosLabel])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment