Model Pipeline - Forward pass computation
This pipeline shows how data moves through a simple neural network during the forward pass. It transforms input data step-by-step to produce predictions.
This pipeline shows how data moves through a simple neural network during the forward pass. It transforms input data step-by-step to produce predictions.
Loss 1.2 |***** 0.9 |**** 0.7 |*** 0.5 |** 0.4 |*
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.45 | Loss starts high, accuracy low as model begins learning |
| 2 | 0.9 | 0.60 | Loss decreases, accuracy improves |
| 3 | 0.7 | 0.72 | Model learns better features, accuracy rises |
| 4 | 0.5 | 0.80 | Loss continues to drop, accuracy nearing good performance |
| 5 | 0.4 | 0.85 | Training converges with low loss and high accuracy |
model with input tensor x?model(x) runs the forward pass internally.model.forward(x) is discouraged; model.run and model.predict are not standard methods.import torch
import torch.nn as nn
class SimpleNet(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 2)
def forward(self, x):
return self.linear(x)
model = SimpleNet()
x = torch.randn(3, 4)
output = model(x)
print(output.shape)import torch
import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super().__init__()
self.fc = nn.Linear(5, 3)
def forward(self, x):
return self.fc(x)
model = Net()
x = torch.randn(4, 4)
output = model(x)
print(output)class ChainNet(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(3, 4)
self.fc2 = nn.Linear(4, 2)
def forward(self, x):
x = self.fc1(x)
x = torch.relu(x)
x = self.fc2(x)
return x
model = ChainNet()
x = torch.tensor([[1.0, 2.0, 3.0]])
output = model(x)
print(output)
What is the shape of output and why?Pass the test and this pattern moves unknown