Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 additions & 2 deletions torchPractice.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMKIObSWw9zRBP98DJ8zV/c",
"authorship_tag": "ABX9TyOO6Xm7mvw5K+JRfZK6D4+F",
"include_colab_link": true
},
"kernelspec": {
Expand All @@ -23,7 +23,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/krishnabhunia/googleColab_mycode/blob/test_review/torchPractice.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/krishnabhunia/googleColab_mycode/blob/test_review_from_google_colab/torchPractice.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand Down Expand Up @@ -198,6 +198,67 @@
]
}
]
},
{
"cell_type": "code",
"source": [
"# Define a simple neural network model\n",
"class SimpleNet(nn.Module):\n",
" def __init__(self):\n",
" super(SimpleNet, self).__init__()\n",
" self.fc1 = nn.Linear(5, 10) # 5 input features, 10 hidden neurons\n",
" self.fc2 = nn.Linear(10, 2) # 10 hidden neurons, 2 output classes\n",
"\n",
" def forward(self, x):\n",
" x = torch.relu(self.fc1(x))\n",
" x = self.fc2(x)\n",
" return x\n",
"\n",
"# Instantiate the model, loss function, and optimizer\n",
"model = SimpleNet()\n",
"criterion = nn.CrossEntropyLoss()\n",
"optimizer = optim.Adam(model.parameters(), lr=0.001)\n",
"\n",
"# Training loop\n",
"for epoch in range(10):\n",
" for batch_X, batch_y in dataloader:\n",
" # Forward pass\n",
" outputs = model(batch_X)\n",
" loss = criterion(outputs, batch_y)\n",
"\n",
" # Backward pass and optimization\n",
" optimizer.zero_grad()\n",
" loss.backward()\n",
" optimizer.step()\n",
"\n",
" print(f'Epoch [{epoch+1}/10], Loss: {loss.item():.4f}')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "pXNFWZgR5_wX",
"outputId": "85870ab9-9cd0-4c45-d47d-e1c1e0e998b0"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Epoch [1/10], Loss: 0.8287\n",
"Epoch [2/10], Loss: 0.5781\n",
"Epoch [3/10], Loss: 0.8722\n",
"Epoch [4/10], Loss: 0.6403\n",
"Epoch [5/10], Loss: 0.7962\n",
"Epoch [6/10], Loss: 0.7425\n",
"Epoch [7/10], Loss: 0.6679\n",
"Epoch [8/10], Loss: 0.7107\n",
"Epoch [9/10], Loss: 0.7298\n",
"Epoch [10/10], Loss: 0.5971\n"
]
}
]
}
]
}