"Function" (Net Encoder)
NetEncoder[{"Function",f,{d1,d2,…,dn}]
represents an encoder that uses a custom function f to encode an input producing an output tensor of dimensions d1×d2×…×dn.
Details

- 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.
- The following parameters are supported:
-
"Pattern" None expected pattern for inputs to the function "Batched" False whether 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.
Parameters
Examples
open allclose allBasic Examples (1)
Scope (2)
Create a custom encoder that encodes radian inputs as their Cartesian coordinates:
Apply the encoder to a list of angles:
Create an encoder that returns a sequence of positive bounded integers:
Use this encoder with an EmbeddingLayer:
Parameters (2)
Possible Issues (1)
With the parameter "Pattern"None, whether or not the input is a single example or a list of examples is ambiguous. As a result, in cases in which a list of examples is provided, the function is called an extra time: