From 7562cf866bdabd52eaa9fbdb2cea4c1fe3adc984 Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 11 Mar 2017 05:58:11 -0500 Subject: [PATCH] [crf] in averaged perceptron training for the CRF, need to update transition features when either guess != truth or prev_guess != prev_truth --- src/crf_trainer_averaged_perceptron.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crf_trainer_averaged_perceptron.c b/src/crf_trainer_averaged_perceptron.c index d34269b3..d7fc2b60 100644 --- a/src/crf_trainer_averaged_perceptron.c +++ b/src/crf_trainer_averaged_perceptron.c @@ -539,7 +539,7 @@ bool crf_averaged_perceptron_trainer_update(crf_averaged_perceptron_trainer_t *s truth = labels[t]; guess = viterbi[t]; - if (t > 0 && guess != truth) { + if (t > 0 && (guess != truth || prev_guess != prev_truth)) { uint32_t idx = indptr[t]; uint32_t next_start = indptr[t + 1]; @@ -580,7 +580,7 @@ bool crf_averaged_perceptron_trainer_update(crf_averaged_perceptron_trainer_t *s truth = labels[t]; guess = viterbi[t]; - if (t > 0 && guess != truth) { + if (t > 0 && (guess != truth || prev_guess != prev_truth)) { if (!crf_averaged_perceptron_trainer_update_trans_feature(self, prev_guess, prev_truth, guess, truth, value)) { return false; } @@ -593,6 +593,7 @@ bool crf_averaged_perceptron_trainer_update(crf_averaged_perceptron_trainer_t *s return true; } + bool crf_averaged_perceptron_trainer_train_example(crf_averaged_perceptron_trainer_t *self, void *tagger, void *tagger_context, cstring_array *features, cstring_array *prev_tag_features, tagger_feature_function feature_function, tokenized_string_t *tokenized, cstring_array *labels) { if (self == NULL || self->base_trainer == NULL) return false;