From 700979fb3c112819aa1f83c815e684e8fc036516 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 7 May 2017 04:01:11 +0200 Subject: [PATCH] CPU/GPU compat --- spacy/syntax/parser.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spacy/syntax/parser.pyx b/spacy/syntax/parser.pyx index b7d33e1c9..77d2a0ebc 100644 --- a/spacy/syntax/parser.pyx +++ b/spacy/syntax/parser.pyx @@ -256,7 +256,7 @@ cdef class Parser: self._cost_batch(costs, is_valid, states, golds) self._set_gradient(d_scores, scores, is_valid, costs) - losses.append(numpy.abs(d_scores).sum()) + losses.append(self.model.ops.xp.abs(d_scores).sum()) if force_gold: softmaxed *= costs <= 0 return finish_update(d_scores, sgd=sgd) @@ -312,9 +312,9 @@ cdef class Parser: n = gradients.shape[0] scores = scores * is_valid g_scores = scores * is_valid * (costs <= 0.) - exps = numpy.exp(scores - scores.max(axis=1).reshape((n, 1))) + exps = self.model.ops.xp.exp(scores - scores.max(axis=1).reshape((n, 1))) exps *= is_valid - g_exps = numpy.exp(g_scores - g_scores.max(axis=1).reshape((n, 1))) + g_exps = self.model.ops.xp.exp(g_scores - g_scores.max(axis=1).reshape((n, 1))) g_exps *= costs <= 0. g_exps *= is_valid gradients[:] = exps / exps.sum(axis=1).reshape((n, 1))