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) |
ChainHelper.ChainCliqueValues |
getCliqueValues(SparseVector[] 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) |
DenseVector[] |
getLocalScores(SparseVector[] features)
Generate the local scores (i.e., the linear classifier for each token).
|
double |
getWeight(int labelID,
int featureID) |
Tensor[] |
merge(Tensor[][] gradients,
int size)
Merge together an array of gradient arrays.
|
int[] |
predict(SparseVector[] features)
Generate a prediction using Viterbi.
|
List<Double> |
predictConfidenceUsingCBP(SparseVector[] features,
List<Chunk> chunks)
This predicts per chunk confidence using the constrained forward backward algorithm from
Culotta and McCallum 2004.
|
DenseVector[] |
predictMarginals(SparseVector[] 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(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.
|
public DenseVector getFeatureWeights(int id)
public double getBias(int id)
public double getWeight(int labelID, int featureID)
public DenseVector[] getLocalScores(SparseVector[] features)
features
- An array of SparseVector
s, one per token.public ChainHelper.ChainCliqueValues getCliqueValues(SparseVector[] features)
features
- The per token SparseVector
of features.DenseVector
scores and the label - label transition weights.public int[] predict(SparseVector[] features)
features
- The per token SparseVector
of features.public DenseVector[] predictMarginals(SparseVector[] features)
features
- The per token SparseVector
of features.DenseVector
per token containing the marginal distribution over labels.public List<Double> predictConfidenceUsingCBP(SparseVector[] 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 SparseVector
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(SparseVector[] features, int[] labels)
features
- The per token SparseVector
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.