The nn.Linear layer can take any input sized Tensor as can be seen in the docs (Linear — PyTorch 1.9.0 documentation), the input has to be of shape (N,∗,H) where H is the number of input nodes in the layer, and * represent other dims. Find the shape of data_model (via data_model.shape) and the final dim is the number of nodes you need. (found via data_model.shape[-1])