-
See Also
- NetDecoder
- NetEncoder
- NetChain
- NetGraph
- FeatureExtract
- Ordering
- TakeLargestBy
- UnitVector
-
- Net Encoders
- Class
- Tokens
- Characters
- Boolean
-
- Net Decoders
- Tokens
- Characters
- Boolean
- Related Guides
- Tech Notes
"Class" (Net Decoder)
NetDecoder["Class"]
represents a decoder that interprets a vector as class probabilities.
NetDecoder[{"Class",{c1,c2,…}}]
represents a decoder with class labels ci.
Details
- 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.
- A decoder can be attached to an output port of a net by specifying "port"->NetDecoder[…] when constructing the net.
- The following parameters are supported:
-
"InputDepth" 1 input array depth "Multilabel" False whether classes are drawn from independent distributions - 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.
- When "Multilabel"False, values must sum to 1 across the class dimension.
- When "Multilabel"True, values must lie between 0 and 1, and each value above 0.5 will produce a class in the output list of decisions.
- 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"n the n classes with the highest probabilities "TopProbabilities" probabilities for the most likely ci, returned as a list of rules "TopProbabilities"n probabilities for the n most likely ci "Probabilities" the association <|c1->p1,c2->p2,…|> "Probability"ci probability for a specific ci "Entropy" the entropy of the probability distribution "RandomSample" sample each class proportionally to its probability "RandomSample"t sample using a positive temperature t "RandomSample"{param1val1,…} random sampling with specific behavior None bypass decoding and return the input - Possible setting for parami in "RandomSample"{param1val1,…} include:
-
"Temperature"t sample using a positive temperature t "TotalProbabilityCutoff"p sample among the most probable classes with an accumulated probability of at least p (nucleus sampling) "TopProbabilities"k sample only among the k highest-probability classes
Parameters
Properties
Examples
open all close allBasic Examples (1)
Scope (3)
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}]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"]Parameters (2)
"InputDepth" (1)
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"]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]"Multilabel" (1)
Create a multilabel class decoder:
dec = NetDecoder[{"Class", {a, b, c}, "Multilabel" -> True}]Apply the decoder to a vector of independent probabilities:
dec[{0.1, 0.7, 0.6}]Obtain the probabilities for each class:
dec[{0.1, 0.7, 0.6}, "Probabilities"]Obtain the entropy for each class:
dec[{0.1, 0.7, 0.6}, "Entropy"]Sample a list of classes according to the probabilities:
dec[{0.1, 0.7, 0.6}, "RandomSample"]See Also
NetDecoder NetEncoder NetChain NetGraph FeatureExtract Ordering TakeLargestBy UnitVector
Net Encoders: Class Tokens Characters Boolean
Net Decoders: Tokens Characters Boolean