Embedding

class Embedding(trainableWeights: TrainableTensor) : TrainableLayer<Embedding>

A trainable embedding table with size vocabSize x embeddingSize

Parameters

numEmbeddings

the size of the vocabulary/number of embedding vectors

embeddingSize

the size of each embedding vector

Accepts a tensor of Shape() and returns a tensor of Shape(, embeddingSize)

Constructors

Embedding
Link copied to clipboard
fun Embedding(numEmbeddings: Int, embeddingSize: Int, random: Random, initializer: (Shape, Random) -> FloatTensor = Initializer.gaussian())
Embedding
Link copied to clipboard
fun Embedding(trainableWeights: TrainableTensor)

Functions

cpu
Link copied to clipboard
open override fun cpu(): Embedding
equals
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
extractTangent
Link copied to clipboard
open override fun extractTangent(output: DTensor, extractor: (DTensor, DTensor) -> DTensor): TrainableComponent.Companion.Tangent
getSingleInput
Link copied to clipboard
open fun getSingleInput(inputs: Array<out DTensor>): DTensor

Helper to check that the layer was called with a single input. Returns that input if successful, else errors.

gpu
Link copied to clipboard
open override fun gpu(): Embedding
hashCode
Link copied to clipboard
open override fun hashCode(): Int
invoke
Link copied to clipboard
open operator override fun invoke(vararg inputs: DTensor): DTensor
operator fun invoke(input: IntTensor): DTensor
load
Link copied to clipboard
open override fun load(from: ByteBuffer): Embedding
store
Link copied to clipboard
open override fun store(into: ByteBuffer): ByteBuffer
to
Link copied to clipboard
open fun to(device: Device): OnDevice
trainingStep
Link copied to clipboard
open override fun trainingStep(optim: Optimizer<*>, tangent: Trainable.Tangent): Embedding
withTrainables
Link copied to clipboard
open override fun withTrainables(trainables: List<Trainable<*>>): Embedding
wrap
Link copied to clipboard
open override fun wrap(wrapper: Wrapper): Embedding

The wrap function should return the same static type it is declared on.

Properties

trainables
Link copied to clipboard
open override val trainables: List<Trainable<*>>
trainableWeights
Link copied to clipboard
val trainableWeights: TrainableTensor