embedding

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: BSD-2-Clause Imports: 7 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedding

type Embedding struct {
	*nn.Param
	// contains filtered or unexported fields
}

Embedding is an implementation of *nn.Param representing embedding values.

func (*Embedding) AccGrad

func (e *Embedding) AccGrad(gx mat.Tensor)

func (*Embedding) ZeroGrad

func (e *Embedding) ZeroGrad()

type Model

type Model struct {
	nn.Module
	Size    int
	Dim     int
	Weights []*nn.Param
	// contains filtered or unexported fields
}

Model implements a simple lookup table that stores fixed-size embeddings for a predefined dictionary. It is commonly used to store and retrieve word embeddings using their corresponding indices.

func New

func New[T float.DType](size int, dim int) *Model

New returns a new embeddings Model.

func (*Model) CountEmbedWithGrad

func (m *Model) CountEmbedWithGrad() int

func (*Model) Embedding

func (m *Model) Embedding(idx int) (*Embedding, error)

func (*Model) Encode

func (m *Model) Encode(input []int) ([]mat.Tensor, error)

Encode returns the embedding values associated with the input indices. It returns an error if one of the input elements is out of range.

func (*Model) MustEncode

func (m *Model) MustEncode(input []int) []mat.Tensor

MustEncode returns the embedding values associated with the input indices.

func (*Model) TraverseParams

func (m *Model) TraverseParams(callback func(param *nn.Param))

TraverseParams allows embeddings with gradients to be traversed for optimization.

func (*Model) ZeroGrad

func (m *Model) ZeroGrad()

type Shared

type Shared struct {
	*Model
}

Shared wraps Model, overriding binary marshaling methods in order to produce (and expect) empty data. This is useful e.g. to share embeddings between encoder and decoder models.

func (Shared) MarshalBinary

func (Shared) MarshalBinary() ([]byte, error)

MarshalBinary satisfies encoding.BinaryMarshaler interface. It always produces empty data (nil) and no error.

func (Shared) UnmarshalBinary

func (Shared) UnmarshalBinary(data []byte) error

UnmarshalBinary satisfies encoding.BinaryUnmarshaler interface. It only accepts empty data (nil or zero-length slice), producing no side effects at all. If data is not blank, it returns an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL