({{, (RefLink[NetDecoder, paclet:ref/NetDecoder])["Class"]
represents a decoder that interprets a vector as class probabilities.}, {, (RefLink[NetDecoder, paclet:ref/NetDecoder])[{"Class",{(Subscript[c, 1]),(Subscript[c, 2]),…}}]
represents a decoder with class labels (Subscript[c, i]).}})

OpenersNotesSection(Spacer1)Details

(RefLink[NetDecoder, paclet:ref/NetDecoder])[…][input] applies the decoder to an input to produce an output.

(RefLink[NetDecoder, paclet:ref/NetDecoder])[…][{(Subscript[input, 1]),(Subscript[input, 2]),…}] applies the decoder to a list of inputs to produce a list of outputs.

(RefLink[NetDecoder, paclet:ref/NetDecoder])["Class"] uses successive integers as class labels.

(RefLink[NetDecoder, paclet:ref/NetDecoder])[{"Class",…,"InputDepth"->n}] can be used to specify that the input array has depth n. The default depth is 1, indicating that the input is a vector. For matrix or higher-rank inputs, the last dimension is interpreted as the class dimension. Values must sum to 1 across this dimension.

A decoder can be attached to an output port of a net by specifying "port"->(RefLink[NetDecoder, paclet:ref/NetDecoder])[…] when constructing the net.

(RefLink[NetDecoder, paclet:ref/NetDecoder])[…][data,prop] can be used to calculate a specific property for the input data.

When a "Class" decoder is attached to a net, net[data,prop] or net[data,"oport"->prop] can be used to calculate a specific property of the decoded output.

The "Class" decoder supports the following properties prop:

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create a class decoder:

dec=NetDecoder[{"Class",{"a","b","c"}}]

Use the decoder on a probability vector to return the most probable class:

dec[{0.1,0.5,.4}]

Obtain the probability of getting each class:

dec[{0.1,0.5,.4},"Probabilities"]

OpenersExampleSection1(Spacer1)Scope  (4)

Decoders are most commonly used by attaching them to the output of a net:

net=SoftmaxLayer["Output"->NetDecoder[{"Class",{a,b,c}}]]

This allows the net to return a class label:

net[{3,4,5}]

Create and attach a class decoder that uses successive integers as class labels:

net=SoftmaxLayer["Output"->NetDecoder["Class"]]

net[{1,2,4,0}]

Create a class decoder:

dec=NetDecoder[{"Class",{a,b,c}}]

Use it on a probability vector to make a class prediction:

dec[{0.1,0.5,.4}]

Return the top two predictions:

dec[{0.1,0.5,0.4},{"TopDecisions",2}]

Return the probabilities for all classes:

dec[{0.1,0.5,0.4},"Probabilities"]

Return the entropy of the distribution:

dec[{0.1,0.5,0.4},"Entropy"]

Return the entropy on a batch of inputs:

dec[{{0.1,0.8,0.1},{0.3,0.4,0.3}},"Entropy"]

Sample a class according to the probabilities:

dec[{0.1,0.5,0.4},"RandomSample"]

Create a class decoder that expects a matrix:

dec=NetDecoder[{"Class",{a,b,c},"InputDepth"->2}]

Apply the decoder to a matrix whose rows are probability vectors:

dec[{{0.1,0.8,0.1},{0.6,0.3,0.1}}]

Obtain the probabilities for each class:

dec[{{0.1,0.8,0.1},{0.6,0.3,0.1}},"Probabilities"]//Map[Normal]

Attach the decoder to a net and apply it to an input:

net=NetInitialize@NetChain[{LinearLayer[{2,3}],SoftmaxLayer[]},"Input"->"Real","Output"->dec]

net[9.2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NetDecoder, paclet:ref/NetDecoder])  ▪  (RefLink[NetEncoder, paclet:ref/NetEncoder])  ▪  (RefLink[NetChain, paclet:ref/NetChain])  ▪  (RefLink[NetGraph, paclet:ref/NetGraph])  ▪  (RefLink[FeatureExtract, paclet:ref/FeatureExtract])  ▪  (RefLink[Ordering, paclet:ref/Ordering])  ▪  (RefLink[TakeLargestBy, paclet:ref/TakeLargestBy])  ▪  (RefLink[UnitVector, paclet:ref/UnitVector])}, {Related Net Encoders:  (RefLink[Class, paclet:ref/netencoder/Class])  ▪  (RefLink[Tokens, paclet:ref/netencoder/Tokens])  ▪  (RefLink[Characters, paclet:ref/netencoder/Characters])}, {Related Net Decoders:  (RefLink[Tokens, paclet:ref/netdecoder/Tokens])  ▪  (RefLink[Characters, paclet:ref/netdecoder/Characters])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Neural Networks in the Wolfram Language, paclet:tutorial/NeuralNetworksOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})