question on the Quickstart CRF example

40 views
Skip to first unread message

David Portabella

unread,
Mar 21, 2017, 11:23:07 AM3/21/17
to Factorie
The QuickStart guide contains this example:
Linear-chain Conditional Random Field for part-of-speech tagging
http://factorie.cs.umass.edu/usersguide/UsersGuide200QuickStart.html

object ExampleLinearChainCRF extends App {
  class Label(val str:String, val token:Token) extends LabeledCategoricalVariable(str){...}
  class LabelSeq extends scala.collection.mutable.ArrayBuffer[Label]

  val labelSequences: List[LabelSeq] = ...

  val trainer = new BatchTrainer(model.parameters, new ConjugateGradient) 
  trainer.trainFromExamples(labelSequences.map(labels => new LikelihoodExample(labels, model, InferByBPChain)))

  // infer
  labelSequences.foreach(labels => BP.inferChainMax(labels, model))
  labelSequences.foreach(_.foreach(l => println(s"Token: ${l.token.value} Label: ${l.value}")))
}

so, there is a training part and an inference part.

The inference part should taken as input a list of token, and return a list of tagged tokens (token and label).
However, in this example, the BP.inferChainMax takes as input the list of already tagged tokens.
It does not make sense to me.

Can you please explain this example?
Once we have the trained model, how we give it an input of tokens to get a list of tagged tokens?

Nilesh Bhosale

unread,
Sep 11, 2017, 9:31:41 AM9/11/17
to Factorie
Can some explain this ...... any pointer will be helpful.....
 
Can you please explain this example?
Once we have the trained model, how we give it an input of tokens to get a list of tagged tokens?

Luke Vilnis

unread,
Sep 11, 2017, 2:50:11 PM9/11/17
to dis...@factorie.cs.umass.edu
The tagged tokens are just to do evaluation. You can set the tags to 0 or whatever if you dont have ground truth data

--
--
Factorie Discuss group.
To post, email: dis...@factorie.cs.umass.edu
To unsubscribe, email: discuss+unsubscribe@factorie.cs.umass.edu

---
You received this message because you are subscribed to the Google Groups "Factorie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@factorie.cs.umass.edu.

Nilesh Bhosale

unread,
Sep 17, 2017, 11:01:43 AM9/17/17
to Factorie
any example showing use of test label sequence for inference.... i tried setting tags to 0....

// infer
  labelSequences.foreach(labels => BP.inferChainMax(labels, model))




To unsubscribe, email: discuss+u...@factorie.cs.umass.edu


---
You received this message because you are subscribed to the Google Groups "Factorie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@factorie.cs.umass.edu.

Emma Strubell

unread,
Sep 17, 2017, 11:04:26 AM9/17/17
to Factorie
This example should work, can you describe the error in more detail or provide a small example?

Nilesh Bhosale

unread,
Sep 17, 2017, 11:16:02 AM9/17/17
to Factorie
Hi Emma, 
 
 // model is trained using labelSequences data.
 // from trained model want to estimate test data .... not sure about 0 tagging but tried with below code .... 

 val dataT = List("See/0 Spot/0 run/0") // want to predict label for this test data
  val labelSequencesT = for (sentence <- dataT) yield new LabelSeq ++= sentence.split(" ").map(s => {
    val a = s.split("/")
    new Label(a(1), new Token(a(0)))
  })

 // Running inference to predict label for dataT 
 labelSequencesT.foreach(labels => BP.inferChainMax(labels, model))

Wanted to know how to run inference on test data .... any example will be really helpful....

Emma Strubell

unread,
Sep 17, 2017, 11:28:13 AM9/17/17
to Factorie
One thing that I notice is that you are setting the labels to the string "0", which I'm guessing is not in your tag set. Luke was referring to the integer representation of the tag. So you may want to try setting the labels to something in your set of labels (i.e. something in its domain).

Another option is using CategoricalVariable (rather than LabledCategoricalVariable), with the same domain, which doesn't require a label.
Reply all
Reply to author
Forward
0 new messages