Possible bug in MPLP?

17 views
Skip to first unread message

Joshua Cason

unread,
Mar 17, 2015, 2:55:52 PM3/17/15
to dis...@factorie.cs.umass.edu

Hi,


While using the MPLP inferencer I sometimes get the following error.


java.util.NoSuchElementException: key not found: MyLabel(labelValue)


I looked at the code, and (1) it seems like there could be a source of error there, but (2) this particular error doesn't make sense - it should have found the MyLabel.


The error is thrown from line 133 in MPLP.scala:


for (v <- variables) converged = converged && updateMessages(v.asInstanceOf[DiscreteVar], variableFactors(v))


It happens when v is looked up in variableFactors. variableFactors is created here:


for (f <- factors) {

    for (v <- f.varyingVariables) {

        val list = variableFactors.getOrElseUpdate(v, ArrayBuffer[MPLPFactor]())

        list += f}}


And "varyingVariables" is created in MPLPFactor, in the same file on line 30:


val varyingVariables = thisVariables.filter(v => v.isInstanceOf[DiscreteVar]).map(_.asInstanceOf[DiscreteVar]).filter(varying.contains).toSet


So, in line 133 you're iterating over all the variables and looking up in a map created using a filtered subset of them. In theory that should be a problem. But, the key that threw my error shouldn't have been filtered out, so I'm still not sure what the cause of my error is.


Anyway, maybe I'm missing something and that code makes sense. Just thought I would point this out in case not.


One more clue is that I was running inference over my training labels after a training iteration to get training accuracy. A priori that doesn't seem like a problem, but it's worth mentioning. I haven't had this problem running inference on a dev set.


Josh

https://www.linkedin.com/in/joshcason





Luke Vilnis

unread,
Mar 17, 2015, 5:28:14 PM3/17/15
to dis...@factorie.cs.umass.edu
If you only sometimes see this error, is there anything different about instances where you see the error vs when you don't? For example, could it be over structures with only 1 inference variable? Sometimes there are edge cases when there is only one variable to do inference over (this happened a while ago in BP).

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

To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@factorie.cs.umass.edu.

Joshua Cason

unread,
Mar 17, 2015, 5:45:18 PM3/17/15
to dis...@factorie.cs.umass.edu
There is just one inference variable type. But when the factors are gathered, it is potentially connected to multiple other inference variables of the same type (if that's what you mean). I expect that sometimes those templates don't return any factors since it's conditioned on the current global value for them and their connection to the same token in the sentence.

Joshua Cason

unread,
Mar 17, 2015, 9:57:49 PM3/17/15
to dis...@factorie.cs.umass.edu
Apparently I had removed the bias template on the label. When I added it back, the problem went away. Maybe that makes sense? I don't get it :)

Josh

Luke Vilnis

unread,
Mar 17, 2015, 10:03:52 PM3/17/15
to dis...@factorie.cs.umass.edu
OK this makes sense. 

From looking at the infer method in MPLP it appears that the issue is we only add variables to the variableFactors map when they have at least one neighboring factor. If there are no neighboring factors for a variable, we get the exception you observed. 

We can fix it by just changing line 133 to only iterate over variables with at least one neighboring factor, but it's still a bit weird to be doing inference over variables with no factors touching them. I'm not sure what the semantics actually should be (uniform marginals for that variable?)

Thanks for reporting this bug!

Joshua Cason

unread,
Mar 17, 2015, 10:07:15 PM3/17/15
to dis...@factorie.cs.umass.edu
Ok, I see. No problem!

Josh
Reply all
Reply to author
Forward
0 new messages