public class CRFLabeler<T> extends java.lang.Object implements SequenceLabeler<T>
Modifier and Type | Field and Description |
---|---|
java.util.function.Function<T,smile.data.Tuple> |
features
The feature function.
|
CRF |
model
The CRF model.
|
Constructor and Description |
---|
CRFLabeler(CRF model,
java.util.function.Function<T,smile.data.Tuple> features)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static <T> CRFLabeler<T> |
fit(T[][] sequences,
int[][] labels,
java.util.function.Function<T,smile.data.Tuple> features)
Fits a CRF model.
|
static <T> CRFLabeler<T> |
fit(T[][] sequences,
int[][] labels,
java.util.function.Function<T,smile.data.Tuple> features,
int ntrees,
int maxDepth,
int maxNodes,
int nodeSize,
double shrinkage)
Fits a CRF.
|
static <T> CRFLabeler<T> |
fit(T[][] sequences,
int[][] labels,
java.util.function.Function<T,smile.data.Tuple> features,
java.util.Properties prop)
Fits a CRF model.
|
int[] |
predict(T[] o)
Returns the most likely label sequence given the feature sequence by the
forward-backward algorithm.
|
java.lang.String |
toString() |
int[] |
viterbi(T[] o)
Labels sequence with Viterbi algorithm.
|
public final CRF model
public final java.util.function.Function<T,smile.data.Tuple> features
public static <T> CRFLabeler<T> fit(T[][] sequences, int[][] labels, java.util.function.Function<T,smile.data.Tuple> features)
sequences
- the training data.labels
- the training sequence labels.public static <T> CRFLabeler<T> fit(T[][] sequences, int[][] labels, java.util.function.Function<T,smile.data.Tuple> features, java.util.Properties prop)
sequences
- the training data.labels
- the training sequence labels.public static <T> CRFLabeler<T> fit(T[][] sequences, int[][] labels, java.util.function.Function<T,smile.data.Tuple> features, int ntrees, int maxDepth, int maxNodes, int nodeSize, double shrinkage)
sequences
- the observation sequences.labels
- the state labels of observations, of which states take
values in [0, k), where k is the number of hidden states.features
- the feature function.ntrees
- the number of trees/iterations.maxDepth
- the maximum depth of the tree.maxNodes
- the maximum number of leaf nodes in the tree.nodeSize
- the number of instances in a node below which the tree will
not split, setting nodeSize = 5 generally gives good results.shrinkage
- the shrinkage parameter in (0, 1] controls the learning rate of procedure.public java.lang.String toString()
toString
in class java.lang.Object
public int[] predict(T[] o)
predict
in interface SequenceLabeler<T>
o
- an observation sequence.public int[] viterbi(T[] o)