public class CRFModel extends ConfidencePredictingSequenceModel
Can be switched to use Viterbi, belief propagation, or constrained BP at test time. By default it uses Viterbi.
See:
Lafferty J, McCallum A, Pereira FC. "Conditional Random Fields: Probabilistic Models for Segmenting and Labeling Sequence Data" Proceedings of the 18th International Conference on Machine Learning 2001 (ICML 2001).
Modifier and Type | Class and Description |
---|---|
static class |
CRFModel.ConfidenceType
The type of subsequence level confidence to predict.
|
ConfidencePredictingSequenceModel.Subsequence
featureIDMap, name, outputIDMap, provenanceOutput
Modifier and Type | Method and Description |
---|---|
static com.oracle.labs.mlrg.olcut.util.Pair<int[],SparseVector[]> |
convert(SequenceExample<Label> example,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<Label> labelIDMap)
Deprecated.
As it's replaced with
convertToVector(org.tribuo.sequence.SequenceExample<T>, org.tribuo.ImmutableFeatureMap) which is more flexible. |
static <T extends Output<T>> |
convert(SequenceExample<T> example,
ImmutableFeatureMap featureIDMap)
Deprecated.
As it's replaced with
convertToVector(org.tribuo.sequence.SequenceExample<T>, org.tribuo.ImmutableFeatureMap) which is more flexible. |
static com.oracle.labs.mlrg.olcut.util.Pair<int[],SGDVector[]> |
convertToVector(SequenceExample<Label> example,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<Label> labelIDMap)
Converts a
SequenceExample into an array of SGDVector s and labels suitable for CRF prediction. |
static <T extends Output<T>> |
convertToVector(SequenceExample<T> example,
ImmutableFeatureMap featureIDMap)
Converts a
SequenceExample into an array of SGDVector s suitable for CRF prediction. |
String |
generateWeightsString()
Generates a human readable string containing all the weights in this model.
|
DenseVector |
getFeatureWeights(int featureID)
Get a copy of the weights for feature
featureID . |
DenseVector |
getFeatureWeights(String featureName)
Get a copy of the weights for feature named
featureName . |
Map<String,List<com.oracle.labs.mlrg.olcut.util.Pair<String,Double>>> |
getTopFeatures(int n)
Gets the top
n features associated with this model. |
List<Prediction<Label>> |
predict(SequenceExample<Label> example)
Uses the model to predict the output for a single example.
|
List<Double> |
scoreChunks(SequenceExample<Label> example,
List<Chunk> chunks)
Scores the chunks using constrained belief propagation.
|
<SUB extends ConfidencePredictingSequenceModel.Subsequence> |
scoreSubsequences(SequenceExample<Label> example,
List<Prediction<Label>> predictions,
List<SUB> subsequences)
The scoring function for the subsequences.
|
void |
setConfidenceType(CRFModel.ConfidenceType type)
Sets the inference method used for confidence prediction.
|
multiplyWeights
getFeatureIDMap, getName, getOutputIDInfo, getProvenance, predict, predict, setName, toMaxLabels, toString, validate
public void setConfidenceType(CRFModel.ConfidenceType type)
type
- Enum specifying the confidence type.public DenseVector getFeatureWeights(int featureID)
featureID
.featureID
- The feature ID.public DenseVector getFeatureWeights(String featureName)
featureName
.featureName
- The feature name.public List<Prediction<Label>> predict(SequenceExample<Label> example)
SequenceModel
predict
in class SequenceModel<Label>
example
- the example to predict.public Map<String,List<com.oracle.labs.mlrg.olcut.util.Pair<String,Double>>> getTopFeatures(int n)
SequenceModel
n
features associated with this model.
If the model does not produce per output feature lists, it returns a map with a single element with key Model.ALL_OUTPUTS.
If the model cannot describe it's top features then it returns Collections.emptyMap()
.
getTopFeatures
in class SequenceModel<Label>
n
- the number of features to return. If this value is less than 0,
all features should be returned for each class, unless the model cannot score it's features.public <SUB extends ConfidencePredictingSequenceModel.Subsequence> List<Double> scoreSubsequences(SequenceExample<Label> example, List<Prediction<Label>> predictions, List<SUB> subsequences)
ConfidencePredictingSequenceModel
scoreSubsequences
in class ConfidencePredictingSequenceModel
SUB
- The subsequence type.example
- The input sequence example.predictions
- The predictions produced by this model.subsequences
- The subsequences to score.public List<Double> scoreChunks(SequenceExample<Label> example, List<Chunk> chunks)
example
- The example to score.chunks
- The predicted chunks.public String generateWeightsString()
@Deprecated public static <T extends Output<T>> SparseVector[] convert(SequenceExample<T> example, ImmutableFeatureMap featureIDMap)
convertToVector(org.tribuo.sequence.SequenceExample<T>, org.tribuo.ImmutableFeatureMap)
which is more flexible.SequenceExample
into an array of SparseVector
s suitable for CRF prediction.T
- The type parameter of the sequence example.example
- The sequence example to convertfeatureIDMap
- The feature id map, used to discover the number of features.SparseVector
.@Deprecated public static com.oracle.labs.mlrg.olcut.util.Pair<int[],SparseVector[]> convert(SequenceExample<Label> example, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Label> labelIDMap)
convertToVector(org.tribuo.sequence.SequenceExample<T>, org.tribuo.ImmutableFeatureMap)
which is more flexible.SequenceExample
into an array of SparseVector
s and labels suitable for CRF prediction.example
- The sequence example to convertfeatureIDMap
- The feature id map, used to discover the number of features.labelIDMap
- The label id map, used to get the index of the labels.Pair
of an int array of labels and an array of SparseVector
.public static <T extends Output<T>> SGDVector[] convertToVector(SequenceExample<T> example, ImmutableFeatureMap featureIDMap)
SequenceExample
into an array of SGDVector
s suitable for CRF prediction.T
- The type parameter of the sequence example.example
- The sequence example to convertfeatureIDMap
- The feature id map, used to discover the number of features.SGDVector
.public static com.oracle.labs.mlrg.olcut.util.Pair<int[],SGDVector[]> convertToVector(SequenceExample<Label> example, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Label> labelIDMap)
SequenceExample
into an array of SGDVector
s and labels suitable for CRF prediction.example
- The sequence example to convertfeatureIDMap
- The feature id map, used to discover the number of features.labelIDMap
- The label id map, used to get the index of the labels.Pair
of an int array of labels and an array of SparseVector
.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.