[fix] handle case of T = 0 in Viterbi decoding
This commit is contained in:
@@ -564,6 +564,9 @@ double crf_context_viterbi(crf_context_t *self, uint32_t *labels) {
|
|||||||
const double *trans = NULL;
|
const double *trans = NULL;
|
||||||
|
|
||||||
const size_t T = self->num_items;
|
const size_t T = self->num_items;
|
||||||
|
if (T == 0) {
|
||||||
|
return max_score;
|
||||||
|
}
|
||||||
const size_t L = self->num_labels;
|
const size_t L = self->num_labels;
|
||||||
|
|
||||||
// This function assumes state and trans scores to be in the logarithm domain.
|
// This function assumes state and trans scores to be in the logarithm domain.
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ void crf_averaged_perceptron_trainer_destroy(crf_averaged_perceptron_trainer_t *
|
|||||||
kh_destroy(feature_class_weights, self->weights);
|
kh_destroy(feature_class_weights, self->weights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
khash_t(prev_tag_class_weights) *prev_tag_weights;
|
||||||
if (self->prev_tag_weights != NULL) {
|
if (self->prev_tag_weights != NULL) {
|
||||||
khash_t(prev_tag_class_weights) *prev_tag_weights;
|
|
||||||
|
|
||||||
kh_foreach(self->prev_tag_weights, feature_id, prev_tag_weights, {
|
kh_foreach(self->prev_tag_weights, feature_id, prev_tag_weights, {
|
||||||
if (prev_tag_weights != NULL) {
|
if (prev_tag_weights != NULL) {
|
||||||
kh_destroy(prev_tag_class_weights, prev_tag_weights);
|
kh_destroy(prev_tag_class_weights, prev_tag_weights);
|
||||||
@@ -602,6 +601,10 @@ bool crf_averaged_perceptron_trainer_train_example(crf_averaged_perceptron_train
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (num_tokens == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_array_clear(self->sequence_features_indptr);
|
uint32_array_clear(self->sequence_features_indptr);
|
||||||
uint32_array_push(self->sequence_features_indptr, 0);
|
uint32_array_push(self->sequence_features_indptr, 0);
|
||||||
cstring_array_clear(self->sequence_features);
|
cstring_array_clear(self->sequence_features);
|
||||||
|
|||||||
Reference in New Issue
Block a user