Vectorsclassv2.0 This feature is new and was introduced in spaCy v2.0
Vectors data is kept in the
Vectors.data attribute, which should be an instance of
numpy.ndarray (for CPU vectors) or
cupy.ndarray (for GPU vectors). Multiple keys can be mapped to the same vector, and not all of the rows in the table need to be assigned – so
vectors.n_keys may be greater or smaller than
Create a new vector store. You can set the vector values and keys directly on initialisation, or supply a
shape keyword argument to create an empty table you can add vectors to later.
|The vector data.|
|iterable||A sequence of keys aligned with the data.|
|tuple|| Size of the table as |
|returns||The newly created object.|
Get a vector by key. If the key is not found in the table, a
KeyError is raised.
|int||The key to get the vector for.|
|returns||The vector for the key.|
Set a vector for the given key.
|int||The key to set the vector for.|
|The vector to set.|
Iterate over the keys in the table.
|yields||int||A key in the table.|
Return the number of vectors in the table.
|returns||int||The number of vectors in the table.|
Check whether a key has been mapped to a vector entry in the table.
|int||The key to check.|
|returns||bool||Whether the key has a vector entry.|
Add a key to the table, optionally setting a vector value as well. Keys can be mapped to an existing vector by setting
row, or a new vector can be added. When adding unicode keys, keep in mind that the
Vectors class itself has no
StringStore , so you have to store the hash-to-string mapping separately. If you need to manage the strings, you should use the
Vectors via the
Vocab class, e.g.
|unicode / int||The key to add.|
|An optional vector to add for the key.|
|int||An optional row number of a vector to map the key to.|
|returns||int||The row the vector was added to.|
Resize the underlying vectors array. If
inplace=True, the memory is reallocated. This may cause other references to the data to become invalid, so only use
inplace=True if you're sure that's what you want. If the number of vectors is reduced, keys mapped to rows that have
been deleted are removed. These removed items are returned as a list of
(key, row) tuples.
|tuple|| A |
|bool||Reallocate the memory.|
|returns||list||The removed items as a list of |
A sequence of the keys in the table.
Iterate over vectors that have been assigned to at least one key. Note that some vectors may be unassigned, so the number of vectors returned may be less than the length of the vectors table.
|yields||A vector in the table.|
(key, vector) pairs, in order.
(rows, dims) tuples of number of rows and number of dimensions in the vector table.
The vector size, i.e.
rows * dims.
|returns||int||The vector size.|
Whether the vectors table is full and has no slots are available for new
keys. If a table is full, it can be resized using
|returns||bool||Whether the vectors table is full.|
Get the number of keys in the table. Note that this is the number of all keys, not just unique vectors. If several keys are mapped are mapped to the same vectors, they will be counted individually.
|returns||int||The number of all keys in the table.|
Load GloVe vectors from a directory. Assumes binary format, that the vocab is in a
vocab.txt, and that vectors are named
vectors.128.f.bin for 128d float32 vectors,
vectors.300.d.bin for 300d float64 (double) vectors, etc. By default GloVe outputs 64-bit vectors.
|unicode / ||The path to load the GloVe vectors from.|
Save the current state to a directory.
|unicode / || A path to a directory, which will be created if it doesn't exist. Paths may be either strings or |
|-||Named attributes to prevent from being saved.|
Loads state from a directory. Modifies the object in place and returns it.
|unicode / || A path to a directory. Paths may be either strings or |
|returns||The modified |
Serialize the current state to a binary string.
|-||Named attributes to prevent from being serialized.|
|returns||bytes||The serialized form of the |
Load state from a binary string.
|bytes||The data to load from.|
|-||Named attributes to prevent from being loaded.|
| Stored vectors data. |
|dict|| Dictionary mapping word hashes to rows in the |
| Array keeping the keys in order, such that |