diff --git a/docs/deep_learning/evaluation_metrics.md b/docs/deep_learning/evaluation_metrics.md index 5748b50..074aa20 100644 --- a/docs/deep_learning/evaluation_metrics.md +++ b/docs/deep_learning/evaluation_metrics.md @@ -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. diff --git a/docs/index.rst b/docs/index.rst index 1b4a156..66dc97a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 diff --git a/docs/requirements.txt b/docs/requirements.txt index 05ad6ce..4cb3ebf 100644 --- a/docs/requirements.txt +++ b/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 \ No newline at end of file diff --git a/docs/torch/pytorch_fundamental.ipynb b/docs/torch/pytorch_fundamental.ipynb index e152f38..8b127fe 100644 --- a/docs/torch/pytorch_fundamental.ipynb +++ b/docs/torch/pytorch_fundamental.ipynb @@ -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__" ] @@ -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, @@ -1758,7 +1843,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.4" }, "orig_nbformat": 4 }, diff --git a/docs/torch/pytorch_transfomers.ipynb b/docs/torch/pytorch_transfomers.ipynb new file mode 100644 index 0000000..e214cd1 --- /dev/null +++ b/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 +} diff --git a/requirements.txt b/requirements.txt index 5f88124..1db4d1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Sphinx~=5.3 +Sphinx~=7.2 -r docs/requirements.txt sphinx_rtd_theme sphinx-autobuild \ No newline at end of file