selfattention

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	InputSize     int
	QuerySize     int
	KeySize       int
	ValueSize     int
	ScaleFactor   mat.Float
	UseCausalMask bool
}

Config provides configuration settings for a Self-Attention Model.

type Model

type Model struct {
	nn.BaseModel
	Config
	Query *linear.Model
	Key   *linear.Model
	Value *linear.Model
}

Model contains the serializable parameters.

func New

func New(config Config) *Model

New returns a new model with parameters initialized to zeros.

func (*Model) Forward

func (m *Model) Forward(qkv attention.QKV) attention.Output

Forward performs the forward step for each input node and returns the result. It generates the queries, keys and values from the same input xs.

func (*Model) ForwardWithPastKeysValues added in v0.5.0

func (m *Model) ForwardWithPastKeysValues(qkv attention.QKV, past attention.KeysValuesPair) attention.Output

ForwardWithPastKeysValues performs the forward step for each input node and returns the result. It generates the queries, keys and values from the same input xs.

Jump to

Keyboard shortcuts

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