UnitVectorLayer

UnitVectorLayer[n]

represents a net layer that transforms integers between 1 and n into n-dimensional unit vectors.

UnitVectorLayer[]

leaves the n to be inferred from context.

Details and Options

  • UnitVectorLayer operates either on integers or tensors of integers, producing a vector or tensor, respectively.
  • Specifying UnitVectorLayer[n] will produce a net that infers the n when a NetEncoder[] that produces integers is connected to its input.
  • UnitVectorLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • UnitVectorLayer is typically used inside NetChain, NetGraph, etc.
  • UnitVectorLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an integer or tensor of integers
    "Output"an n-dimensional numerical vector or tensor of vectors
  • UnitVectorLayer[size,"Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:
  • NetEncoder[]encoder producing an integer or tensor of integers
    "Integer"a single integer
    da vector of integers of length d
    {d1,d2,}a tensor of integers of dimensions d1×d2×
    "Varying"a variable-length vector of integers
    {"Varying",d2,d3,}a variable-length sequence of tensors of dimensions d2×d3×

Examples

open allclose all

Basic Examples  (2)

Create a UnitVectorLayer that will accept 1 or 2 as input and produce a "one-hot" vector:

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

Create a UnitVectorLayer that will accept 1, 2 or 3 as input and produce a "one-hot" vector:

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

Apply the layer to an integer to produce an output vector:

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

Scope  (3)

Applications  (1)

Properties & Relations  (1)

See Also

EmbeddingLayer  NetChain  NetGraph  NetInitialize  NetTrain  NetExtract  UnitVector

Introduced in 2017
(11.1)