represents a net that takes a sequence of inputs and returns the last element of the sequence.
SequenceLastLayer
represents a net that takes a sequence of inputs and returns the last element of the sequence.
Details and Options
- SequenceLastLayer[] represents a net that takes a sequence of arrays and outputs a single array.
- SequenceLastLayer[…][input] explicitly computes the output from applying the layer.
- SequenceLastLayer[…][{input1,input2,…}] explicitly computes an output for each of the inputi.
- When given a NumericArray as input, the output will be a NumericArray.
- SequenceLastLayer is typically used inside NetChain, NetGraph, etc.
- The input and output ports of the net represented by SequenceLastLayer[] are:
-
"Input" a sequence of rank-n arrays "Output" a rank-n array - SequenceLastLayer["Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:
-
n a sequence of n numbers "Varying" a vector whose length is variable {len,d1,d2,…} sequence of len arrays of dimensions d1×d2×… {"Varying",d1,d2,…} varying number of arrays of dimensions d1×d2×… - Options[SequenceLastLayer] gives the list of default options to construct the layer. Options[SequenceLastLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[SequenceLastLayer[…]] gives a report about the layer.
- Information[SequenceLastLayer[…],prop] gives the value of the property prop of SequenceLastLayer[…]. Possible properties are the same as for NetGraph.
Examples
open all close allBasic Examples (2)
Create a SequenceLastLayer:
SequenceLastLayer[]Create a SequenceLastLayer that expects a sequence of vectors of size 3:
last = SequenceLastLayer["Input" -> {"Varying", 3}]Apply the layer to a sequence:
last[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]Scope (2)
Ports (2)
Create a SequenceLastLayer that expects a length-3 sequence of 2×2 matrices:
last = SequenceLastLayer["Input" -> {3, 2, 2}]Apply the layer to a sequence:
last[{{{1, 2}, {4, 5}}, {{7, 8}, {10, 11}}, {{12, 13}, {14, 15}}}]Create a SequenceLastLayer that expects a sequence of real numbers:
last = SequenceLastLayer["Input" -> "Varying"]last[{1, 2, 3}]The layer threads across a batch of inputs:
last[{{1, 2, 3}, {4, 5}, {6, 7, 8, 9}}]Applications (1)
SequenceLastLayer is commonly used to obtain a fixed-sized representation of a sequence, needed for tasks such as sequence classification, by taking the final output from a recurrent layer:
classify = NetChain[{BasicRecurrentLayer[10], SequenceLastLayer[], LinearLayer[3], SoftmaxLayer[]}, "Input" -> {"Varying", 3}, "Output" -> NetDecoder[{"Class", {"a", "b", "c"}}]]Possible Issues (1)
SequenceLastLayer cannot accept symbolic inputs:
last = SequenceLastLayer[];
last[{1, 2}]last[{1, z}]Tech Notes
Related Guides
History
Text
Wolfram Research (2017), SequenceLastLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/SequenceLastLayer.html.
CMS
Wolfram Language. 2017. "SequenceLastLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SequenceLastLayer.html.
APA
Wolfram Language. (2017). SequenceLastLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SequenceLastLayer.html
BibTeX
@misc{reference.wolfram_2026_sequencelastlayer, author="Wolfram Research", title="{SequenceLastLayer}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/SequenceLastLayer.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sequencelastlayer, organization={Wolfram Research}, title={SequenceLastLayer}, year={2017}, url={https://reference.wolfram.com/language/ref/SequenceLastLayer.html}, note=[Accessed: 13-June-2026]}