mirror of https://github.com/explosion/spaCy.git
* Make Zipf regularization a bit more efficient
This commit is contained in:
parent
7fc24821bc
commit
4d37b66c55
|
@ -44,10 +44,13 @@ cdef class Model:
|
||||||
count_feats(counts[guess], feats, n_feats, -cost)
|
count_feats(counts[guess], feats, n_feats, -cost)
|
||||||
self._model.update(counts)
|
self._model.update(counts)
|
||||||
|
|
||||||
|
@cython.cdivision
|
||||||
|
@cython.boundscheck(False)
|
||||||
cdef int regularize(self, Feature* feats, int n, int a=3) except -1:
|
cdef int regularize(self, Feature* feats, int n, int a=3) except -1:
|
||||||
zipfs = numpy.random.zipf(a, n)
|
cdef int i
|
||||||
|
cdef long[:] zipfs = numpy.random.zipf(a, n)
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
feats[i].value *= 1.0 / zipfs[i]
|
feats[i].value *= 1 / zipfs[i]
|
||||||
|
|
||||||
def end_training(self):
|
def end_training(self):
|
||||||
self._model.end_training()
|
self._model.end_training()
|
||||||
|
|
Loading…
Reference in New Issue