Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Deep Learning with PyTorch

Cursus bekijken

Oefeninstructies

  • Create a Linear layer that takes 3 features as input and returns 2 outputs.
  • Pass input_tensor through the linear layer.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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)
Code bewerken en uitvoeren