[fix] handle case of T = 0 in Viterbi decoding

This commit is contained in:
Al
2017-03-12 22:55:48 -04:00
parent 35ccb3ee62
commit 6cf113b1df
2 changed files with 8 additions and 2 deletions

View File

@@ -15,9 +15,8 @@ void crf_averaged_perceptron_trainer_destroy(crf_averaged_perceptron_trainer_t *
kh_destroy(feature_class_weights, self->weights);
}
khash_t(prev_tag_class_weights) *prev_tag_weights;
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, {
if (prev_tag_weights != NULL) {
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;
}
if (num_tokens == 0) {
return true;
}
uint32_array_clear(self->sequence_features_indptr);
uint32_array_push(self->sequence_features_indptr, 0);
cstring_array_clear(self->sequence_features);