new commit.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -133,7 +133,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv (3.11.15)",
|
||||
"display_name": ".venv (3.11.15.final.0)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv (3.11.15)",
|
||||
"display_name": ".venv (3.11.15.final.0)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
+188
-52
@@ -10,7 +10,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 22,
|
||||
"id": "3163fb75",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 23,
|
||||
"id": "64a02514",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -34,7 +34,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 24,
|
||||
"id": "35200e59",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -42,36 +42,36 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Epoch 0: Loss = 42.0600\n",
|
||||
"Epoch 400: Loss = 24.6847\n",
|
||||
"Epoch 800: Loss = 14.4873\n",
|
||||
"Epoch 1200: Loss = 8.5024\n",
|
||||
"Epoch 1600: Loss = 4.9900\n",
|
||||
"Epoch 2000: Loss = 2.9286\n",
|
||||
"Epoch 2400: Loss = 1.7188\n",
|
||||
"Epoch 2800: Loss = 1.0087\n",
|
||||
"Epoch 3200: Loss = 0.5920\n",
|
||||
"Epoch 3600: Loss = 0.3474\n",
|
||||
"Epoch 4000: Loss = 0.2039\n",
|
||||
"Epoch 4400: Loss = 0.1197\n",
|
||||
"Epoch 4800: Loss = 0.0702\n",
|
||||
"Epoch 5200: Loss = 0.0412\n",
|
||||
"Epoch 5600: Loss = 0.0242\n",
|
||||
"Epoch 6000: Loss = 0.0142\n",
|
||||
"Epoch 6400: Loss = 0.0083\n",
|
||||
"Epoch 6800: Loss = 0.0049\n",
|
||||
"Epoch 7200: Loss = 0.0029\n",
|
||||
"Epoch 7600: Loss = 0.0017\n",
|
||||
"Epoch 8000: Loss = 0.0010\n",
|
||||
"Epoch 8400: Loss = 0.0006\n",
|
||||
"Epoch 8800: Loss = 0.0003\n",
|
||||
"Epoch 9200: Loss = 0.0002\n",
|
||||
"Epoch 9600: Loss = 0.0001\n",
|
||||
"Epoch 10000: Loss = 0.0001\n",
|
||||
"Epoch 10400: Loss = 0.0000\n",
|
||||
"Epoch 10800: Loss = 0.0000\n",
|
||||
"Epoch 11200: Loss = 0.0000\n",
|
||||
"Epoch 11600: Loss = 0.0000\n",
|
||||
"Epoch 0: Loss = 10481.2871\n",
|
||||
"Epoch 400: Loss = 207.9038\n",
|
||||
"Epoch 800: Loss = 122.0165\n",
|
||||
"Epoch 1200: Loss = 71.6102\n",
|
||||
"Epoch 1600: Loss = 42.0273\n",
|
||||
"Epoch 2000: Loss = 24.6654\n",
|
||||
"Epoch 2400: Loss = 14.4759\n",
|
||||
"Epoch 2800: Loss = 8.4958\n",
|
||||
"Epoch 3200: Loss = 4.9861\n",
|
||||
"Epoch 3600: Loss = 2.9263\n",
|
||||
"Epoch 4000: Loss = 1.7174\n",
|
||||
"Epoch 4400: Loss = 1.0079\n",
|
||||
"Epoch 4800: Loss = 0.5916\n",
|
||||
"Epoch 5200: Loss = 0.3472\n",
|
||||
"Epoch 5600: Loss = 0.2038\n",
|
||||
"Epoch 6000: Loss = 0.1196\n",
|
||||
"Epoch 6400: Loss = 0.0702\n",
|
||||
"Epoch 6800: Loss = 0.0412\n",
|
||||
"Epoch 7200: Loss = 0.0242\n",
|
||||
"Epoch 7600: Loss = 0.0142\n",
|
||||
"Epoch 8000: Loss = 0.0083\n",
|
||||
"Epoch 8400: Loss = 0.0049\n",
|
||||
"Epoch 8800: Loss = 0.0029\n",
|
||||
"Epoch 9200: Loss = 0.0017\n",
|
||||
"Epoch 9600: Loss = 0.0010\n",
|
||||
"Epoch 10000: Loss = 0.0006\n",
|
||||
"Epoch 10400: Loss = 0.0003\n",
|
||||
"Epoch 10800: Loss = 0.0002\n",
|
||||
"Epoch 11200: Loss = 0.0001\n",
|
||||
"Epoch 11600: Loss = 0.0001\n",
|
||||
"Epoch 12000: Loss = 0.0000\n",
|
||||
"Epoch 12400: Loss = 0.0000\n",
|
||||
"Epoch 12800: Loss = 0.0000\n",
|
||||
@@ -117,7 +117,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 25,
|
||||
"id": "be1eb1bd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -127,9 +127,9 @@
|
||||
"text": [
|
||||
"\n",
|
||||
"--- Результаты обучения ---\n",
|
||||
"Предсказание для 100°C: 211.99°F (Ожидалось: 212.00)\n",
|
||||
"Итоговый вес W: 1.7999 (Ожидалось: 1.8)\n",
|
||||
"Итоговое смещение B: 32.0029 (Ожидалось: 32.0)\n"
|
||||
"Предсказание для 100°C: 212.00°F (Ожидалось: 212.00)\n",
|
||||
"Итоговый вес W: 1.8000 (Ожидалось: 1.8)\n",
|
||||
"Итоговое смещение B: 31.9986 (Ожидалось: 32.0)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -153,7 +153,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"execution_count": 26,
|
||||
"id": "fa3c1e81",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -168,7 +168,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": 27,
|
||||
"id": "8860a027",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -178,7 +178,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": 28,
|
||||
"id": "b1213a8a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -189,7 +189,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 29,
|
||||
"id": "27d203c4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -197,11 +197,11 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Epoch 0: loss = 6039.51318359375\n",
|
||||
"Epoch 400: loss = 199.59164428710938\n",
|
||||
"Epoch 800: loss = 117.13835144042969\n",
|
||||
"Epoch 1200: loss = 68.74734497070312\n",
|
||||
"Epoch 1600: loss = 40.34719467163086\n"
|
||||
"Epoch 0: loss = 5640.71875\n",
|
||||
"Epoch 400: loss = 197.63983154296875\n",
|
||||
"Epoch 800: loss = 115.99267578125\n",
|
||||
"Epoch 1200: loss = 68.0748291015625\n",
|
||||
"Epoch 1600: loss = 39.95244598388672\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -223,7 +223,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 30,
|
||||
"id": "024b4276",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -233,9 +233,9 @@
|
||||
"text": [
|
||||
"\n",
|
||||
"--- Результаты обучения ---\n",
|
||||
"Предсказание для 100°C: 231.68°F\n",
|
||||
"Итоговый вес W: 2.0811\n",
|
||||
"Итоговое смещение B: 23.5716\n"
|
||||
"Предсказание для 100°C: 231.59°F\n",
|
||||
"Итоговый вес W: 2.0797\n",
|
||||
"Итоговое смещение B: 23.6129\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -253,16 +253,152 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 31,
|
||||
"id": "df8942cd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"--- MLP Model Architecture ---\n",
|
||||
"SimpleMLP(\n",
|
||||
" (fc1): Linear(in_features=784, out_features=128, bias=True)\n",
|
||||
" (fc2): Linear(in_features=128, out_features=10, bias=True)\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"--- Starting Training Simulation ---\n",
|
||||
"Epoch [1/5], Loss: 2.3642\n",
|
||||
"Epoch [2/5], Loss: 2.0382\n",
|
||||
"Epoch [3/5], Loss: 1.7581\n",
|
||||
"Epoch [4/5], Loss: 1.5167\n",
|
||||
"Epoch [5/5], Loss: 1.3047\n",
|
||||
"\n",
|
||||
"MLP Example successfully defined and simulated training steps.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import torch\n",
|
||||
"import torch.nn as nn\n",
|
||||
"import torch.optim as optim\n",
|
||||
"\n",
|
||||
"# 1. Define the MLP model\n",
|
||||
"class SimpleMLP(nn.Module):\n",
|
||||
" def __init__(self, input_size, hidden_size, output_size):\n",
|
||||
" super(SimpleMLP, self).__init__()\n",
|
||||
" # First linear layer: input to hidden layer\n",
|
||||
" self.fc1 = nn.Linear(input_size, hidden_size)\n",
|
||||
" # Second linear layer: hidden layer to output layer\n",
|
||||
" self.fc2 = nn.Linear(hidden_size, output_size)\n",
|
||||
"\n",
|
||||
" def forward(self, x):\n",
|
||||
" # Apply ReLU activation function\n",
|
||||
" x = torch.relu(self.fc1(x))\n",
|
||||
" # Output layer (no activation for regression or logits)\n",
|
||||
" x = self.fc2(x)\n",
|
||||
" return x\n",
|
||||
"\n",
|
||||
"# 2. Setup parameters\n",
|
||||
"input_size = 784 # Example: Flattened MNIST image (28*28)\n",
|
||||
"hidden_size = 128\n",
|
||||
"output_size = 10 # Example: Number of classes for classification\n",
|
||||
"\n",
|
||||
"# Initialize the model\n",
|
||||
"model = SimpleMLP(input_size, hidden_size, output_size)\n",
|
||||
"print(\"--- MLP Model Architecture ---\")\n",
|
||||
"print(model)\n",
|
||||
"\n",
|
||||
"# 3. Create dummy data for demonstration (In a real scenario, you would load a dataset like MNIST)\n",
|
||||
"# Batch size and input features\n",
|
||||
"batch_size = 64\n",
|
||||
"dummy_input = torch.randn(batch_size, input_size)\n",
|
||||
"# Dummy labels\n",
|
||||
"dummy_target = torch.randint(0, output_size, (batch_size,))\n",
|
||||
"\n",
|
||||
"# 4. Setup Loss Function and Optimizer\n",
|
||||
"criterion = nn.CrossEntropyLoss() # Suitable for multi-class classification\n",
|
||||
"optimizer = optim.Adam(model.parameters(), lr=0.001)\n",
|
||||
"\n",
|
||||
"print(\"\\n--- Starting Training Simulation ---\")\n",
|
||||
"\n",
|
||||
"# 5. Training Loop (Simulation)\n",
|
||||
"num_epochs = 5\n",
|
||||
"\n",
|
||||
"for epoch in range(num_epochs):\n",
|
||||
" # Forward pass\n",
|
||||
" outputs = model(dummy_input)\n",
|
||||
" \n",
|
||||
" # Calculate loss\n",
|
||||
" loss = criterion(outputs, dummy_target)\n",
|
||||
" \n",
|
||||
" # Backward pass and optimization\n",
|
||||
" optimizer.zero_grad()\n",
|
||||
" loss.backward()\n",
|
||||
" optimizer.step()\n",
|
||||
" \n",
|
||||
" print(f'Epoch [{epoch+1}/{num_epochs}], Loss: {loss.item():.4f}')\n",
|
||||
"\n",
|
||||
"print(\"\\nMLP Example successfully defined and simulated training steps.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"id": "98166324",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import torch\n",
|
||||
"from torch import nn\n",
|
||||
"from matplotlib import pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ef1351a0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X_test = torch.tensor("
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b9f7783b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"class Model(nn.Module):\n",
|
||||
" def __init__(self):\n",
|
||||
" super().__init__()\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "90874c3d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7b808533",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv (3.11.15)",
|
||||
"display_name": ".venv (3.11.15.final.0)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
@@ -776,7 +776,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv (3.11.15)",
|
||||
"display_name": ".venv (3.11.15.final.0)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user