From 4d37b66c558ce2940a1ab8eae0c96859231cb045 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 27 May 2015 01:12:50 +0200 Subject: [PATCH] * Make Zipf regularization a bit more efficient --- spacy/_ml.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spacy/_ml.pyx b/spacy/_ml.pyx index 02db80a2d..a2b943589 100644 --- a/spacy/_ml.pyx +++ b/spacy/_ml.pyx @@ -44,10 +44,13 @@ cdef class Model: count_feats(counts[guess], feats, n_feats, -cost) self._model.update(counts) + @cython.cdivision + @cython.boundscheck(False) 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): - feats[i].value *= 1.0 / zipfs[i] + feats[i].value *= 1 / zipfs[i] def end_training(self): self._model.end_training()