* Move moves to bilou_moves. Refactor context, returning to the simpler giant-enum style

This commit is contained in:
Matthew Honnibal 2014-11-12 00:54:25 +11:00
parent c788633429
commit e6bb8aa3a9
8 changed files with 17 additions and 40 deletions

View File

@ -1,21 +1,5 @@
from cymem.cymem cimport Pool
from .moves cimport Move
cdef struct Entity:
int start
int end
int label
cdef struct State:
Entity curr
Entity* ents
int* tags
int i
int j
int length
from .structs cimport State, Entity, Move
cdef int begin_entity(State* s, label) except -1

View File

@ -1,4 +1,4 @@
from .moves cimport BEGIN, UNIT
from .bilou_moves cimport BEGIN, UNIT
cdef int begin_entity(State* s, label) except -1:

View File

@ -3,7 +3,8 @@ from cymem.cymem cimport Pool
from thinc.typedefs cimport class_t
from thinc.typedefs cimport weight_t
from ._state cimport State
from .structs cimport State, Move
cpdef enum ActionType:
MISSING
@ -15,13 +16,6 @@ cpdef enum ActionType:
N_ACTIONS
cdef struct Move:
class_t clas
int action
int label
bint accept
cdef int set_accept_if_oracle(Move* moves, Move* golds, int n, State* s) except 0
cdef int set_accept_if_valid(Move* moves, int n, State* s) except 0

View File

@ -6,7 +6,7 @@ from thinc.typedefs cimport *
from ..tokens cimport Tokens
from ..typedefs cimport *
from .moves cimport Move
from .bilou_moves cimport Move
cdef class NERParser:

View File

@ -12,11 +12,11 @@ from thinc.features cimport ConjFeat
from .context cimport fill_context
from .context cimport N_FIELDS
from .moves cimport Move
from .moves cimport fill_moves, transition, best_accepted
from .moves cimport set_accept_if_valid, set_accept_if_oracle
from .bilou_moves cimport Move
from .bilou_moves cimport fill_moves, transition, best_accepted
from .bilou_moves cimport set_accept_if_valid, set_accept_if_oracle
from ._state cimport entity_is_open
from .moves import get_n_moves
from .bilou_moves import get_n_moves
from ._state cimport State
from ._state cimport init_state
@ -81,7 +81,7 @@ cdef class NERParser:
n_correct = 0
cdef int f = 0
while s.i < tokens.length:
fill_context(self._context, s.i, tokens)
fill_context(self._context, s, tokens)
self.extractor.extract(self._feats, self._values, self._context, NULL)
self.model.score(self._scores, self._feats, self._values)
@ -109,7 +109,7 @@ cdef class NERParser:
cdef State* s = init_state(mem, tokens.length)
cdef Move* move
while s.i < tokens.length:
fill_context(self._context, s.i, tokens)
fill_context(self._context, s, tokens)
self.extractor.extract(self._feats, self._values, self._context, NULL)
self.model.score(self._scores, self._feats, self._values)
set_accept_if_valid(self._moves, self.n_classes, s)

View File

@ -1,7 +1,6 @@
from cymem.cymem cimport Pool
from .moves cimport Move
from ._state cimport State
from .structs cimport Move, State
cdef class PyState:

View File

@ -2,11 +2,11 @@ from __future__ import unicode_literals
from ._state cimport init_state
from ._state cimport entity_is_open
from .moves cimport fill_moves
from .moves cimport transition
from .moves cimport set_accept_if_valid, set_accept_if_oracle
from .moves import get_n_moves
from .moves import ACTION_NAMES
from .bilou_moves cimport fill_moves
from .bilou_moves cimport transition
from .bilou_moves cimport set_accept_if_valid, set_accept_if_oracle
from .bilou_moves import get_n_moves
from .bilou_moves import ACTION_NAMES
cdef class PyState: