[][src]Struct finalfusion::embeddings::Embeddings

pub struct Embeddings<V, S> { /* 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<V, S> Embeddings<V, S> where
    V: Vocab
[src]

pub fn new(
    metadata: Option<Metadata>,
    vocab: V,
    storage: S,
    norms: NdNorms
) -> Self
[src]

Construct an embeddings from a vocabulary, storage, and norms.

The embeddings for known words must be normalized. However, this is not verified due to the high computational cost.

impl<V, S> Embeddings<V, S>[src]

pub fn into_parts(self) -> (Option<Metadata>, V, S, Option<NdNorms>)[src]

Decompose embeddings in its vocabulary, storage, and optionally norms.

pub fn metadata(&self) -> Option<&Metadata>[src]

Get metadata.

pub fn metadata_mut(&mut self) -> Option<&mut Metadata>[src]

Get metadata mutably.

pub fn norms(&self) -> Option<&NdNorms>[src]

Get embedding norms.

pub fn set_metadata(&mut self, metadata: Option<Metadata>) -> Option<Metadata>[src]

Set metadata.

Returns the previously-stored metadata.

pub fn storage(&self) -> &S[src]

Get the embedding storage.

pub fn vocab(&self) -> &V[src]

Get the vocabulary.

impl<V, S> Embeddings<V, S> where
    V: Vocab,
    S: Storage
[src]

pub fn dims(&self) -> usize[src]

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

pub fn embedding(&self, word: &str) -> Option<CowArray1<f32>>[src]

Get the embedding of a word.

pub fn embedding_with_norm(&self, word: &str) -> Option<EmbeddingWithNorm>[src]

Get the embedding and original norm of a word.

Returns for a word:

  • The word embedding.
  • The norm of the embedding before normalization to a unit vector.

The original embedding can be reconstructed by multiplying all embedding components by the original norm.

If the model does not have associated norms, 1 will be returned as the norm for vocabulary words.

Important traits for Iter<'a>
pub fn iter(&self) -> Iter[src]

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

Important traits for IterWithNorms<'a>
pub fn iter_with_norms(&self) -> IterWithNorms[src]

Get an iterator over triples of words, embeddings, and norms.

Returns an iterator that returns triples of:

  • A word.
  • Its word embedding.
  • The original norm of the embedding before normalization to a unit vector.

The original embedding can be reconstructed by multiplying all embedding components by the original norm.

If the model does not have associated norms, the norm is always 1.

pub fn len(&self) -> usize[src]

Get the vocabulary size.

The vocabulary size excludes subword units.

Trait Implementations

impl ReadFastText for Embeddings<FastTextSubwordVocab, NdArray>[src]

impl<R> ReadText<R> for Embeddings<SimpleVocab, NdArray> where
    R: BufRead
[src]

impl<R> ReadTextDims<R> for Embeddings<SimpleVocab, NdArray> where
    R: BufRead
[src]

impl<W, V, S> WriteText<W> for Embeddings<V, S> where
    W: Write,
    V: Vocab,
    S: Storage
[src]

impl<W, V, S> WriteTextDims<W> for Embeddings<V, S> where
    W: Write,
    V: Vocab,
    S: Storage
[src]

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

impl<W, V, S> WriteWord2Vec<W> for Embeddings<V, S> where
    W: Write,
    V: Vocab,
    S: Storage
[src]

impl<V, S> Quantize<V> for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[src]

fn quantize<T>(
    &self,
    n_subquantizers: usize,
    n_subquantizer_bits: u32,
    n_iterations: usize,
    n_attempts: usize,
    normalize: bool
) -> Embeddings<V, QuantizedArray> where
    T: TrainPQ<f32>, 
[src]

Quantize the embedding matrix. Read more

impl<V, S> ReadEmbeddings for Embeddings<V, S> where
    V: ReadChunk,
    S: ReadChunk, 
[src]

impl<V, S> MmapEmbeddings for Embeddings<V, S> where
    Self: Sized,
    V: ReadChunk,
    S: MmapChunk, 
[src]

impl<V, S> WriteEmbeddings for Embeddings<V, S> where
    V: WriteChunk,
    S: WriteChunk, 
[src]

impl<V, S> Analogy for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[src]

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

Perform an analogy query. Read more

impl<V, S> AnalogyBy for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[src]

fn analogy_by<F>(
    &self,
    query: [&str; 3],
    limit: usize,
    similarity: F
) -> Result<Vec<WordSimilarityResult>, [bool; 3]> where
    F: FnMut(ArrayView2<f32>, ArrayView1<f32>) -> Array1<f32>, 
[src]

Perform an analogy query using the given similarity function. Read more

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

impl<V, S> EmbeddingSimilarity for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[src]

fn embedding_similarity(
    &self,
    query: ArrayView1<f32>,
    limit: usize
) -> Option<Vec<WordSimilarityResult>>
[src]

Find words that are similar to the query embedding. Read more

impl From<Embeddings<SimpleVocab, NdArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SimpleVocab, NdArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SimpleVocab, MmapArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SimpleVocab, MmapArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SimpleVocab, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<HashIndexer<FnvHasher>>, NdArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<HashIndexer<FnvHasher>>, NdArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SubwordVocab<HashIndexer<FnvHasher>>, MmapArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<HashIndexer<FnvHasher>>, MmapArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SubwordVocab<HashIndexer<FnvHasher>>, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<FastTextIndexer>, NdArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<FastTextIndexer>, NdArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SubwordVocab<FastTextIndexer>, MmapArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl From<Embeddings<SubwordVocab<FastTextIndexer>, MmapArray>> for Embeddings<VocabWrap, StorageViewWrap>[src]

impl From<Embeddings<SubwordVocab<FastTextIndexer>, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

impl<'a, V, S> IntoIterator for &'a Embeddings<V, S> where
    V: Vocab,
    S: Storage
[src]

type Item = (&'a str, CowArray1<'a, f32>)

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

impl<V: Debug, S: Debug> Debug for Embeddings<V, S>[src]

Auto Trait Implementations

impl<V, S> Sync for Embeddings<V, S> where
    S: Sync,
    V: Sync

impl<V, S> Unpin for Embeddings<V, S> where
    S: Unpin,
    V: Unpin

impl<V, S> Send for Embeddings<V, S> where
    S: Send,
    V: Send

impl<V, S> UnwindSafe for Embeddings<V, S> where
    S: UnwindSafe,
    V: UnwindSafe

impl<V, S> RefUnwindSafe for Embeddings<V, S> where
    S: RefUnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]