Struct rust2vec::Embeddings [] [src]

pub struct Embeddings { /* fields omitted */ }

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.

Methods

impl Embeddings
[src]

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 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

impl<R> ReadText<R> for Embeddings where
    R: BufRead + Seek
[src]

Read the embeddings from the given buffered reader.

impl<W> WriteText<W> for Embeddings where
    W: Write
[src]

Read the embeddings from the given buffered reader.

impl<R> ReadWord2Vec<R> for Embeddings where
    R: BufRead
[src]

Read the embeddings from the given buffered reader.

impl<W> WriteWord2Vec<W> for Embeddings where
    W: Write
[src]

Write the embeddings from the given writer.