Class ChainHelper
java.lang.Object
org.tribuo.classification.sgd.crf.ChainHelper
A collection of helper methods for performing training and inference in a CRF.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Belief Propagation results.static final class
Clique scores within a chain.static final class
Viterbi output from a linear chain. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChainHelper.ChainBPResults
Runs belief propagation on a linear chain CRF.static double
constrainedBeliefPropagation
(ChainHelper.ChainCliqueValues scores, int[] constraints) Runs constrained belief propagation on a linear chain CRF.static double
sumLogProbs
(double[] input) Sums the log probabilities.static double
sumLogProbs
(DenseVector input) Sums the log probabilities.viterbi
(ChainHelper.ChainCliqueValues scores) Runs Viterbi on a linear chain CRF.
-
Method Details
-
beliefPropagation
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
Sums the log probabilities. Must be updated in concert withsumLogProbs(double[])
.- Parameters:
input
- ADenseVector
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 withsumLogProbs(DenseVector)
.- Parameters:
input
- A double array of log probabilities.- Returns:
- log sum exp input[i].
-