From 6574e4f2d332f7b12d933920457dd268f156ec4c Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 21 Feb 2019 09:27:38 +0100 Subject: [PATCH] Fix issue #3112 part 1 --- spacy/syntax/_parser_model.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spacy/syntax/_parser_model.pyx b/spacy/syntax/_parser_model.pyx index 657e30f41..85463dbb8 100644 --- a/spacy/syntax/_parser_model.pyx +++ b/spacy/syntax/_parser_model.pyx @@ -261,8 +261,9 @@ class ParserStepModel(Model): # lowest score. # numpy's nan_to_num function doesn't take a value, and nan is replaced # by 0...-inf is replaced by minimum, so we go via that. Ugly to the max. - scores[self.ops.xp.isnan(scores)] = -self.ops.xp.inf - self.ops.xp.nan_to_num(scores, copy=False) + # Note that scores is always a numpy array! Should fix #3112 + scores[numpy.isnan(scores)] = -numpy.inf + numpy.nan_to_num(scores, copy=False) def backprop_parser_step(d_scores, sgd=None): # If we have a non-zero gradient for a previously unseen class,