TransformerEncoder
public struct TransformerEncoder<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
Transformer encoder sequencing positional encoding and token embedding and multiple transformer encoder layers, as introduced by Attention Is All You Need.
-
Undocumented
Declaration
Swift
public var encoderLayers: [TransformerEncoderBlock<Element, Device>] -
Declaration
Swift
public var parameters: [Tensor<Element, Device>] { get } -
Declaration
Swift
public var parameterPaths: [WritableKeyPath<`Self`, Tensor<Element, Device>>] { get } -
Creates a transformer encoder sequencing positional encoding and token embedding and multiple transformer encoder layers, as introduced by Attention Is All You Need.
Declaration
Swift
public init(layerCount: Int, heads: Int, keyDim: Int, valueDim: Int, modelDim: Int, forwardDim: Int, dropout: Float)Parameters
vocabSizeNumber of distinct tokens that can occur in input
layerCountNumber of transformer encoder layers
headsNumber of attention heads in each encoder layer
keyDimSize of keys in multi-head attention layers
valueDimSize of values in multi-head attention layers
modelDimSize of embedding vectors as well as hidden layer activations and outputs
forwardDimSize of hidden layer activations within pointwise feed forward layers
dropoutRate of dropout applied within pointwise feed forward and multi-head attention layers
-
Forwards the given batch of token sequences through the encoder.
Declaration
Parameters
inputsToken sequences
Return Value
Batch of encoder outputs with shape [inputs.count, maxLen, hiddenSize]
View on GitHub
TransformerEncoder Structure Reference