* Make Zipf regularization a bit more efficient

This commit is contained in:
Matthew Honnibal 2015-05-27 01:12:50 +02:00
parent 7fc24821bc
commit 4d37b66c55
1 changed files with 5 additions and 2 deletions

View File

@ -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()