  from thinc.api import chain
  from thinc.v2v import Affine, Maxout, Softmax
  from thinc.misc import LayerNorm
  from thinc.neural.util import to_categorical
  
  from ..cli.pretrain import get_cossim_loss
  from .functions import merge_subtokens
  from ..tokens.doc cimport Doc
  from ..syntax.nn_parser cimport Parser
 
</s> remove import numpy as np

 </s> add  </s> remove                         best_index = scores.index(max(scores))
 </s> add  </s> remove                         scores = []
                        for c in candidates:
                            prior_prob = c.prior_prob * self.prior_weight
                            kb_id = c.entity_
                            entity_encoding = c.entity_vector
                            sim = float(cosine(np.asarray([entity_encoding]), context_enc_t)) * self.context_weight
                            score = prior_prob + sim - (prior_prob*sim)
                            scores.append(score)
 </s> add                         prior_probs = xp.asarray([c.prior_prob for c in candidates])
                        prior_probs *= self.prior_weight

                        entity_encodings = xp.asarray([c.entity_vector for c in candidates])
                        norm_2 = xp.linalg.norm(entity_encodings, axis=1)

                        # cosine similarity
                        sims = xp.dot(entity_encodings, context_enc_t) / (norm_1 * norm_2)
                        sims *= self.context_weight
                        scores = prior_probs + sims - (prior_probs*sims)
                        best_index = scores.argmax() </s> remove                 context_encoding = self.model([doc])
                context_enc_t = np.transpose(context_encoding)
 </s> add                 context_encoding = context_encodings[i]
                context_enc_t = context_encoding.T
                norm_1 = xp.linalg.norm(context_enc_t)
from thinc.neural.util import get_array_module
  from thinc.api import chain
  from thinc.v2v import Affine, Maxout, Softmax
  from thinc.misc import LayerNorm
  from thinc.neural.util import to_categorical
from thinc.neural.util import get_array_module
  
  from ..cli.pretrain import get_cossim_loss
  from .functions import merge_subtokens
  from ..tokens.doc cimport Doc
  from ..syntax.nn_parser cimport Parser
keep keep keep add keep keep keep keep keep
 improve speed of prediction loop 
spacy/pipeline/pipes.pyx