2014-12-30 10:20:15 +00:00
|
|
|
from libc.stdint cimport uint8_t
|
|
|
|
|
|
|
|
from cymem.cymem cimport Pool
|
|
|
|
|
|
|
|
from thinc.learner cimport LinearModel
|
2015-05-26 20:17:15 +00:00
|
|
|
from thinc.features cimport Extractor, Feature
|
2014-12-30 10:20:15 +00:00
|
|
|
from thinc.typedefs cimport atom_t, feat_t, weight_t, class_t
|
|
|
|
|
|
|
|
from preshed.maps cimport PreshMapArray
|
|
|
|
|
|
|
|
from .typedefs cimport hash_t, id_t
|
|
|
|
from .tokens cimport Tokens
|
|
|
|
|
|
|
|
|
2014-12-31 08:40:59 +00:00
|
|
|
cdef int arg_max(const weight_t* scores, const int n_classes) nogil
|
|
|
|
|
|
|
|
|
2014-12-30 10:20:15 +00:00
|
|
|
cdef class Model:
|
2014-12-31 08:40:59 +00:00
|
|
|
cdef int n_classes
|
2015-05-26 20:17:15 +00:00
|
|
|
|
|
|
|
cdef int regularize(self, Feature* feats, int n, int a=*) except -1
|
2014-12-31 08:40:59 +00:00
|
|
|
|
|
|
|
cdef int update(self, atom_t* context, class_t guess, class_t gold, int cost) except -1
|
|
|
|
|
2014-12-30 10:20:15 +00:00
|
|
|
cdef object model_loc
|
|
|
|
cdef Extractor _extractor
|
|
|
|
cdef LinearModel _model
|
|
|
|
|
2015-05-26 20:17:15 +00:00
|
|
|
cdef inline const weight_t* score(self, atom_t* context, bint regularize) except NULL:
|
2014-12-31 08:40:59 +00:00
|
|
|
cdef int n_feats
|
|
|
|
feats = self._extractor.get_feats(context, &n_feats)
|
2015-05-26 20:17:15 +00:00
|
|
|
if regularize:
|
|
|
|
self.regularize(feats, n_feats, 3)
|
2014-12-31 08:40:59 +00:00
|
|
|
return self._model.get_scores(feats, n_feats)
|
|
|
|
|