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
This commit is contained in:
Matthew Honnibal 2019-02-24 16:36:29 +01:00
parent 7ac0f9626c
commit d74dbde828
1 changed files with 11 additions and 0 deletions

View File

@ -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