-
See Also
- NetEncoder
- NetDecoder
- NetChain
- NetGraph
- FeatureExtract
- UnitVector
-
- Net Encoders
- Tokens
- Characters
-
- Net Decoders
- Class
- Related Guides
- Tech Notes
"Class" (Net Encoder)
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 all close allBasic Examples (1)
Scope (1)
The default output form is to encode classes as integers:
enc = NetEncoder[{"Class", {a, b, c}}]enc[{a, b, c}]Specifying the "IndicatorVector" form will encode classes as "one-hot" vectors:
enc = NetEncoder[{"Class", {a, b, c}, "IndicatorVector"}]enc[{a, b, c}]Parameters (3)
"Dimensions" (2)
Create an encoder that takes a 3x3 matrix of classes and returns a matrix of indices:
enc = NetEncoder[{"Class", {a, b, c}, "Dimensions" -> {3, 3}}]enc[{{a, b, c}, {b, c, a}, {c, a, b}}]//MatrixFormCreate an encoder that takes a 2x2 matrix of classes and returns unit vectors:
enc = NetEncoder[{"Class", {a, b, c}, "IndicatorVector", "Dimensions" -> {2, 2}}]enc[{{a, b}, {b, c}}]Properties & Relations (1)
NetTrain will automatically try attach an encoder when a net is not fully specified. Automatic attachment of a class encoder:
net = NetTrain[NetChain[{UnitVectorLayer[], LinearLayer[]}], {"a" -> {1, 2}, "a" -> {2, 3}, "b" -> {3, 4}, "b" -> {4, 5}}]NetExtract[net, "Input"]See Also
NetEncoder NetDecoder NetChain NetGraph FeatureExtract UnitVector
Net Encoders: Tokens Characters
Net Decoders: Class