From f0e05888337ea3b82f2ed475614952cd11edc724 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 7 Feb 2015 08:44:42 -0500 Subject: [PATCH] * Fill L2 norm attribute on LexemeC struct --- spacy/vocab.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spacy/vocab.pyx b/spacy/vocab.pyx index 468a2acef..8ed9805a0 100644 --- a/spacy/vocab.pyx +++ b/spacy/vocab.pyx @@ -5,6 +5,7 @@ from libc.stdint cimport int32_t import bz2 from os import path import codecs +import math from .lexeme cimport EMPTY_LEXEME from .lexeme cimport set_lex_struct_props @@ -205,6 +206,9 @@ cdef class Vocab: lex = self.lexemes[i] if lex.lower < vectors.size(): lex.repvec = vectors[lex.lower] + for i in range(vec_len): + lex.l2_norm += (lex.repvec[i] * lex.repvec[i]) + lex.l2_norm = math.sqrt(lex.l2_norm) else: lex.repvec = EMPTY_VEC