Skip to content

Commit be564b6

Browse files
author
Programmer-RD-AI
committed
20/6/23
1 parent 43e1532 commit be564b6

File tree

3 files changed

+177
-9
lines changed

3 files changed

+177
-9
lines changed

.ipynb_checkpoints/01-checkpoint.ipynb

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,74 @@
403403
"model_0.state_dict()"
404404
]
405405
},
406+
{
407+
"cell_type": "markdown",
408+
"id": "d2396bc2-ba48-4407-913c-8035d4490429",
409+
"metadata": {},
410+
"source": [
411+
"### Making predictions using `torch.inference_mode()`\n",
412+
"\n",
413+
"To check our models predictive poweerer, let's see how well it predictions `y_test` based on `X_test`\n",
414+
"\n",
415+
"When we pass data thhrough our moodel, it's going to run it through the forrward() mmeethod"
416+
]
417+
},
418+
{
419+
"cell_type": "code",
420+
"execution_count": 36,
421+
"id": "baa3c018-d9e3-4608-9436-81a50d17bd43",
422+
"metadata": {},
423+
"outputs": [],
424+
"source": [
425+
"# predictions = inference\n",
426+
"with torch.inference_mode():\n",
427+
" y_preds = model_0(X_test)"
428+
]
429+
},
406430
{
407431
"cell_type": "code",
408-
"execution_count": 30,
409-
"id": "4ea31f40-be2a-46dc-bc2f-939fe4d20d76",
432+
"execution_count": 37,
433+
"id": "2d180f63-6ed6-424a-8bab-ac57bc711e89",
434+
"metadata": {},
435+
"outputs": [
436+
{
437+
"data": {
438+
"text/plain": [
439+
"(tensor([[0.3982],\n",
440+
" [0.4049],\n",
441+
" [0.4116],\n",
442+
" [0.4184],\n",
443+
" [0.4251],\n",
444+
" [0.4318],\n",
445+
" [0.4386],\n",
446+
" [0.4453],\n",
447+
" [0.4520],\n",
448+
" [0.4588]]),\n",
449+
" tensor([[0.8600],\n",
450+
" [0.8740],\n",
451+
" [0.8880],\n",
452+
" [0.9020],\n",
453+
" [0.9160],\n",
454+
" [0.9300],\n",
455+
" [0.9440],\n",
456+
" [0.9580],\n",
457+
" [0.9720],\n",
458+
" [0.9860]]))"
459+
]
460+
},
461+
"execution_count": 37,
462+
"metadata": {},
463+
"output_type": "execute_result"
464+
}
465+
],
466+
"source": [
467+
"y_preds,y_test"
468+
]
469+
},
470+
{
471+
"cell_type": "code",
472+
"execution_count": 38,
473+
"id": "d5f30fe8-87be-437d-9465-27b2880184c1",
410474
"metadata": {},
411475
"outputs": [
412476
{
@@ -423,13 +487,29 @@
423487
}
424488
],
425489
"source": [
426-
"plot_predictions(predictions=model_0(X_test).detach().numpy())"
490+
"plot_predictions(predictions=y_preds)"
491+
]
492+
},
493+
{
494+
"cell_type": "markdown",
495+
"id": "577b7e2a-6ea8-4331-8b64-93e82a893c6a",
496+
"metadata": {},
497+
"source": [
498+
"## 3. Train Model\n",
499+
"\n",
500+
"The whole idea of training is for a model to move from *uknown* paamters to know parameters\n",
501+
"\n",
502+
"or in other words from a poor representation of the data to a better representation of the data\n",
503+
"\n",
504+
"One way to measure how badly the models predicions are is using a loss function\n",
505+
"\n",
506+
"Loss functions also called \"cost function\" or \"criterion\""
427507
]
428508
},
429509
{
430510
"cell_type": "code",
431511
"execution_count": null,
432-
"id": "baa3c018-d9e3-4608-9436-81a50d17bd43",
512+
"id": "f02c3d46-9f3e-48d4-8256-9fec0e11d899",
433513
"metadata": {},
434514
"outputs": [],
435515
"source": []

.virtual_documents/01.ipynb.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ def forward(self,X):
9999
model_0.state_dict()
100100

101101

102-
plot_predictions(predictions=model_0(X_test).detach().numpy())
102+
# predictions = inference
103+
with torch.inference_mode():
104+
y_preds = model_0(X_test)
105+
106+
107+
y_preds,y_test
108+
109+
110+
plot_predictions(predictions=y_preds)
103111

104112

105113

01.ipynb

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,74 @@
403403
"model_0.state_dict()"
404404
]
405405
},
406+
{
407+
"cell_type": "markdown",
408+
"id": "d2396bc2-ba48-4407-913c-8035d4490429",
409+
"metadata": {},
410+
"source": [
411+
"### Making predictions using `torch.inference_mode()`\n",
412+
"\n",
413+
"To check our models predictive poweerer, let's see how well it predictions `y_test` based on `X_test`\n",
414+
"\n",
415+
"When we pass data thhrough our moodel, it's going to run it through the forrward() mmeethod"
416+
]
417+
},
418+
{
419+
"cell_type": "code",
420+
"execution_count": 36,
421+
"id": "baa3c018-d9e3-4608-9436-81a50d17bd43",
422+
"metadata": {},
423+
"outputs": [],
424+
"source": [
425+
"# predictions = inference\n",
426+
"with torch.inference_mode():\n",
427+
" y_preds = model_0(X_test)"
428+
]
429+
},
406430
{
407431
"cell_type": "code",
408-
"execution_count": 30,
409-
"id": "4ea31f40-be2a-46dc-bc2f-939fe4d20d76",
432+
"execution_count": 37,
433+
"id": "2d180f63-6ed6-424a-8bab-ac57bc711e89",
434+
"metadata": {},
435+
"outputs": [
436+
{
437+
"data": {
438+
"text/plain": [
439+
"(tensor([[0.3982],\n",
440+
" [0.4049],\n",
441+
" [0.4116],\n",
442+
" [0.4184],\n",
443+
" [0.4251],\n",
444+
" [0.4318],\n",
445+
" [0.4386],\n",
446+
" [0.4453],\n",
447+
" [0.4520],\n",
448+
" [0.4588]]),\n",
449+
" tensor([[0.8600],\n",
450+
" [0.8740],\n",
451+
" [0.8880],\n",
452+
" [0.9020],\n",
453+
" [0.9160],\n",
454+
" [0.9300],\n",
455+
" [0.9440],\n",
456+
" [0.9580],\n",
457+
" [0.9720],\n",
458+
" [0.9860]]))"
459+
]
460+
},
461+
"execution_count": 37,
462+
"metadata": {},
463+
"output_type": "execute_result"
464+
}
465+
],
466+
"source": [
467+
"y_preds,y_test"
468+
]
469+
},
470+
{
471+
"cell_type": "code",
472+
"execution_count": 38,
473+
"id": "d5f30fe8-87be-437d-9465-27b2880184c1",
410474
"metadata": {},
411475
"outputs": [
412476
{
@@ -423,13 +487,29 @@
423487
}
424488
],
425489
"source": [
426-
"plot_predictions(predictions=model_0(X_test).detach().numpy())"
490+
"plot_predictions(predictions=y_preds)"
491+
]
492+
},
493+
{
494+
"cell_type": "markdown",
495+
"id": "577b7e2a-6ea8-4331-8b64-93e82a893c6a",
496+
"metadata": {},
497+
"source": [
498+
"## 3. Train Model\n",
499+
"\n",
500+
"The whole idea of training is for a model to move from *uknown* paamters to know parameters\n",
501+
"\n",
502+
"or in other words from a poor representation of the data to a better representation of the data\n",
503+
"\n",
504+
"One way to measure how badly the models predicions are is using a loss function\n",
505+
"\n",
506+
"Loss functions also called \"cost function\" or \"criterion\""
427507
]
428508
},
429509
{
430510
"cell_type": "code",
431511
"execution_count": null,
432-
"id": "baa3c018-d9e3-4608-9436-81a50d17bd43",
512+
"id": "f02c3d46-9f3e-48d4-8256-9fec0e11d899",
433513
"metadata": {},
434514
"outputs": [],
435515
"source": []

0 commit comments

Comments
 (0)