public protocol Layer: Differentiable & KeyPathIterable
    where AllDifferentiableVariables: KeyPathIterable

A neural network layer.

Types that conform to Layer represent functions that map inputs to outputs. They may have an internal state represented by parameters, such as weight tensors.

Layer instances define a differentiable call method for mapping inputs to outputs.

  • The input type of the layer.

    Declaration

    associatedtype Input : Differentiable
  • The output type of the layer.

    Declaration

    associatedtype Output : Differentiable
  • Returns the output obtained from applying the layer to the given input.

    Declaration

    func call(_ input: Input) -> Output

    Parameters

    input

    The input to the layer.

    Return Value

    The output.

  • inferring(from:)

    Extension method

    Returns the inference output obtained from applying the layer to the given input.

    Declaration

    func inferring(from input: Input) -> Output

    Parameters

    input

    The input to the layer.

    Return Value

    The inference output.

  • Backpropagator

    Extension method

    Declaration

    typealias Backpropagator = (_ direction: Output.CotangentVector) -> (layerGradient: CotangentVector, inputGradient: Input.CotangentVector)
  • Returns the inference output and the backpropagation function obtained from applying the layer to the given input.

    Declaration

    func appliedForBackpropagation(to input: Input)
        -> (output: Output, backpropagator: Backpropagator)

    Parameters

    input

    The input to the layer.

    Return Value

    A tuple containing the output and the backpropagation function. The backpropagation function (a.k.a. backpropagator) takes a direction vector and returns the gradients at the layer and at the input, respectively.