Class ChainHelper

java.lang.Object
org.tribuo.classification.sgd.crf.ChainHelper

public final class ChainHelper extends Object
A collection of helper methods for performing training and inference in a CRF.
  • Method Details

    • beliefPropagation

      public static ChainHelper.ChainBPResults beliefPropagation(ChainHelper.ChainCliqueValues scores)
      Runs belief propagation on a linear chain CRF. Uses the linear predictions for each token and the label transition probabilities.
      Parameters:
      scores - Tuple containing the label-label transition matrix, and the per token label scores.
      Returns:
      Tuple containing the normalising constant, the forward values and the backward values.
    • constrainedBeliefPropagation

      public static double constrainedBeliefPropagation(ChainHelper.ChainCliqueValues scores, int[] constraints)
      Runs constrained belief propagation on a linear chain CRF. Uses the linear predictions for each token and the label transition probabilities.

      See:

       "Confidence Estimation for Information Extraction",
       A. Culotta and A. McCallum
       Proceedings of HLT-NAACL 2004: Short Papers, 2004.
       
      Parameters:
      scores - Tuple containing the label-label transition matrix, and the per token label scores.
      constraints - An array of integers, representing the label constraints. -1 signifies no constraint, otherwise it's the label id.
      Returns:
      The normalization constant for this constrained run.
    • viterbi

      Runs Viterbi on a linear chain CRF. Uses the linear predictions for each token and the label transition probabilities.
      Parameters:
      scores - Tuple containing the label-label transition matrix, and the per token label scores.
      Returns:
      Tuple containing the score of the maximum path and the maximum predicted label per token.
    • sumLogProbs

      public static double sumLogProbs(DenseVector input)
      Sums the log probabilities. Must be updated in concert with sumLogProbs(double[]).
      Parameters:
      input - A DenseVector of log probabilities.
      Returns:
      log sum exp input[i].
    • sumLogProbs

      public static double sumLogProbs(double[] input)
      Sums the log probabilities. Must be updated in concert with sumLogProbs(DenseVector).
      Parameters:
      input - A double array of log probabilities.
      Returns:
      log sum exp input[i].