Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New examples #49

Merged
merged 6 commits into from Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/deep_learning/evaluation_metrics.md
Expand Up @@ -115,6 +115,14 @@ $$
\text{recall} = \frac{\text{TP}}{\text{TP} + \text{FN}}
$$

```{note}
Precision is about your prediction.
Recall is about reality.

If your job is to identify thieves.
```


#### False Negative Rate
False Negative Rate (FNR) tells us what proportion of the positive class got incorrectly classified by the classifier.

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -93,6 +93,7 @@ Contents
torch/pytorch_fundamental.ipynb
torch/pytorch_workflow.ipynb
torch/pytorch_neural_network_classification.ipynb
torch/pytorch_transformers.ipynb

.. toctree::
:caption: Recommendation System
Expand Down
16 changes: 8 additions & 8 deletions docs/requirements.txt
@@ -1,12 +1,12 @@
torch~=2.0
seaborn~=0.12
scipy~=1.10
scikit-learn~=1.2
torchmetrics~=0.11
myst-nb~=0.17
sphinx-design~=0.3
torch~=2.2
seaborn~=0.13
scipy~=1.12
scikit-learn~=1.4
torchmetrics~=1.3
myst-nb~=1.0
sphinx-design~=0.5
sphinx-copybutton
xlrd~=2.0
scikit-surprise~=1.1
networkx~=3.1
networkx~=3.2
gensim~=4.3
93 changes: 89 additions & 4 deletions docs/torch/pytorch_fundamental.ipynb
Expand Up @@ -12,22 +12,23 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2.0.0'"
"'2.1.0'"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import torch\n",
"import numpy as np\n",
"\n",
"torch.__version__"
]
Expand Down Expand Up @@ -1734,6 +1735,90 @@
"x[0, 0, :] # same as x[0][0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pytorch Best Practise"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also use torch.as_tensor() to convert a numpy array to a torch tensor, This will not create a new copy of the data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"a = np.random.rand(3, 3)\n",
"# Bad way\n",
"t1 = torch. tensor(a)\n",
"\n",
"# Good way\n",
"t2 = torch.as_tensor(a)\n",
"t3 = torch.from_numpy(a)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Avoid cpu, item() these will use functions to tranfer data between devices"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[0.7461, 0.3134],\n",
" [0.4447, 0.7793]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t= torch.rand(2,2)\n",
"# bad way\n",
"t.cpu ()\n",
"t[0][0].item()\n",
"t. numpy ()\n",
"\n",
"# good way\n",
"t.detach ()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create tensor direclty on GPU"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# bad way\n",
"# t = torch.rand(2,2).cuda()\n",
"\n",
"# good way\n",
"# t = torch. rand(2,2, device=\"cuda\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1758,7 +1843,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.4"
},
"orig_nbformat": 4
},
Expand Down
23 changes: 23 additions & 0 deletions docs/torch/pytorch_transfomers.ipynb
@@ -0,0 +1,23 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pytorch Transformer Implementation\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
Sphinx~=5.3
Sphinx~=7.2
-r docs/requirements.txt
sphinx_rtd_theme
sphinx-autobuild