Invoking: `Python_REPL` with `import torch
import torch.nn as nn
import torch.optim as optim
# Define the neural network
class SingleNeuron(nn.Module):
    def __init__(self):
        super(SingleNeuron, self).__init__()
        self.linear = nn.Linear(1, 1)
        
    def forward(self, x):
        return self.linear(x)
# Create the synthetic data
x_train = torch.tensor([[1.0], [2.0], [3.0], [4.0]], dtype=torch.float32)
y_train = torch.tensor([[2.0], [4.0], [6.0], [8.0]], dtype=torch.float32)
# Create the neural network
model = SingleNeuron()
# Define the loss function and optimizer
criterion = nn.MSELoss()
optimizer = optim.SGD(model.parameters(), lr=0.01)
# Train the neural network
for epoch in range(1, 1001):
    # Forward pass
    y_pred = model(x_train)
    
    # Compute loss
    loss = criterion(y_pred, y_train)
    
    # Backward pass and optimization
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    
    # Print the loss every 100 epochs
    if epoch % 100 == 0:
        print(f"Epoch {epoch}: Loss = {loss.item()}")
# Make a prediction for x = 5
x_test = torch.tensor([[5.0]], dtype=torch.float32)
y_pred = model(x_test)
y_pred.item()`
Epoch 100: Loss = 0.03825576975941658
Epoch 200: Loss = 0.02100197970867157
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/toolkits/examples/python.html