Class MultiHeadAttention<H extends Head>
java.lang.Object
me.damoebe.architectures.transformer.mha.MultiHeadAttention<H>
- Type Parameters:
H- The type of head that is used stored in the class
- All Implemented Interfaces:
Cloneable,Backpropagation
public class MultiHeadAttention<H extends Head>
extends Object
implements Cloneable, Backpropagation
A container class for Heads
-
Constructor Summary
ConstructorsConstructorDescriptionMultiHeadAttention(Class<H> c, int headAmount, int inputEmbeddingAmount, int inputEmbeddingSize, boolean masked, double learningRate) Main constructor for the MultiHeadAttention class -
Method Summary
Modifier and TypeMethodDescriptiondouble[][]backPropagate(double[][] deltas) Updates All head QKV weights as well as the weights which are used to merge the head matricesclone()Clones a MultiHeadAttention object.static double[][]concatMatrices(List<double[][]> matrices) Merges a list of matrices.generateOutputFor(Sequence[] input) Generates an output for a list of inputs(embedding lists).intGetter for the used embedding amount of this MHA.intGetter for the used embedding size of this MHA.getHeads()Getter for the heads stored in the MultiHeadAttention
-
Constructor Details
-
MultiHeadAttention
public MultiHeadAttention(Class<H> c, int headAmount, int inputEmbeddingAmount, int inputEmbeddingSize, boolean masked, double learningRate) Main constructor for the MultiHeadAttention class- Parameters:
c- The class that is being used for the headsheadAmount- The amount of heads this MHA object should haveinputEmbeddingAmount- The amount of the input embeddingsinputEmbeddingSize- The size of the input embeddings
-
-
Method Details
-
generateOutputFor
-
backPropagate
public double[][] backPropagate(double[][] deltas) Updates All head QKV weights as well as the weights which are used to merge the head matrices- Specified by:
backPropagatein interfaceBackpropagation- Parameters:
deltas- The first hidden-layer deltas of the block's mlp- Returns:
- The new deltas used for the next backpropagation step.
-
clone
Clones a MultiHeadAttention object. -
concatMatrices
Merges a list of matrices.- Parameters:
matrices- the matrices that will be concat- Returns:
- the merged matrix as a 2d array
-
getEmbeddingAmount
public int getEmbeddingAmount()Getter for the used embedding amount of this MHA.- Returns:
- The embedding Amount
-
getEmbeddingSize
public int getEmbeddingSize()Getter for the used embedding size of this MHA.- Returns:
- the embedding size.
-
getHeads
-