# How to use UnitVectorLayer in a NetChain?

How can I create a NetChain with UnitVectorLayer inside? In this way I receive this error:

NetChain[{LinearLayer[1, "Input" -> 5], UnitVectorLayer[8, "Input" -> 1]}]


NetChain::ninctyp2: Incompatible types for output of layer 1, LinearLayer[{1},...], and input to layer 2, UnitVectorLayer[8,...]; a length-1 vector is not compatible with a length-1 vector of integers between 1 and 8, respectively.

Or

NetChain [{LinearLayer[1, "Input" -> 5], ThreadingLayer[LogisticSigmoid[#] + 1 &], ThreadingLayer[Round[#] &], UnitVectorLayer[2, "Input" -> 1]}]


NetChain::tyfail2: Inferred inconsistent shapes for output of third layer (a length-1 vector of integers between 1 and 2 versus a vector).

Or

NetChain [{LinearLayer[1, "Input" -> 5], ThreadingLayer[LogisticSigmoid[#] + 1 &], ThreadingLayer[IntegerPart[#] &], UnitVectorLayer[2, "Input" -> 1]}]


ThreadingLayer::invscf: IntegerPart[#1]& could not be symbolically evaluated as a binary scalar function.

## migrated from mathematica.meta.stackexchange.comNov 9 '18 at 12:38

This question came from our discussion, support, and feature requests site for users of Wolfram Mathematica.

• UnitVectorLayer works on a integers which LinearLayer returns reals. This seems like the crux of the issue... – Carl Lange Nov 9 '18 at 13:31
• Solutions as NetChain [{LinearLayer[1, "Input" -> 5], ThreadingLayer[LogisticSigmoid[#] + 1 &], ThreadingLayer[Chop[#] &], UnitVectorLayer[2, "Input" -> 1]}] give errors like: NetChain::tyfail2: Inferred inconsistent shapes for output of third layer (a length-1 vector of integers between 1 and 2 versus a vector). – tonegas Nov 12 '18 at 8:18