mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-10 16:22:29 +03:00
Fix add_action for NER, so labelled 'O' actions aren't added
This commit is contained in:
parent
683d81bb49
commit
daf869ab3b
|
@ -220,6 +220,31 @@ cdef class BiluoPushDown(TransitionSystem):
|
||||||
raise Exception(move)
|
raise Exception(move)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
def add_action(self, int action, label_name):
|
||||||
|
cdef attr_t label_id
|
||||||
|
if not isinstance(label_name, (int, long)):
|
||||||
|
label_id = self.strings.add(label_name)
|
||||||
|
else:
|
||||||
|
label_id = label_name
|
||||||
|
if action == OUT and label_id != 0:
|
||||||
|
return
|
||||||
|
if action == MISSING or action == ISNT:
|
||||||
|
return
|
||||||
|
# Check we're not creating a move we already have, so that this is
|
||||||
|
# idempotent
|
||||||
|
for trans in self.c[:self.n_moves]:
|
||||||
|
if trans.move == action and trans.label == label_id:
|
||||||
|
return 0
|
||||||
|
if self.n_moves >= self._size:
|
||||||
|
self._size *= 2
|
||||||
|
self.c = <Transition*>self.mem.realloc(self.c, self._size * sizeof(self.c[0]))
|
||||||
|
self.c[self.n_moves] = self.init_transition(self.n_moves, action, label_id)
|
||||||
|
assert self.c[self.n_moves].label == label_id
|
||||||
|
self.n_moves += 1
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cdef int initialize_state(self, StateC* st) nogil:
|
cdef int initialize_state(self, StateC* st) nogil:
|
||||||
# This is especially necessary when we use limited training data.
|
# This is especially necessary when we use limited training data.
|
||||||
for i in range(st.length):
|
for i in range(st.length):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user