Struct rust2vec::Embeddings

source ·
pub struct Embeddings { /* private fields */ }
Expand description

Word embeddings.

This data structure stores word embeddings (also known as word vectors) and provides some useful methods on the embeddings, such as similarity and analogy queries.

Implementations

Perform an analogy query.

This method returns words that are close in vector space the analogy query word1 is to word2 as word3 is to ?. More concretely, it searches embeddings that are similar to:

embedding(word2) - embedding(word1) + embedding(word3)

At most, limit results are returned.

Perform an analogy query using the given similarity function.

This method returns words that are close in vector space the analogy query word1 is to word2 as word3 is to ?. More concretely, it searches embeddings that are similar to:

embedding(word2) - embedding(word1) + embedding(word3)

At most, limit results are returned.

Get (a view of) the raw embedding matrix.

Return the length (in vector components) of the word embeddings.

Get the embedding of a word.

Get the mapping from words to row indices of the embedding matrix.

Get an iterator over pairs of words and the corresponding embeddings.

Normalize the embeddings using their L2 (euclidean) norms.

Note: when you are using the output of e.g. word2vec, you should normalize the embeddings to get good query results.

Find words that are similar to the query word.

The similarity between two words is defined by the dot product of the embeddings. If the vectors are unit vectors (e.g. by virtue of calling normalize), this is the cosine similarity. At most, limit results are returned.

Find words that are similar to the query word using the given similarity function.

The similarity function should return, given the embeddings matrix and the word vector a vector of similarity scores. At most, limit results are returned.

Get the number of words for which embeddings are stored.

Get the words for which embeddings are stored. The words line up with the rows in the matrix returned by data.

Trait Implementations

The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
Read the embeddings from the given buffered reader.
Read the embeddings from the given buffered reader.
Read the embeddings from the given buffered reader.
Write the embeddings from the given writer.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.