BaşlayınÜcretsiz Başlayın

Introducing the LightningModule

Get ready to build your first LightningModule! In this hands-on exercise, you'll set up the core structure of a classification workflow. You'll define a linear layer, pass data through it in the forward method, and compute the loss in the training step. This clean structure gives you a solid foundation to start experimenting with your models.

The torch and lightning.pytorch, imported as pl, have been preloaded for you.

Bu egzersiz

Scalable AI Models with PyTorch Lightning

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Define a class LightModel that inherits from pl.LightningModule.
  • Define a linear layer to transform your input, assuming the input features are 16 and there are 10 output classes.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Define the model class
class LightModel(____):
  	# Define a linear layer to transform your input
    def __init__(self):
        super().__init__()
        self.layer = ____
    def forward(self, x):
        return self.layer(x)
    def training_step(self, batch, batch_idx):
        x, y = batch
        logits = self(x)
        loss = torch.nn.functional.cross_entropy(logits, y)
        return loss
Kodu Düzenle ve Çalıştır