Class Word2Vec

java.lang.Object
ai.beestream.jitnn.nn.Module
ai.beestream.jitnn.nn.models.Word2Vec
All Implemented Interfaces:
AutoCloseable

public final class Word2Vec extends Module
word2vec (Mikolov et al., 2013) with negative sampling: an input embedding (the word vectors) and an output embedding, initialised like the original C code (input uniform in +-0.5 / dim, output zero). Skip-gram predicts a context word from the centre word, CBOW the centre word from the mean of its context. Examples come from Corpus.
  • Constructor Details

    • Word2Vec

      public Word2Vec(int vocab, int dim, Word2Vec.Mode mode, long seed)
      word2vec over vocab words with vectors of dim, trained as mode says, initialised from seed.
  • Method Details

    • loss

      public Tensor loss(int[] centres, int[] contexts, int[] negatives, int k)
      The loss of a batch: skip-gram takes centres [B] and contexts [B]; CBOW takes the centre words [B] and their contexts [B * window2] (window2 per sample). negatives holds k words per sample.
    • forward

      public Tensor forward(Tensor x)
      The word vectors of ids x.
      Specified by:
      forward in class Module
    • vectors

      public float[] vectors()
      All word vectors [vocab, dim] on the host.
    • dim

      public int dim()
      The vector size.