Linear layer network
Neural networks often contain many layers, but most of them are linear layers. Understanding a single linear layer helps you grasp how they work before adding complexity.
Apply a linear layer to an input tensor and observe the output.
This exercise is part of the course
Introduction to Deep Learning with PyTorch
Exercise instructions
- Create a
Linear
layer that takes 3 features as input and returns 2 outputs. - Pass
input_tensor
through the linear layer.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import torch
import torch.nn as nn
input_tensor = torch.tensor([[0.3471, 0.4547, -0.2356]])
# Create a Linear layer
linear_layer = nn.____(
in_features=____,
out_features=____
)
# Pass input_tensor through the linear layer
output = ____(____)
print(output)