"Class" (Net Encoder)
[Experimental]
NetEncoder[{"Class",classes}]
represents an encoder that converts a class label in the list classes to an integer code.
NetEncoder[{"Class",classes,form}]
represents an encoder that converts class labels to the output type form.
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 must be an element in the list classes.
- The following parameters are supported:
-
"Dimensions" {} input dimensions "Multilabel" False whether classes are not exclusive - When "Multilabel"False and form is "Index" (the default), the output of the encoder is the integer that is the position of input in classes.
- When "Multilabel"False and form is "IndicatorVector", the output of the encoder is an n-dimensional unit vector in the p
direction, where p is the position of input in classes, and n is the length of classes.
- When "Multilabel"True and form is "IndicatorVector", the output of the encoder is an n-dimensional unit vector with ones at the position of input classes and zeros elsewhere.
- An encoder can be attached to an input port of a net by specifying "port"->
[…] when constructing the net.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (1)Survey of the scope of standard use cases
The default output form is to encode classes as integers:
In[1]:=1

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-bddxmk
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-3v49em
Out[2]=2

Specifying the "IndicatorVector" form will encode classes as "one-hot" vectors:
In[3]:=3

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-hvyfbr
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-cp4tds
Out[4]=4

Parameters (3)
"Dimensions" (2)
Create an encoder that takes a 3x3 matrix of classes and returns a matrix of indices:
In[1]:=1

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-pdsdod
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-ln4n2t

Create an encoder that takes a 2x2 matrix of classes and returns unit vectors:
In[1]:=1

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-s85abb
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-5kg3fa
Out[2]=2

Properties & Relations (1)Properties of the function, and connections to other functions
NetTrain will automatically try attach an encoder when a net is not fully specified. Automatic attachment of a class encoder:
In[1]:=1

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-on9q0n
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0jvxou418hvrde4a2d2q-cma7rq
Out[2]=2
