Class EmbeddingLayer

java.lang.Object
smile.deep.layer.EmbeddingLayer
All Implemented Interfaces:
Function<Tensor,Tensor>, Layer

public class EmbeddingLayer extends Object implements Layer
An embedding layer that is a simple lookup table that stores embeddings of a fixed dictionary and size.

This layer is often used to store word embeddings and retrieve them using indices. The input to the module is a list of indices, and the output is the corresponding word embeddings.

  • Constructor Details

    • EmbeddingLayer

      public EmbeddingLayer(int numTokens, int dim)
      Constructor.
      Parameters:
      numTokens - the size of the dictionary of embeddings.
      dim - the size of each embedding vector.
    • EmbeddingLayer

      public EmbeddingLayer(int numTokens, int dim, double alpha)
      Constructor.
      Parameters:
      numTokens - the size of the dictionary of embeddings.
      dim - the size of each embedding vector.
      alpha - optional scaling factor.
  • Method Details

    • asTorch

      public org.bytedeco.pytorch.Module asTorch()
      Description copied from interface: Layer
      Returns the PyTorch Module object.
      Specified by:
      asTorch in interface Layer
      Returns:
      the PyTorch Module object.
    • forward

      public Tensor forward(Tensor input)
      Description copied from interface: Layer
      Forward propagation (or forward pass) through the layer.
      Specified by:
      forward in interface Layer
      Parameters:
      input - the input tensor.
      Returns:
      the output tensor.