title: Thread-safe or multithreaded CRF in Java with support for continuous variables?
body: <p>I want to use Mallet to run Conditional Random Fields in a Leave-One-Sequence-Out manner on a rather large data set. Therefore I need multithreaded computation to handle this computationally, either by 1) training multiple CRFs in parallel, with each CRF being trained on a single thread, or 2) training each CRF in a multithreaded manner.</p>
  
  <p>In the Mallet API I found a multithreaded version of a CRF trainer, cc.mallet.fst.CRFTrainerByThreadedLabelLikelihood.java, which implements option 2. However, in my situation I need support for continuous variables, for which fst does not seem to have support and for which GRMM seems needed. With a small adjustment I managed to let GRMM handle continuous inputs. For GRMM however, as far as I was able to find, there seems to be no support for multithreaded training through option 2 like in fst.</p>
  
  <p>As an alternative, I implemented option 1, in which I train the CRFs for the folds of the experiment in parallel in different threads. I use my own build of the Minmo/Mallet github version of Mallet, checked out on the 26th of August 2015. The GRMM code however seems to be not thread safe, as exceptions are thrown when I run the code in parallel while these exceptions are not thrown when I run the same code while using a single thread. Also, the prediction accuracy is significantly lower when the CRFs are trained in parallel, when I simply catch the exceptions and let the execution continue. The exception thrown when executed on multiple threads is the following:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Assignment does not give a value for variable I216_VAR[f=0][tm=38]
      at cc.mallet.grmm.types.Assignment.get(Assignment.java:337)
      at cc.mallet.grmm.types.Assignment.get(Assignment.java:315)
      at cc.mallet.grmm.types.LogTableFactor.rawValue(LogTableFactor.java:255)
      at cc.mallet.grmm.types.LogTableFactor.logValue(LogTableFactor.java:219)
      at cc.mallet.grmm.inference.AbstractBeliefPropagation.lookupLogJoint(AbstractBeliefPropagation.java:553)
      at cc.mallet.grmm.learning.ACRF$MaximizableACRF.computeLogLikelihood(ACRF.java:1348)
      at cc.mallet.grmm.learning.ACRF$MaximizableACRF.getValue(ACRF.java:1270)
      at cc.mallet.optimize.LimitedMemoryBFGS.optimize(LimitedMemoryBFGS.java:99)
      at cc.mallet.grmm.learning.DefaultAcrfTrainer.train(DefaultAcrfTrainer.java:207)
      at cc.mallet.grmm.learning.DefaultAcrfTrainer.train(DefaultAcrfTrainer.java:119)
  </code></pre>
  
  <p>Is there any way to circumvent these problems and train Conditional Random Fields with continuous variables in a multithreaded way, either by training each CRF multithreaded, or by training multiple CRFs in different threads simultaneously? Preferably by using Mallet (fst or GRMM), as that would safe me the time of switching, but I would be open to any other CRF/PGM Java library as well.</p>