Class CRFLabeler<T>
java.lang.Object
smile.sequence.CRFLabeler<T>
- Type Parameters:
T- the data type of model input objects.
- All Implemented Interfaces:
Serializable, SequenceLabeler<T>
First-order CRF sequence labeler.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CRFLabeler<T> Fits a CRF model.static <T> CRFLabeler<T> fit(T[][] sequences, int[][] labels, Function<T, Tuple> features, CRF.Options options) Fits a CRF.int[]Returns the most likely label sequence given the feature sequence by the forward-backward algorithm.toString()int[]Labels sequence with Viterbi algorithm.
-
Constructor Details
-
CRFLabeler
-
-
Method Details
-
fit
Fits a CRF model.- Type Parameters:
T- the data type of observations.- Parameters:
sequences- the training data.labels- the training sequence labels.features- the feature function.- Returns:
- the model.
-
fit
public static <T> CRFLabeler<T> fit(T[][] sequences, int[][] labels, Function<T, Tuple> features, CRF.Options options) Fits a CRF.- Type Parameters:
T- the data type of observations.- Parameters:
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.options- the hyperparameters.- Returns:
- the model.
-
toString
-
predict
Returns the most likely label sequence given the feature sequence by the forward-backward algorithm.- Specified by:
predictin interfaceSequenceLabeler<T>- Parameters:
o- the observation sequence.- Returns:
- the most likely state sequence.
-
viterbi
Labels sequence with Viterbi algorithm. Viterbi algorithm returns the whole sequence label that has the maximum probability, which makes sense in applications (e.g.part-of-speech tagging) that require coherent sequential labeling. The forward-backward algorithm labels a sequence by individual prediction on each position. This usually produces better accuracy although the results may not be coherent.- Parameters:
o- the observation sequence.- Returns:
- the sequence labels.
-