specifies a neural net in which the output of layeri is connected to the input of layeri+1.


specifies a net consisting of a chain of explicitly named layers.

Details and Options

  • The input of a NetChain is taken to be the input of the first layer.
  • The output of a NetChain is taken to be the output of the last layer.
  • All intermediary layers must have exactly one input and one output port.
  • NetChain[][data] gives the result of applying the net to data.
  • NetChain[][data,NetPortGradient["Input"]] gives the gradient of the output with respect to the input data.
  • NetChain supports the following special layer specifications:
  • Ramp,LogisticSigmoid,ElementwiseLayer[f]
  • Normal[NetChain[]] will return a list or association of the layers used to construct the chain.
  • The StandardForm of NetChain shows a summary of the layers in the chain and the array dimensions of the output of each layer. Clicking a layer in the chain shows more information about that layer.
  • The following optional parameter can be included:
  • LearningRateMultipliersAutomaticlearning rate multipliers for the trainable arrays
  • The overall input and output array shapes for the chain can be specified using "Input"->shape and "Output"->shape options for NetChain.
  • Possible forms for shape include:
  • "Real"a single real number
    "Integer"a single integer
    na vector of length n
    {n1,n2,}an array of dimensions n1×n2×
    "Varying"a vector whose length is variable
    {"Varying",n2,n3,}an array whose first dimension is variable and remaining dimensions are n2×n3×
    NetEncoder[]an encoder (for input ports)
    NetEncoder[{,"Dimensions"{n1,}}]an encoder mapped over an array of dimensions n1×
    NetDecoder[]a decoder (for output ports)
    NetDecoder[{,"InputDepth"n}}]a decoder applied to an array of rank n
  • Any of the lengths ni given as Automatic are inferred from the structure of the chain.
  • NetChain[][data,opts] specifies that options should be used in applying the net to data. Possible options include:
  • BatchSizeAutomaticfor lists of inputs, the number of inputs to evaluate at once
    NetEvaluationMode"Test"what mode to use in performing evaluation
    TargetDevice"CPU"the target device on which to perform evaluation
    WorkingPrecision"Real32"the numerical precision used for evaluating the net
  • Possible settings for WorkingPrecision include:
  • "Real32"use single-precision real (32-bit)
    "Real64"use double-precision real (64-bit)
    "Mixed"use half-precision real for certain operations
  • WorkingPrecision->"Mixed" is only supported for TargetDevice->"GPU", where it can result in significant performance increases on certain devices.
  • When given a NumericArray as input, the output will be a NumericArray. In this case, its numeric type is derived from WorkingPrecision.
  • With the setting NetEvaluationMode->"Training", layers such as DropoutLayer will behave as they do for training rather than ordinary evaluation.
  • NetChain[][[spec]] extracts the layer specified by spec from the net.
  • NetTake[NetChain[],{start,end}] returns the sequence of layers between start and end as a new NetChain.
  • NetDrop[NetChain[],{start,end}] removes a sequence of layers from a NetChain, returning a new chain.
  • NetInsert[NetChain[],layer,pos] inserts a new layer into a NetChain at a specified position.
  • NetDelete[NetChain[],layer] deletes one or more layers from a NetChain, returning a new chain.
  • NetFlatten[NetChain[]] will flatten away any nested chains that appear as layers of a NetChain.
  • NetReplacePart[NetChain[],pos->layer] can be used to replace an existing layer of a NetChain with a new layer.
  • NetReplace[NetChain[],patt->layer] can be used to replace layers matching patt within a NetGraph with a new layer.
  • NetRename[NetChain[],"old"->"new"] can be used to rename layers of a NetChain.
  • Options[NetChain] gives the list of default options to construct the network. Options[NetChain[]] gives the list of default options to evaluate the network on some data.
  • Information[NetChain[]] gives a report about the network.
  • Information[NetChain[],prop] gives the value of the property prop of NetChain[]. Possible properties are the same as for NetGraph.


open allclose all

Basic Examples  (1)

Construct a chain consisting of two layers:

Apply the net to an input:

Scope  (4)

Construct a chain consisting of two layers and specifying that the input is a length-2 vector:

Initialize the net with random weights:

Apply the net to an input vector:

Construct a chain with explicitly named layers:

Extract the second layer by name:

Use Part syntax to extract the first layer:

Construct a chain:

Construct a new network consisting of the first two layers:

Construct a new network consisting of the last two layers:

Use special syntax for ElementwiseLayer and LinearLayer:

Properties & Relations  (5)

NetChain objects can be used as layers in a NetGraph:

NetGraph objects with one output and one input port can be used as layers inside NetChain objects:

NetChain objects can be converted to the equivalent NetGraph objects by writing NetGraph[chain]:

The layers used to construct a NetChain can be extracted using Normal:

Use Information[chain,"SummaryGraphic"] to get a Graphics[] expression that shows the underlying connectivity of a chain:

Neat Examples  (1)

Construct a base network that takes vector inputs of size 2 and produces vector outputs of size 3:

Make a table of 16 randomly initialized copies of the base network:

Plot them in a gallery by treating them as functions mapping (x,y) positions to (r,g,b) color values:

Wolfram Research (2016), NetChain, Wolfram Language function, (updated 2020).


Wolfram Research (2016), NetChain, Wolfram Language function, (updated 2020).


@misc{reference.wolfram_2020_netchain, author="Wolfram Research", title="{NetChain}", year="2020", howpublished="\url{}", note=[Accessed: 21-January-2021 ]}


@online{reference.wolfram_2020_netchain, organization={Wolfram Research}, title={NetChain}, year={2020}, url={}, note=[Accessed: 21-January-2021 ]}


Wolfram Language. 2016. "NetChain." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020.


Wolfram Language. (2016). NetChain. Wolfram Language & System Documentation Center. Retrieved from