({{, (RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net] 
represents a net in which net is mapped over a sequence of inputs to give a sequence of outputs.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net] represents a net that takes a sequence of arrays and outputs a sequence of the same length.

(RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net] accepts a single input sequence {(Subscript[x, 1]),(Subscript[x, 2]),…,(Subscript[x, n])} and computes {net[(Subscript[x, 1])],net[(Subscript[x, 2])],…,net[(Subscript[x, n])]}.

In (RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net], net should take exactly one input and produce exactly one output.

(RefLink[NetExtract, paclet:ref/NetExtract]) can be used to extract net from a (RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net] object.

The input and output ports of the net represented by (RefLink[NetMapOperator, paclet:ref/NetMapOperator]) are:

(RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net] can be seen as allowing a form of weight sharing between multiple copies of net, one for each sequence element that is being mapped.

(RefLink[NetMapOperator, paclet:ref/NetMapOperator])[net,"Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:

When given a (RefLink[NumericArray, paclet:ref/NumericArray]) as input, the output will be a (RefLink[NumericArray, paclet:ref/NumericArray]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[NetMapOperator, paclet:ref/NetMapOperator]) that maps a (RefLink[LinearLayer, paclet:ref/LinearLayer]) over a sequence:

NetMapOperator[LinearLayer[]]

Create a (RefLink[NetMapOperator, paclet:ref/NetMapOperator]) that maps a (RefLink[SummationLayer, paclet:ref/SummationLayer]) over a sequence:

map=NetMapOperator[SummationLayer["Input"->2]]

Apply the layer to a sequence of vectors:

map[{{1,2},{3,4},{5,6}}]

The layer threads across a batch of sequences of different lengths:

map[{{{1,2},{3,4}},{{5,6},{7,8},{9,10}}}]

OpenersExampleSection1(Spacer1)Scope  (3)

Create a net that maps a (RefLink[LinearLayer, paclet:ref/LinearLayer]) over a sequence of vectors that have been one-hot encoded from the characters of a string:

map=NetInitialize @ NetMapOperator[LinearLayer[2],"Input"->NetEncoder[{"Characters",Automatic,"UnitVector"}]]

Apply the net to some inputs:

map["abc"]//MatrixForm

map["abcxyz"]//MatrixForm

The initialized (RefLink[LinearLayer, paclet:ref/LinearLayer]) can be obtained using (RefLink[NetExtract, paclet:ref/NetExtract]):

NetExtract[map,"Net"]

Create a net that maps a single pooling layer over a pair of images. First create a pooling layer that operates on images:

pool=PoolingLayer[16,"Input"->NetEncoder["Image"],"Output"->NetDecoder["Image"]]

pool[]

Create a net that maps the pooling layer over sequences of images:

map=NetMapOperator[pool]

map[{,}]

Use (RefLink[NetMapOperator, paclet:ref/NetMapOperator]) to apply a one-dimensional pooling to each row of an image:

map=NetMapOperator[PoolingLayer[20],"Input"->NetEncoder["Image"],"Output"->NetDecoder["Image"]]

map[]

OpenersExampleSection3(Spacer1)Applications  (1)

Sorting lists of numbers. Generate a test and training set consisting of lists of integers between 1 and 6:

digits=Range[6];
seqs=RandomSample[Flatten[Table[Tuples[digits,n],{n,3,6}],1]];
data=Map[#->Sort[#]&,seqs];
{testData,trainData}=TakeDrop[data,Ceiling[Length[data]/10]];

Display three random samples drawn from the training set:

RandomSample[trainData,3]

Define a (RefLink[NetGraph, paclet:ref/NetGraph]) with an (RefLink[AttentionLayer, paclet:ref/AttentionLayer]):

net = NetGraph[<|
"enc"->{EmbeddingLayer[12],LongShortTermMemoryLayer[50]},"dec"->LongShortTermMemoryLayer[50],
"key"->NetMapOperator[50],
"value"->NetMapOperator[50],
"attend"->AttentionLayer["Dot"],
"cat"->CatenateLayer[2],"classify"->{NetMapOperator[LinearLayer[]],SoftmaxLayer[]}
|>,{
"enc"->"key"->NetPort["attend","Key"],"enc"->"value"->NetPort["attend","Value"],
"enc"->"dec"->NetPort["attend","Query"],
"dec"->"cat","attend"->"cat","cat"->"classify"},"Input"->{"Varying",NetEncoder[{"Class",digits}]},"Output"->{"Varying",NetDecoder[{"Class",digits}]}
]

Train the net:

trained=NetTrain[net,trainData,MaxTrainingRounds->3,ValidationSet->testData]

Use the net to sort a list of integers:

trained[{6,6,1,4,2}]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

(RefLink[NetMapOperator, paclet:ref/NetMapOperator]) can be used to implement (RefLink[NetPairEmbeddingOperator, paclet:ref/NetPairEmbeddingOperator]). Create an initialized (RefLink[LinearLayer, paclet:ref/LinearLayer]):

linear=NetInitialize@LinearLayer[2,"Input"->{2}]

Create (RefLink[NetPairEmbeddingOperator, paclet:ref/NetPairEmbeddingOperator]) using the linear layer as its embedding net, and evaluate it on an input:

pairNet=NetPairEmbeddingOperator[linear,"DistanceFunction"->EuclideanDistance]

pairNet[{{1,2},{3,4}}]

Define a (RefLink[NetGraph, paclet:ref/NetGraph]) with a (RefLink[NetMapOperator, paclet:ref/NetMapOperator]) that is equivalent to the previous (RefLink[NetPairEmbeddingOperator, paclet:ref/NetPairEmbeddingOperator]), and evaluate it on the same input:

mapNet=NetGraph[{NetMapOperator[linear,"Input"->{2,2}],PartLayer[1],PartLayer[2],ThreadingLayer[(#1-#2)^2&],SummationLayer[]},{1->2,1->3,{2,3}->4->5}]

mapNet[{{1,2},{3,4}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NetMapThreadOperator, paclet:ref/NetMapThreadOperator])  ▪  (RefLink[NetNestOperator, paclet:ref/NetNestOperator])  ▪  (RefLink[NetFoldOperator, paclet:ref/NetFoldOperator])  ▪  (RefLink[Fold, paclet:ref/Fold])  ▪  (RefLink[NetChain, paclet:ref/NetChain])  ▪  (RefLink[NetGraph, paclet:ref/NetGraph])  ▪  (RefLink[NetExtract, paclet:ref/NetExtract])}})}})

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

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