mirror of https://github.com/explosion/spaCy.git
Add resize_vectors method to Vocab
This commit is contained in:
parent
8ce8803824
commit
7ab03050d4
|
@ -9,7 +9,7 @@ import bz2
|
||||||
from os import path
|
from os import path
|
||||||
import io
|
import io
|
||||||
import math
|
import math
|
||||||
import json
|
import ujson as json
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from .lexeme cimport EMPTY_LEXEME
|
from .lexeme cimport EMPTY_LEXEME
|
||||||
|
@ -129,6 +129,20 @@ cdef class Vocab:
|
||||||
"""The current number of lexemes stored."""
|
"""The current number of lexemes stored."""
|
||||||
return self.length
|
return self.length
|
||||||
|
|
||||||
|
def resize_vectors(self, int new_size):
|
||||||
|
'''
|
||||||
|
Set vectors_length to a new size, and allocate more memory for the Lexeme
|
||||||
|
vectors if necessary. The memory will be zeroed.
|
||||||
|
'''
|
||||||
|
cdef hash_t key
|
||||||
|
cdef size_t addr
|
||||||
|
if new_size > self.vectors_length:
|
||||||
|
for key, addr in self._by_hash.items():
|
||||||
|
lex = <LexemeC*>addr
|
||||||
|
lex.vector = <float*>self.mem.realloc(lex.vector,
|
||||||
|
new_size * sizeof(lex.vector[0]))
|
||||||
|
self.vectors_length = new_size
|
||||||
|
|
||||||
def add_flag(self, flag_getter, int flag_id=-1):
|
def add_flag(self, flag_getter, int flag_id=-1):
|
||||||
'''Set a new boolean flag to words in the vocabulary. The flag_setter
|
'''Set a new boolean flag to words in the vocabulary. The flag_setter
|
||||||
function will be called over the words currently in the vocab, and then
|
function will be called over the words currently in the vocab, and then
|
||||||
|
|
Loading…
Reference in New Issue