"Function" (Net Encoder)


represents an encoder that uses a custom function f to encode an input producing an output tensor of dimensions d1×d2××dn.


  • NetEncoder[][input] applies the encoder to an input to produce an output.
  • NetEncoder[][{input1,input2,}] applies the encoder to a list of inputs to produce a list of outputs.
  • The input to the encoder inputi is of any type such that f[inputi] produces an array of dimensions d1×d2××dn. The array can be a NumericArray expression or a multidimensional list of numbers.
  • An encoder can be attached to an input port of a net by specifying "port"->NetEncoder[] when constructing the net.
  • Parameters
  • The following parameters are supported:
  • "Pattern"Noneexpected pattern for inputs to the function
    "Batched"Falsewhether the function should be provided a batch of inputs
  • The parameter "Pattern"patt specifies that inputs to the encoder must match the pattern patt. "Pattern" None indicates that no check should be performed.
  • With the parameter "Batched" True the function is applied once to a batch of examples rather than being applied to each of the examples individually.


open all close all

Basic Examples  (1)

Create a function encoder that takes a scalar and produces a length-2 list of these scalars:

Click for copyable input

Apply the encoder to a scalar:

Click for copyable input

Apply the encoder to a list of scalars:

Click for copyable input

Scope  (2)

Parameters  (2)

Possible Issues  (1)