Class CRFParameters
java.lang.Object
org.tribuo.classification.sgd.crf.CRFParameters
- All Implemented Interfaces:
Serializable,Parameters,org.tribuo.protos.ProtoSerializable<org.tribuo.math.protos.ParametersProto>
A
Parameters for training a CRF using SGD.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Method Summary
Modifier and TypeMethodDescriptionstatic CRFParametersdeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.Tensor[]get()doublegetBias(int id) Returns the bias for the specified label id.getCliqueValues(SGDVector[] features) Generates the local scores and tuples them with the label - label transition weights.Tensor[]Returns a 3 elementTensorarray.getFeatureWeights(int id) Gets a copy of the weights for the specified label id.getLocalScores(SGDVector[] features) Generate the local scores (i.e., the linear classifier for each token).doublegetWeight(int labelID, int featureID) Returns the feature/label weight for the specified feature and label id.Tensor[]int[]Generate a prediction using Viterbi.predictConfidenceUsingCBP(SGDVector[] features, List<Chunk> chunks) This predicts per chunk confidence using the constrained forward backward algorithm from Culotta and McCallum 2004.predictMarginals(SGDVector[] features) Generate a prediction using Belief Propagation.org.tribuo.math.protos.ParametersProtovoidvoidvalueAndGradient(SGDVector[] 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.
-
Field Details
-
CURRENT_VERSION
-
-
Method Details
-
deserializeFromProto
public static CRFParameters deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version- The serialized object version.className- The class name.message- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException- If the protobuf could not be parsed from themessage.
-
serialize
- Specified by:
serializein interfaceorg.tribuo.protos.ProtoSerializable<org.tribuo.math.protos.ParametersProto>
-
getFeatureWeights
Gets a copy of the weights for the specified label id.- Parameters:
id- The label id.- Returns:
- The feature weights.
-
getBias
Returns the bias for the specified label id.- Parameters:
id- The label id.- Returns:
- The bias.
-
getWeight
Returns the feature/label weight for the specified feature and label id.- Parameters:
labelID- The label id.featureID- The feature id.- Returns:
- The feature/label weight.
-
getLocalScores
Generate the local scores (i.e., the linear classifier for each token).- Parameters:
features- An array ofSGDVectors, 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 tokenSGDVectorof features.- Returns:
- A tuple containing the array of
DenseVectorscores and the label - label transition weights.
-
predict
-
predictMarginals
Generate a prediction using Belief Propagation.- Parameters:
features- The per tokenSGDVectorof 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 tokenSGDVectorof 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(SGDVector[] 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.Assumes all the features in this example are either SparseVector or DenseVector. Mixing the two will cause undefined behaviour.
- Parameters:
features- The per tokenSGDVectorof 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
- Specified by:
getin interfaceParameters
-
set
- Specified by:
setin interfaceParameters
-
update
- Specified by:
updatein interfaceParameters
-
merge
- Specified by:
mergein interfaceParameters
-