* Fill L2 norm attribute on LexemeC struct

This commit is contained in:
Matthew Honnibal 2015-02-07 08:44:42 -05:00
parent 75f9b7d6bf
commit f0e0588833
1 changed files with 4 additions and 0 deletions

View File

@ -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 = <LexemeC*>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