pub trait WordSimilarity {
    // Required method
    fn word_similarity(
        &self,
        word: &str,
        limit: usize,
        batch_size: Option<usize>
    ) -> Option<Vec<WordSimilarityResult<'_>>>;
}
Expand description

Trait for word similarity queries.

Required Methods§

source

fn word_similarity( &self, word: &str, limit: usize, batch_size: Option<usize> ) -> Option<Vec<WordSimilarityResult<'_>>>

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.

If batch_size is None, the query will be performed on all word embeddings at once. This is typically the most efficient, but can require a large amount of memory. The query is performed on batches of size n when batch_size is Some(n). Setting this to a smaller value than the number of word embeddings reduces memory use at the cost of computational efficiency.

Implementors§

source§

impl<V, S> WordSimilarity for Embeddings<V, S>where V: Vocab, S: StorageView,