multiheadattention

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeysValuesPairs added in v0.5.0

type KeysValuesPairs = []attention.KeysValuesPair

KeysValuesPairs contains the attention.KeysValuesPair for each attention head.

type Model

type Model struct {
	nn.BaseModel
	Attention   []*selfattention.Model
	OutputMerge *linear.Model
	NumOfHeads  int // number of heads
	Dm          int // input and output vectors dimension
	Dk          int // hidden vectors dimension (Dm / NumOfHeads)
}

Model contains the serializable parameters.

func New

func New(size, numOfHeads int, useCausalMask bool) *Model

New returns a new model with parameters initialized to zeros.

func (*Model) Forward

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

Forward performs the forward step for each input node and returns the result.

func (*Model) ForwardWithPastKeysValues added in v0.5.0

func (m *Model) ForwardWithPastKeysValues(qkv attention.QKV, pastProjKeysValues KeysValuesPairs) Output

ForwardWithPastKeysValues performs the forward step for each input node and returns the result.

type Output added in v0.5.0

type Output struct {
	// Result of the multi-head attention.
	AttOutput []ag.Node
	// AttWeights attention scores.
	AttWeights [][]mat.Matrix
	// ProjKeysValues contains the attention.KeysValuesPair for each attention head.
	ProjKeysValues KeysValuesPairs
}

Output aggregates the multiple output of the multi-head attentions, incl. attention scores and last projected keys and values for each head.

Jump to

Keyboard shortcuts

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