Network Layers
-
Undocumented
See moreDeclaration
Swift
public protocol LayerType
-
A sequential layer that concatenates the computations of two other layers.
With function builders, a sequential layer can be used to express sequential models in a type safe way.
Example:
let model = Sequential { Dense<Float, CPU>(inputSize: 32, outputSize: 64) Relu<Float, CPU>() Dense<Float, CPU>(inputSize: 64, outputSize: 10) Softmax<Float, CPU>() }
See moremodel
will have a typeSequential<Sequential<Dense<Float, CPU>, Relu<Float, CPU>>, Sequential<Dense<Float, CPU>, Softmax<Float, CPU>>>
. -
Dense (Linear, Fully connected) layer with no activation function.
See moreDeclaration
Swift
public struct Dense<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A 2D convolutional layer
See moreDeclaration
Swift
public struct Convolution2D<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A 2D transposed (fractionally strided) convolutional layer
See moreDeclaration
Swift
public struct TransposedConvolution2D<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A 2D max pooling layer
See moreDeclaration
Swift
public struct MaxPool2D<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
A 2D average pooling layer
See moreDeclaration
Swift
public struct AvgPool2D<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
A 2D adaptive max pooling layer that pools its inputs with an automatically computed stride and window size to reach the desired output size
See moreDeclaration
Swift
public struct AdaptiveMaxPool2D<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
A 2D adaptive average pooling layer that pools its inputs with an automatically computed stride and window size to reach the desired output size
See moreDeclaration
Swift
public struct AdaptiveAvgPool2D<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Undocumented
See moreDeclaration
Swift
public struct LSTM<Element, Device> : RNN, Codable where Element : RandomizableType, Device : DeviceType
-
Undocumented
See moreDeclaration
Swift
public struct GRU<Element, Device> : RNN, Codable where Element : RandomizableType, Device : DeviceType
-
A ‘vanilla’ RNN. In each step, the RNN performs the transformation matMul(x_t, W) + matMul(h_t-1, U) + b
See moreDeclaration
Swift
public struct BasicRNN<Element, Device> : RNN, Codable where Element : RandomizableType, Device : DeviceType
-
Transforms discrete values, such as word indices, into a lower dimensional embedding.
See moreDeclaration
Swift
public struct Embedding<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Positional Encoding layer using the encoding method proposed in Attention Is All You Need.
The layer takes an array of Ints as an input, which indicate the number of elements in each sequence of the minibatch. It returns a tensor with the shape [max(inputs), hiddenSize]. It does not mask out positional encodings for padding elements.
See moreDeclaration
Swift
public struct PositionalEncoding<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Computes Scaled Multi-Head Dot Product Attention as introduced by Attention Is All You Need.
See moreDeclaration
Swift
public struct ScaledDotProductAttention<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Multi-Head Attention Layer following Attention Is All You Need.
See moreDeclaration
Swift
public struct MultiHeadAttention<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Transformer encoder layer consisting of a self-attention and a pointwise feed forward layer as introduced by Attention Is All You Need.
See moreDeclaration
Swift
public struct TransformerEncoderBlock<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Transformer decoder layer consisting of a self attention, encoder attention and a pointwise feed forward layer as introduced by Attention Is All You Need.
See moreDeclaration
Swift
public struct TransformerDecoderBlock<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.
See moreDeclaration
Swift
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.
See moreDeclaration
Swift
public struct TransformerDecoder<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Pointwise feed forward layer as introduced in Attention Is All You Need.
The layer sequences a dense layer, GeLU activation, another dense layer and a dropout layer. Furthermore, it has a residual connection and the output is layer normalized.
See moreDeclaration
Swift
public struct PointwiseFeedForward<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A layer that normalizes its inputs along all dimensions except the batch dimension
See moreDeclaration
Swift
public struct LayerNorm<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A layer that normalizes its inputs along the batch dimension
See moreDeclaration
Swift
public struct BatchNorm<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
A dropout layer
See moreDeclaration
Swift
public struct Dropout<Element, Device> : LayerType, Codable where Element : RandomizableType, Device : DeviceType
-
Element-wise hyperbolic tangent activation layer.
See moreDeclaration
Swift
public struct Tanh<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise sigmoid activation layer.
See moreDeclaration
Swift
public struct Sigmoid<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise rectified linear unit activation layer.
See moreDeclaration
Swift
public struct Relu<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise leaky linear rectified unit activation layer.
See moreDeclaration
Swift
public struct LeakyRelu<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Softmax activation layer
See moreDeclaration
Swift
public struct Softmax<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Log Softmax activation layer
See moreDeclaration
Swift
public struct LogSoftmax<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Layer wrapping an arbitrary transform provided by a closure.
See moreDeclaration
Swift
public struct Lambda<Inputs, Outputs, Element, Device> : LayerType where Element : NumericType, Device : DeviceType
-
Layer that flattens its inputs into a tensor of shape [batchSize, -1]
See moreDeclaration
Swift
public struct Flatten<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Layer that reshapes its inputs to a given target size, except the batch size
See moreDeclaration
Swift
public struct Reshape<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Layer that concatenates a list of input tensors along their second dimension
See moreDeclaration
Swift
public struct Concat<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Type erased layer
See moreDeclaration
Swift
public struct AnyLayer<Inputs, Outputs, Parameter, Device> : LayerType where Parameter : NumericType, Device : DeviceType
-
Element-wise gaussian error linear unit activation layer.
See moreDeclaration
Swift
public struct Gelu<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise Swish activation layer.
See moreDeclaration
Swift
public struct Swish<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise Mish activation layer.
See moreDeclaration
Swift
public struct Mish<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType
-
Element-wise LiSHT activation layer.
See moreDeclaration
Swift
public struct LiSHT<Element, Device> : LayerType, Codable where Element : NumericType, Device : DeviceType