ScaledDotProductAttention

scalation.modeling.autograd.ScaledDotProductAttention

Implements the Scaled Dot-Product Attention mechanism. This class is a sequence module that computes the attention scores and applies them to the value tensor (v) based on the query (q) and key (k) tensors. It is a fundamental building block for transformer models.

Attributes

See also
Graph
Supertypes
class SeqModule
class BaseModule
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def forward(inputs: IndexedSeq[Variabl]): IndexedSeq[Variabl]

Forward pass for the Scaled Dot-Product Attention module. This method takes three input tensors (q, k, v), computes the attention scores, and applies them to the value tensor.

Forward pass for the Scaled Dot-Product Attention module. This method takes three input tensors (q, k, v), computes the attention scores, and applies them to the value tensor.

Value parameters

inputs

an IndexedSeq containing the query (q), key (k), and value (v) tensors

Attributes

Returns

an IndexedSeq containing the resulting attention tensor

Throws
IllegalArgumentException

if the number of inputs is not 3

Definition Classes

Inherited methods

def apply(inputs: IndexedSeq[Variabl]): IndexedSeq[Variabl]

Alias for forward, allows calling the module as a function: module(xs).

Alias for forward, allows calling the module as a function: module(xs).

Attributes

Inherited from:
SeqModule
def eval(): Unit

Set the module to evaluation mode (and all submodules recursively).

Set the module to evaluation mode (and all submodules recursively).

Attributes

Inherited from:
BaseModule
def gradients: IndexedSeq[TensorD]

Return the gradients of all parameters.

Return the gradients of all parameters.

Attributes

Inherited from:
BaseModule
def parameters: IndexedSeq[Variabl]

Return all trainable parameters, including those from submodules.

Return all trainable parameters, including those from submodules.

Attributes

Inherited from:
BaseModule
def setParameters(newParams: IndexedSeq[Variabl]): Unit

Replace the current parameters with new ones. Useful for weight updates, loading saved models, etc.

Replace the current parameters with new ones. Useful for weight updates, loading saved models, etc.

Value parameters

newParams

The new parameter list to assign

Attributes

Inherited from:
BaseModule
def train(mode: Boolean = ...): Unit

Set the module to training mode (and all submodules recursively).

Set the module to training mode (and all submodules recursively).

Attributes

Inherited from:
BaseModule
def zeroGrad()(using ops: AutogradOps): Unit

Zero out all gradients (in-place).

Zero out all gradients (in-place).

Attributes

Inherited from:
BaseModule

Inherited fields

var inTrainingMode: Boolean

Flag to control training or evaluation behavior.

Flag to control training or evaluation behavior.

Attributes

Inherited from:
BaseModule
lazy val subModules: IndexedSeq[BaseModule]

Automatically detect submodules (other BaseModules) within this module.

Automatically detect submodules (other BaseModules) within this module.

Attributes

Inherited from:
BaseModule