[][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,
    S: Storage
[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<CowArray<f32, Ix1>>[src]

Get the embedding of a word.

pub fn embedding_into(&self, word: &str, target: ArrayViewMut1<f32>) -> bool[src]

Realize the embedding of a word into the given vector.

This variant of embedding realizes the embedding into the given vector. This makes it possible to look up embeddings without any additional allocations. This method returns false and does not modify the vector if no embedding could be found.

Panics when then the vector does not have the same dimensionality as the word embeddings.

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.

pub fn iter(&self) -> Iter[src]

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

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

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

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

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

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

impl<V, S> EmbeddingSimilarityBy for Embeddings<V, S> where
    V: Vocab,
    S: StorageView
[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, MmapQuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

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

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

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

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

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

impl From<Embeddings<SubwordVocab<ExplicitIndexer>, MmapQuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

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

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

impl From<Embeddings<SubwordVocab<ExplicitIndexer>, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[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>, MmapQuantizedArray>> 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>, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[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>>, MmapQuantizedArray>> 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>>, QuantizedArray>> for Embeddings<VocabWrap, StorageWrap>[src]

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

impl From<Embeddings<VocabWrap, 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, CowArray<'a, f32, Ix1>)

The type of the elements being iterated over.

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?

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

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

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

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<R> ReadWord2Vec<R> for Embeddings<SimpleVocab, NdArray> where
    R: BufRead
[src]

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

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

impl<V, S> WriteEmbeddings for Embeddings<V, S> where
    V: WriteChunk,
    S: WriteChunk, 
[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<W, V, S> WriteWord2Vec<W> for Embeddings<V, S> where
    W: Write,
    V: Vocab,
    S: Storage
[src]

Auto Trait Implementations

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

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

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> UnwindSafe for Embeddings<V, S> where
    S: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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<V, T> VZip<V> for T where
    V: MultiLane<T>,