"Class" (Net Decoder)


represents a decoder that interprets a vector as class probabilities.


represents a decoder with class labels ci.


  • NetDecoder[][input] applies the decoder to an input to produce an output.
  • NetDecoder[][{input1,input2,}] applies the decoder to a list of inputs to produce a list of outputs.
  • NetDecoder["Class"] uses successive integers as class labels.
  • 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"->NetDecoder[] when constructing the net.
  • Properties
  • 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:
  • "Decision"the class ci with the highest probability (default)
    "TopDecisions"nthe n classes with the highest probabilities
    "TopProbabilities"probabilities for the most likely ci, returned as a list of rules
    "TopProbabilities"nprobabilities for the n most likely ci
    "Probabilities"the association <|c1->p1,c2->p2,|>
    "Probability"ciprobability for a specific ci
    "Entropy"the entropy of the probability distribution
    "RandomSample"sample each class proportionally to its probability
    "RandomSample"tsample using a positive temperature t
    Nonebypass decoding and return the input


open allclose all

Basic Examples  (1)

Create a class decoder:

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

Obtain the probability of getting each class:

Scope  (4)

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

This allows the net to return a class label:

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

Create a class decoder:

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

Return the top two predictions:

Return the probabilities for all classes:

Return the entropy of the distribution:

Return the entropy on a batch of inputs:

Sample a class according to the probabilities:

Create a class decoder that expects a matrix:

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

Obtain the probabilities for each class:

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