public class CRFParameters extends Object implements Parameters, Serializable
Parameters
for training a CRF using SGD.Modifier and Type | Method and Description |
---|---|
Tensor[] |
get()
Get a reference to the underlying
Tensor array. |
double |
getBias(int id)
Returns the bias for the specified label id.
|
ChainHelper.ChainCliqueValues |
getCliqueValues(SGDVector[] features)
Generates the local scores and tuples them with the label - label transition weights.
|
Tensor[] |
getEmptyCopy()
Returns a 3 element
Tensor array. |
DenseVector |
getFeatureWeights(int id)
Gets a copy of the weights for the specified label id.
|
DenseVector[] |
getLocalScores(SGDVector[] features)
Generate the local scores (i.e., the linear classifier for each token).
|
double |
getWeight(int labelID,
int featureID)
Returns the feature/label weight for the specified feature and label id.
|
Tensor[] |
merge(Tensor[][] gradients,
int size)
Merge together an array of gradient arrays.
|
int[] |
predict(SGDVector[] features)
Generate a prediction using Viterbi.
|
List<Double> |
predictConfidenceUsingCBP(SGDVector[] features,
List<Chunk> chunks)
This predicts per chunk confidence using the constrained forward backward algorithm from
Culotta and McCallum 2004.
|
DenseVector[] |
predictMarginals(SGDVector[] features)
Generate a prediction using Belief Propagation.
|
void |
set(Tensor[] newWeights)
Set the underlying
Tensor array to newWeights. |
void |
update(Tensor[] gradients)
Apply gradients to the parameters.
|
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.
|
public DenseVector getFeatureWeights(int id)
id
- The label id.public double getBias(int id)
id
- The label id.public double getWeight(int labelID, int featureID)
labelID
- The label id.featureID
- The feature id.public DenseVector[] getLocalScores(SGDVector[] features)
features
- An array of SGDVector
s, one per token.public ChainHelper.ChainCliqueValues getCliqueValues(SGDVector[] features)
features
- The per token SGDVector
of features.DenseVector
scores and the label - label transition weights.public int[] predict(SGDVector[] features)
features
- The per token SGDVector
of features.public DenseVector[] predictMarginals(SGDVector[] features)
features
- The per token SGDVector
of features.DenseVector
per token containing the marginal distribution over labels.public List<Double> predictConfidenceUsingCBP(SGDVector[] features, List<Chunk> chunks)
Runs one pass of BP to get the normalizing constant, and then a further chunks.size() passes of constrained forward backward.
features
- The per token SGDVector
of features.chunks
- A list of extracted chunks to pin constrain the labels to.public com.oracle.labs.mlrg.olcut.util.Pair<Double,Tensor[]> valueAndGradient(SGDVector[] features, int[] labels)
Assumes all the features in this example are either SparseVector or DenseVector. Mixing the two will cause undefined behaviour.
features
- The per token SGDVector
of features.labels
- The per token ground truth labels.Pair
containing the loss for this example and the associated gradient.public Tensor[] getEmptyCopy()
Tensor
array.
The first element is a DenseVector
of label biases.
The second element is a DenseMatrix
of feature-label weights.
The third element is a DenseMatrix
of label-label transition weights.getEmptyCopy
in interface Parameters
Tensor
array.public Tensor[] get()
Parameters
Tensor
array.get
in interface Parameters
public void set(Tensor[] newWeights)
Parameters
Tensor
array to newWeights.set
in interface Parameters
newWeights
- New parameters to store in this object.public void update(Tensor[] gradients)
Parameters
Tensor
is the same size as the corresponding one from the parameters.
The gradients are added to the parameters.
update
in interface Parameters
gradients
- A Tensor
array of updates, with the length equal to Parameters.get()
.length.public Tensor[] merge(Tensor[][] gradients, int size)
Parameters
Tensor
s.merge
in interface Parameters
gradients
- An array of gradient update arrays.size
- The number of elements of gradients to merge. Allows gradients to have unused elements.Tensor
array of the summed gradients.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.