pub trait Analogy {
    // Required method
    fn analogy_masked(
        &self,
        query: [&str; 3],
        remove: [bool; 3],
        limit: usize,
        batch_size: Option<usize>
    ) -> Result<Vec<WordSimilarityResult<'_>>, [bool; 3]>;

    // Provided method
    fn analogy(
        &self,
        query: [&str; 3],
        limit: usize,
        batch_size: Option<usize>
    ) -> Result<Vec<WordSimilarityResult<'_>>, [bool; 3]> { ... }
}
Expand description

Trait for analogy queries.

Required Methods§

source

fn analogy_masked( &self, query: [&str; 3], remove: [bool; 3], limit: usize, batch_size: Option<usize> ) -> Result<Vec<WordSimilarityResult<'_>>, [bool; 3]>

Perform an analogy query.

This method returns words that are close in vector space for 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.

remove specifies which parts of the queries are excluded from the output candidates. If remove[0] is true, word1 cannot be returned as an answer to the query.

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.

Result::Err is returned when no embedding could be computed for one or more of the tokens, indicating which of the tokens were present.

Provided Methods§

source

fn analogy( &self, query: [&str; 3], limit: usize, batch_size: Option<usize> ) -> Result<Vec<WordSimilarityResult<'_>>, [bool; 3]>

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. Result::Err is returned when no embedding could be computed for one or more of the tokens, indicating which of the tokens were present.

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> Analogy for Embeddings<V, S>where V: Vocab, S: StorageView,