From d74dbde828fb867c6f8958f54cec23470f48ea55 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 24 Feb 2019 16:36:29 +0100 Subject: [PATCH] Fix order of actions when labels added to parser When labels were added to the parser or NER, we weren't loading back the classes in the correct order. Re issue #3189 --- spacy/syntax/transition_system.pyx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spacy/syntax/transition_system.pyx b/spacy/syntax/transition_system.pyx index 6d64a4fb4..5ec254e04 100644 --- a/spacy/syntax/transition_system.pyx +++ b/spacy/syntax/transition_system.pyx @@ -147,6 +147,8 @@ cdef class TransitionSystem: def initialize_actions(self, labels_by_action, min_freq=None): self.labels = {} self.n_moves = 0 + added_labels = [] + added_actions = {} for action, label_freqs in sorted(labels_by_action.items()): action = int(action) # Make sure we take a copy here, and that we get a Counter @@ -157,6 +159,15 @@ cdef class TransitionSystem: sorted_labels.sort() sorted_labels.reverse() for freq, label_str in sorted_labels: + if freq < 0: + added_labels.append((freq, label_str)) + added_actions.setdefault(label_str, []).append(action) + else: + self.add_action(int(action), label_str) + self.labels[action][label_str] = freq + added_labels.sort(reverse=True) + for freq, label_str in added_labels: + for action in added_actions[label_str]: self.add_action(int(action), label_str) self.labels[action][label_str] = freq