NetDecoder

NetDecoder[type]

represents a decoder that takes a net representation and decodes it into an expression of a given form.

Details

  • A NetDecoder object can be attached to an output port of a net by specifying "port"->NetDecoder[] when constructing the net. Specifying "port"->"type" will create a decoder of the given type and attach it.
  • When a decoder is attached to the output of a net, net[input] will return the decoded output of the net. The raw output of the net can be obtained by specifying net[input,None].
  • Possible types include:
  • "Scalar"a single number decoded from a length-1 vector
    "Image"an RGB image
    {"Image",ColorSpaces}image with specified color space
    {"Class",{c1,c2,}}the ci for which the probability is highest
    "Boolean"probability of a Boolean variable being True
  • Possible types for decoding sequences include:
  • "Characters"probabilities of successive characters in a string
    {"Characters","c1c2"}probabilities pi for characters ci in a string
    "Tokens"probabilities of common English words
    {"Tokens",{"t1","t2",}}probabilities pi of tokens ti in a string
  • NetDecoder[][array] gives the specified decoded form for array.
  • NetDecoder[][{array1,array2, }] explicitly computes outputs for each of the arrayi.
  • With NetDecoder[{"Class", {c1,c2,}}], the ci typically represent categorical classes in a classifier.
  • NetDecoder[{"Class",}][array,prop] allows the following properties:
  • "Decision"the class ci with the highest probability
    {"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
  • NetDecoder[{"Characters",spec}] uses the same specifications spec as NetEncoder[{"Characters",spec}].
  • NetDecoder["Boolean"] decodes a probability p as True if p>0.5 and False otherwise.
  • NetDecoder is not involved in training done by NetTrain. However, when NetTrain is allowed to automatically attach a loss layer and a NetDecoder is attached to the output of the net, a NetEncoder of the same type will be created for the "Target" input of the loss layer.
  • NetDecoder[NetEncoder[]] will create a decoder based on the parameters of an existing encoder.

Examples

open allclose all

Basic Examples  (6)

Create a class decoder:

In[1]:=
Click for copyable input
Out[1]=

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

In[2]:=
Click for copyable input
Out[2]=

Predict the class for a batch of inputs:

In[3]:=
Click for copyable input
Out[3]=

Create a scalar decoder:

In[1]:=
Click for copyable input
Out[1]=

Use it to decode a vector of length one to a single scalar value:

In[2]:=
Click for copyable input
Out[2]=

Decode a set of vectors at once:

In[3]:=
Click for copyable input
Out[3]=

Create an RGB image decoder:

In[1]:=
Click for copyable input
Out[1]=

Use it to decode a three-channel matrix as an RGB image:

In[2]:=
Click for copyable input
Out[2]=

Create a grayscale image decoder:

In[3]:=
Click for copyable input
Out[3]=

Use it to decode a single-channel matrix as a grayscale image:

In[4]:=
Click for copyable input
Out[4]=

Create a Boolean decoder:

In[1]:=
Click for copyable input
Out[1]=

Decode a probability as either True or False:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Create a character decoder:

In[1]:=
Click for copyable input
Out[1]=

Decode a sentence from a one-hot vector representation:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Create a token encoder for English text:

In[1]:=
Click for copyable input
Out[1]=

Encode an English sentence:

In[2]:=
Click for copyable input
Out[2]=

Decode a nonsense sentence from a random matrix of probabilities:

In[3]:=
Click for copyable input
Out[3]=

Scope  (1)

Properties & Relations  (2)

Neat Examples  (1)

See Also

NetEncoder

Introduced in 2016
(11.0)
| Updated in 2017
(11.1)