Class CRFParameters
java.lang.Object
org.tribuo.classification.sgd.crf.CRFParameters
- All Implemented Interfaces:
Serializable,Parameters
A
Parameters for training a CRF using SGD.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionTensor[]get()Get a reference to the underlyingTensorarray.doublegetBias(int id) getCliqueValues(SparseVector[] features) Generates the local scores and tuples them with the label - label transition weights.Tensor[]Returns a 3 elementTensorarray.getFeatureWeights(int id) getLocalScores(SparseVector[] features) Generate the local scores (i.e., the linear classifier for each token).doublegetWeight(int labelID, int featureID) Tensor[]Merge together an array of gradient arrays.int[]predict(SparseVector[] features) Generate a prediction using Viterbi.predictConfidenceUsingCBP(SparseVector[] features, List<Chunk> chunks) This predicts per chunk confidence using the constrained forward backward algorithm from Culotta and McCallum 2004.predictMarginals(SparseVector[] features) Generate a prediction using Belief Propagation.voidSet the underlyingTensorarray to newWeights.voidApply gradients to the parameters.valueAndGradient(SparseVector[] features, int[] labels) Generates predictions based on the input features and labels, then scores those predictions to produce a loss for the example and a gradient update.
-
Method Details
-
getFeatureWeights
-
getBias
-
getWeight
-
getLocalScores
Generate the local scores (i.e., the linear classifier for each token).- Parameters:
features- An array ofSparseVectors, one per token.- Returns:
- An array of DenseVectors representing the scores per label for each token.
-
getCliqueValues
Generates the local scores and tuples them with the label - label transition weights.- Parameters:
features- The per tokenSparseVectorof features.- Returns:
- A tuple containing the array of
DenseVectorscores and the label - label transition weights.
-
predict
Generate a prediction using Viterbi.- Parameters:
features- The per tokenSparseVectorof features.- Returns:
- An int array giving the predicted label per token.
-
predictMarginals
Generate a prediction using Belief Propagation.- Parameters:
features- The per tokenSparseVectorof features.- Returns:
- A
DenseVectorper token containing the marginal distribution over labels.
-
predictConfidenceUsingCBP
This predicts per chunk confidence using the constrained forward backward algorithm from Culotta and McCallum 2004.Runs one pass of BP to get the normalizing constant, and then a further chunks.size() passes of constrained forward backward.
- Parameters:
features- The per tokenSparseVectorof features.chunks- A list of extracted chunks to pin constrain the labels to.- Returns:
- A list containing the confidence value for each chunk.
-
valueAndGradient
public com.oracle.labs.mlrg.olcut.util.Pair<Double,Tensor[]> valueAndGradient(SparseVector[] features, int[] labels) Generates predictions based on the input features and labels, then scores those predictions to produce a loss for the example and a gradient update.- Parameters:
features- The per tokenSparseVectorof features.labels- The per token ground truth labels.- Returns:
- A
Paircontaining the loss for this example and the associated gradient.
-
getEmptyCopy
Returns a 3 elementTensorarray. The first element is aDenseVectorof label biases. The second element is aDenseMatrixof feature-label weights. The third element is aDenseMatrixof label-label transition weights.- Specified by:
getEmptyCopyin interfaceParameters- Returns:
- A
Tensorarray.
-
get
Description copied from interface:ParametersGet a reference to the underlyingTensorarray.- Specified by:
getin interfaceParameters- Returns:
- The parameters.
-
set
Description copied from interface:ParametersSet the underlyingTensorarray to newWeights.- Specified by:
setin interfaceParameters- Parameters:
newWeights- New parameters to store in this object.
-
update
Description copied from interface:ParametersApply gradients to the parameters. Assumes that gradients is the same length as the parameters, and eachTensoris the same size as the corresponding one from the parameters.The gradients are added to the parameters.
- Specified by:
updatein interfaceParameters- Parameters:
gradients- ATensorarray of updates, with the length equal toParameters.get().length.
-
merge
Description copied from interface:ParametersMerge together an array of gradient arrays. Assumes the first dimension is the number of gradient arrays and the second dimension is the number of parameterTensors.- Specified by:
mergein interfaceParameters- Parameters:
gradients- An array of gradient update arrays.size- The number of elements of gradients to merge. Allows gradients to have unused elements.- Returns:
- A single
Tensorarray of the summed gradients.
-