mirror of https://github.com/explosion/spaCy.git
* Fix min function in fill_context
This commit is contained in:
parent
142b6f9510
commit
bbef71f213
|
@ -3,7 +3,7 @@ from thinc.typedefs cimport atom_t
|
||||||
from .stateclass cimport StateClass
|
from .stateclass cimport StateClass
|
||||||
|
|
||||||
|
|
||||||
cdef int fill_context(atom_t* context, StateClass state) except -1
|
cdef int fill_context(atom_t* context, StateClass state) nogil
|
||||||
# Context elements
|
# Context elements
|
||||||
|
|
||||||
# Ensure each token's attributes are listed: w, p, c, c6, c4. The order
|
# Ensure each token's attributes are listed: w, p, c, c6, c4. The order
|
||||||
|
|
|
@ -59,7 +59,7 @@ cdef inline void fill_token(atom_t* context, const TokenC* token) nogil:
|
||||||
context[10] = token.ent_iob
|
context[10] = token.ent_iob
|
||||||
context[11] = token.ent_type
|
context[11] = token.ent_type
|
||||||
|
|
||||||
cdef int fill_context(atom_t* ctxt, StateClass st) except -1:
|
cdef int fill_context(atom_t* ctxt, StateClass st) nogil:
|
||||||
# Take care to fill every element of context!
|
# Take care to fill every element of context!
|
||||||
# We could memset, but this makes it very easy to have broken features that
|
# We could memset, but this makes it very easy to have broken features that
|
||||||
# make almost no impact on accuracy. If instead they're unset, the impact
|
# make almost no impact on accuracy. If instead they're unset, the impact
|
||||||
|
@ -84,14 +84,14 @@ cdef int fill_context(atom_t* ctxt, StateClass st) except -1:
|
||||||
fill_token(&ctxt[E1w], st.E_(1))
|
fill_token(&ctxt[E1w], st.E_(1))
|
||||||
|
|
||||||
if st.stack_depth() >= 1 and not st.eol():
|
if st.stack_depth() >= 1 and not st.eol():
|
||||||
ctxt[dist] = min(st.B(0) - st.E(0), 5)
|
ctxt[dist] = min_(st.B(0) - st.E(0), 5)
|
||||||
else:
|
else:
|
||||||
ctxt[dist] = 0
|
ctxt[dist] = 0
|
||||||
ctxt[N0lv] = min(st.n_L(st.B(0)), 5)
|
ctxt[N0lv] = min_(st.n_L(st.B(0)), 5)
|
||||||
ctxt[S0lv] = min(st.n_L(st.S(0)), 5)
|
ctxt[S0lv] = min_(st.n_L(st.S(0)), 5)
|
||||||
ctxt[S0rv] = min(st.n_R(st.S(0)), 5)
|
ctxt[S0rv] = min_(st.n_R(st.S(0)), 5)
|
||||||
ctxt[S1lv] = min(st.n_L(st.S(1)), 5)
|
ctxt[S1lv] = min_(st.n_L(st.S(1)), 5)
|
||||||
ctxt[S1rv] = min(st.n_R(st.S(1)), 5)
|
ctxt[S1rv] = min_(st.n_R(st.S(1)), 5)
|
||||||
|
|
||||||
ctxt[S0_has_head] = 0
|
ctxt[S0_has_head] = 0
|
||||||
ctxt[S1_has_head] = 0
|
ctxt[S1_has_head] = 0
|
||||||
|
@ -104,6 +104,10 @@ cdef int fill_context(atom_t* ctxt, StateClass st) except -1:
|
||||||
ctxt[S2_has_head] = st.has_head(st.S(2)) + 1
|
ctxt[S2_has_head] = st.has_head(st.S(2)) + 1
|
||||||
|
|
||||||
|
|
||||||
|
cdef inline int min_(int a, int b) nogil:
|
||||||
|
return a if a > b else b
|
||||||
|
|
||||||
|
|
||||||
ner = (
|
ner = (
|
||||||
(N0W,),
|
(N0W,),
|
||||||
(P1W,),
|
(P1W,),
|
||||||
|
|
Loading…
Reference in New Issue