{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "title: 11 Introduction to GNNs\n", "description: Introduction to Graph Neural Networks. Applies basic GCN to Cora dataset for node classification.\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"Colab\"" ] }, { "cell_type": "markdown", "metadata": { "id": "sjX6CPJFA52R" }, "source": [ "## Introduction to GNNs with PyTorch Geometric\n", "\n", "In this short notebook, the goal is to provide a introductory guide to get started with Graph Neural Networks using the popular library called [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/index.html). PyTorch Geometric is a PyTorch based libary hence we will be using PyTorch in this tutorial. \n", "\n", "The code used in this tutorial has been adapted from their official [examples](https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html). I have incorporated a bit more beginner-friendly guidance and kept it minimal." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "mwTz9zaHC7YA", "outputId": "ce24d6a4-907f-4094-eb98-bc6ea0520e34" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11.1\n" ] } ], "source": [ "# Find the CUDA version PyTorch was installed with\n", "!python -c \"import torch; print(torch.version.cuda)\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2jo0YpV0DLDW", "outputId": "238637c0-e60b-42fc-e7de-86f47f39ec4f" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.10.0+cu111\n" ] } ], "source": [ "# PyTorch version\n", "!python -c \"import torch; print(torch.__version__)\"" ] }, { "cell_type": "markdown", "metadata": { "id": "P-VLTfxzEmLu" }, "source": [ "Install the follow packages but make sure to install the right version below. Find more instructions [here](https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html) if you get lost. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "fLbSOIkaDRe4", "outputId": "b196161e-d1bf-4595-ccaa-49747f3ec00c" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Looking in links: https://data.pyg.org/whl/torch-1.10.0+cu111.html\n", "Collecting torch-scatter\n", " Downloading https://data.pyg.org/whl/torch-1.10.0%2Bcu113/torch_scatter-2.0.9-cp37-cp37m-linux_x86_64.whl (7.9 MB)\n", "\u001b[K |████████████████████████████████| 7.9 MB 2.5 MB/s \n", "\u001b[?25hInstalling collected packages: torch-scatter\n", "Successfully installed torch-scatter-2.0.9\n" ] } ], "source": [ "!pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu111.html" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Q-wRLXE_DkZF", "outputId": "cb249940-3c85-4572-eb41-3d3ef2a5407d" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Looking in links: https://data.pyg.org/whl/torch-1.10.0+cu111.html\n", "Collecting torch-sparse\n", " Downloading https://data.pyg.org/whl/torch-1.10.0%2Bcu113/torch_sparse-0.6.12-cp37-cp37m-linux_x86_64.whl (3.5 MB)\n", "\u001b[K |████████████████████████████████| 3.5 MB 2.8 MB/s \n", "\u001b[?25hRequirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from torch-sparse) (1.4.1)\n", "Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.7/dist-packages (from scipy->torch-sparse) (1.19.5)\n", "Installing collected packages: torch-sparse\n", "Successfully installed torch-sparse-0.6.12\n" ] } ], "source": [ "!pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu111.html" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "lAobCDu6Dppo", "outputId": "d7675ad2-6b5f-4162-caa8-13fa658d1793" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting torch-geometric\n", " Downloading torch_geometric-2.0.3.tar.gz (370 kB)\n", "\u001b[K |████████████████████████████████| 370 kB 5.3 MB/s \n", "\u001b[?25hRequirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (1.19.5)\n", "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (4.62.3)\n", "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (1.4.1)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (2.6.3)\n", "Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (1.0.2)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (2.23.0)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (1.3.5)\n", "Collecting rdflib\n", " Downloading rdflib-6.1.1-py3-none-any.whl (482 kB)\n", "\u001b[K |████████████████████████████████| 482 kB 48.3 MB/s \n", "\u001b[?25hRequirement already satisfied: googledrivedownloader in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (0.4)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (2.11.3)\n", "Requirement already satisfied: pyparsing in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (3.0.7)\n", "Collecting yacs\n", " Downloading yacs-0.1.8-py3-none-any.whl (14 kB)\n", "Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from torch-geometric) (3.13)\n", "Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from jinja2->torch-geometric) (2.0.1)\n", "Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->torch-geometric) (2018.9)\n", "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->torch-geometric) (2.8.2)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->torch-geometric) (1.15.0)\n", "Collecting isodate\n", " Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\n", "\u001b[K |████████████████████████████████| 41 kB 486 kB/s \n", "\u001b[?25hRequirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from rdflib->torch-geometric) (4.10.1)\n", "Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from rdflib->torch-geometric) (57.4.0)\n", "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->rdflib->torch-geometric) (3.7.0)\n", "Requirement already satisfied: typing-extensions>=3.6.4 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->rdflib->torch-geometric) (3.10.0.2)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->torch-geometric) (2021.10.8)\n", "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->torch-geometric) (2.10)\n", "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->torch-geometric) (3.0.4)\n", "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->torch-geometric) (1.24.3)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->torch-geometric) (3.1.0)\n", "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->torch-geometric) (1.1.0)\n", "Building wheels for collected packages: torch-geometric\n", " Building wheel for torch-geometric (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for torch-geometric: filename=torch_geometric-2.0.3-py3-none-any.whl size=581968 sha256=eee568026f004ea2d960222f33768328b638194617a05429f1e10e5c019857d0\n", " Stored in directory: /root/.cache/pip/wheels/c3/2a/58/87ce0508964d4def1aafb92750c4f3ac77038efd1b9a89dcf5\n", "Successfully built torch-geometric\n", "Installing collected packages: isodate, yacs, rdflib, torch-geometric\n", "Successfully installed isodate-0.6.1 rdflib-6.1.1 torch-geometric-2.0.3 yacs-0.1.8\n" ] } ], "source": [ "!pip install torch-geometric" ] }, { "cell_type": "markdown", "metadata": { "id": "GNfiSdoUFaoF" }, "source": [ "## Getting Started" ] }, { "cell_type": "markdown", "metadata": { "id": "D6LCvEr7CGF9" }, "source": [ "Import PyTorch" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "pqrlyFN1AtXI", "outputId": "850011fd-9eb1-4afc-8ba2-1416f4801c05" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.10.0+cu111\n" ] } ], "source": [ "import torch\n", "\n", "# print torch version\n", "print(torch.__version__)" ] }, { "cell_type": "markdown", "metadata": { "id": "V0xfcmMfCFIH" }, "source": [ "The great thing about PyTorch Geometric is that it contain useful functionalities to import and load graph related data. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "gfIc5j5YB2_a" }, "outputs": [], "source": [ "from torch_geometric.data import Data" ] }, { "cell_type": "markdown", "metadata": { "id": "4wuBs1NHEFqn" }, "source": [ "Now let's create an unweighted and undirected graph with three nodes and four total edges." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "-nLnUIObCTjK", "outputId": "e4ac0c52-5b42-40be-8f35-091f04fd7a9c" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data(x=[3, 1], edge_index=[2, 4])\n" ] } ], "source": [ "# define edge list\n", "edge_index = torch.tensor([[0, 1, 1, 2], [1, 0, 2, 1]], dtype=torch.long)\n", "\n", "# define node features\n", "x = torch.tensor([[-1], [0], [1]])\n", "\n", "# create graph data object\n", "data = Data(x=x, edge_index=edge_index)\n", "print(data)" ] }, { "cell_type": "markdown", "metadata": { "id": "zV7bQ6tAEQ7H" }, "source": [ "Our data object `Data` has many useful utility functions to check the properties of the graph. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "idbfqPzoEOPC", "outputId": "f22248ff-27e6-4cec-ec15-a0c2bbea463c" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n" ] } ], "source": [ "# check number of edges of the graph\n", "print(data.num_edges)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "r0lcSstME0MP", "outputId": "c88ad32a-22aa-4507-8824-ac9961cad74e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n" ] } ], "source": [ "# check number of nodes of the graph\n", "print(data.num_nodes)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "yiegwHTyE2AO", "outputId": "182f22cc-0a52-48b8-d1b6-19c0d926a35f" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] } ], "source": [ "# check number of features of the graph\n", "print(data.num_features)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "JNWjhaSeE3Yk", "outputId": "5a08aebe-a590-4a93-f58f-a0d45d70a2b2" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n" ] } ], "source": [ "# check if graph is directed\n", "print(data.is_directed())" ] }, { "cell_type": "markdown", "metadata": { "id": "HF-jGPyhFeO6" }, "source": [ "## Loading Data" ] }, { "cell_type": "markdown", "metadata": { "id": "KBVX6mZfFBxE" }, "source": [ "Find more fun functions related to graph data [here](https://pytorch-geometric.readthedocs.io/en/latest/modules/data.html#torch_geometric.data.Data). " ] }, { "cell_type": "markdown", "metadata": { "id": "LHvE23mwFJ-3" }, "source": [ "One of the cool things about the PyTorch Geometric library is that it contains out-of-the-box benchmark datasets that are ready to use and explore. A popular dataset is the Cora dataset that is used for supervised graph node classification. (We will talk about these applications in an upcoming tutorial but for now we will focus on the data itself).\n", "\n", "\"The Cora dataset consists of 2708 scientific publications classified into one of seven classes. The citation network consists of 5429 links. Each publication in the dataset is described by a 0/1-valued word vector indicating the absence/presence of the corresponding word from the dictionary. The dictionary consists of 1433 unique words.\" - [Papers with Code](https://paperswithcode.com/dataset/cora)." ] }, { "cell_type": "markdown", "metadata": { "id": "_8ganBm_FiaQ" }, "source": [ "Let's load the Cora dataset:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "K3bXwOpoE75M", "outputId": "ede1ca54-0336-4642-c82f-c1b9c7ed5f3b" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.x\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.tx\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.allx\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.y\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.ty\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.ally\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.graph\n", "Downloading https://github.com/kimiyoung/planetoid/raw/master/data/ind.cora.test.index\n", "Processing...\n", "Done!\n" ] } ], "source": [ "from torch_geometric.datasets import Planetoid\n", "\n", "dataset = Planetoid(root='tmp/Cora', name='Cora')" ] }, { "cell_type": "markdown", "metadata": { "id": "rQTFnBcuFpLv" }, "source": [ "Let's check some of the properties of the Cora dataset." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "q9jvXbRXFlGG", "outputId": "5d22903d-65dd-4e67-b5d4-ccfe682c1157" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of graphs: 1\n", "Number of features: 1433\n", "Number of classes: 7\n" ] } ], "source": [ "# number of graphs\n", "print(\"Number of graphs: \", len(dataset))\n", "\n", "# number of features\n", "print(\"Number of features: \", dataset.num_features)\n", "\n", "# number of classes\n", "print(\"Number of classes: \", dataset.num_classes)" ] }, { "cell_type": "markdown", "metadata": { "id": "57SX-idAF02R" }, "source": [ "We can see that this particular graph dataset only contains one graph. Graph data can be very complex and can include multiple graphs depending on the type of data and application. Let's check more feature of the Cora dataset:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "8aOt8HwfFrH_", "outputId": "b7043e70-aafe-4b7d-c877-83feed65c12b" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of nodes: 2708\n", "Number of edges: 10556\n", "Is directed: False\n" ] } ], "source": [ "# select the first graph\n", "data = dataset[0]\n", "\n", "# number of nodes\n", "print(\"Number of nodes: \", data.num_nodes)\n", "\n", "# number of edges\n", "print(\"Number of edges: \", data.num_edges)\n", "\n", "# check if directed\n", "print(\"Is directed: \", data.is_directed())" ] }, { "cell_type": "markdown", "metadata": { "id": "3XX2MRY4GEQS" }, "source": [ "You can sample nodes from the graph this way:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "qGJKbv-4GAtY", "outputId": "8c2a45dc-0b4d-4027-b252-5e48ef787cd6" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape of sample nodes: torch.Size([5, 1433])\n" ] } ], "source": [ "# sample nodes from the graph\n", "print(\"Shape of sample nodes: \", data.x[:5].shape)" ] }, { "cell_type": "markdown", "metadata": { "id": "wV1yBQSvGM9q" }, "source": [ "We extracted 5 nodes from the graph and checked its shape. You will see that each node has `1433` features." ] }, { "cell_type": "markdown", "metadata": { "id": "oXMY2lU0GWQL" }, "source": [ "Another great advantage of using PyTorch Geometric to load the Cora data is that it comes pre-processed and ready to use. It also has the splits for training, validation and test which we can directly use for training a GNN.\n", "\n", "Let's check some stats for the partitions of the data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "MzITbLkpGIUP", "outputId": "7a95cc3c-67dc-4050-e22a-556928cefae8" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# of nodes to train on: 140\n", "# of nodes to test on: 1000\n", "# of nodes to validate on: 500\n" ] } ], "source": [ "# check training nodes\n", "print(\"# of nodes to train on: \", data.train_mask.sum().item())\n", "\n", "# check test nodes\n", "print(\"# of nodes to test on: \", data.test_mask.sum().item())\n", "\n", "# check validation nodes\n", "print(\"# of nodes to validate on: \", data.val_mask.sum().item())" ] }, { "cell_type": "markdown", "metadata": { "id": "7IGOoSfwHjeD" }, "source": [ "That information is important as it will indicate to our model which nodes to train against and which to test against, and so on.\n", "\n", "When training neural networks we train them using batches of data. PyTorch Geometric provides efficient processes to load batches of data.\n", "\n", "PyTorch Geometric contains a data loader which is a very popular feature in PyTorch to efficiently load data when training neural networks. " ] }, { "cell_type": "markdown", "metadata": { "id": "_SUZUnXzH1zN" }, "source": [ "So let's try to load the data using the built in `DataLoader`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "9tdHl4oZGw_y" }, "outputs": [], "source": [ "from torch_geometric.datasets import Planetoid\n", "from torch_geometric.loader import DataLoader\n", "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "xtJAp4QqIMWw", "outputId": "8df69cee-89ab-441b-9526-6029b41b6bb8" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "cpu\n" ] } ], "source": [ "print(device)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "06xbeTJcH8C-" }, "outputs": [], "source": [ "dataset = Planetoid(root='tmp/Cora', name='Cora')\n", "data = dataset[0].to(device)" ] }, { "cell_type": "markdown", "metadata": { "id": "8MH0lQsYIV0V" }, "source": [ "Print some quick statistics about the data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "gK7-K6uYH_Iu", "outputId": "0613a450-caf0-4137-c00f-a45ed8db412f" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "X shape: torch.Size([2708, 1433])\n", "Edge shape: torch.Size([2, 10556])\n", "Y shape: torch.Size([2708])\n" ] } ], "source": [ "print(\"X shape: \", data.x.shape)\n", "print(\"Edge shape: \", data.edge_index.shape)\n", "print(\"Y shape: \", data.y.shape)" ] }, { "cell_type": "markdown", "metadata": { "id": "TUGNxhBOIuYe" }, "source": [ "## Model and Training" ] }, { "cell_type": "markdown", "metadata": { "id": "v1pz24blIwnR" }, "source": [ "Finally, let's define a standard GCN to train on the Cora dataset. The aim is to train a model that gets better at predicting the class of the node." ] }, { "cell_type": "markdown", "metadata": { "id": "dhdMehneI2bn" }, "source": [ "To keep thins simple we will use the same model definition as used in the [tutorial](https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html) we adpated the code from. Note that we are using the built-in `GCNConv` model but you could easily implement your own (something we will cover in a future tutorial). \n", "\n", "The model below uses two `GCNConv` layers. The first layer is followed by a non-linearity `ReLU` and `Dropout`. The result is fed to the second layer on top of which we apply `Softmax` to get distribution over the number of classes." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "q0AiwyWrJGhj" }, "outputs": [], "source": [ "import torch.nn.functional as F\n", "from torch_geometric.nn import GCNConv\n", "\n", "class GCN(torch.nn.Module):\n", " def __init__(self):\n", " super().__init__()\n", " \"\"\" GCNConv layers \"\"\"\n", " self.conv1 = GCNConv(data.num_features, 16)\n", " self.conv2 = GCNConv(16, dataset.num_classes)\n", "\n", " def forward(self, data):\n", " x, edge_index = data.x, data.edge_index\n", " x = self.conv1(x, edge_index)\n", " x = F.relu(x)\n", " x = F.dropout(x, training=self.training)\n", " x = self.conv2(x, edge_index)\n", "\n", " return F.log_softmax(x, dim=1)" ] }, { "cell_type": "markdown", "metadata": { "id": "Mfob8LS2KezY" }, "source": [ "Initial model and optimizer" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "GSZL4HS5Kd55" }, "outputs": [], "source": [ "model = GCN().to(device)\n", "optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)" ] }, { "cell_type": "markdown", "metadata": { "id": "qpgxKMhmKitV" }, "source": [ "Define axcuracy function for evaluating performance:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "abnE-XTmKl92" }, "outputs": [], "source": [ "# useful function for computing accuracy\n", "def compute_accuracy(pred_y, y):\n", " return (pred_y == y).sum()" ] }, { "cell_type": "markdown", "metadata": { "id": "26W7sxVsKrGM" }, "source": [ "And finally we train the model on the trainin nodes for 200 epochs:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "m39ZbE6RKyim", "outputId": "2e7a3a02-e654-4c11-9c50-d40eab4e6c45" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch: 10, Loss: 0.8235, Training Acc: 0.9357\n", "Epoch: 20, Loss: 0.2665, Training Acc: 0.9786\n", "Epoch: 30, Loss: 0.1056, Training Acc: 0.9857\n", "Epoch: 40, Loss: 0.0583, Training Acc: 1.0000\n", "Epoch: 50, Loss: 0.0461, Training Acc: 1.0000\n", "Epoch: 60, Loss: 0.0388, Training Acc: 0.9929\n", "Epoch: 70, Loss: 0.0406, Training Acc: 1.0000\n", "Epoch: 80, Loss: 0.0447, Training Acc: 1.0000\n", "Epoch: 90, Loss: 0.0571, Training Acc: 0.9929\n", "Epoch: 100, Loss: 0.0304, Training Acc: 1.0000\n", "Epoch: 110, Loss: 0.0373, Training Acc: 1.0000\n", "Epoch: 120, Loss: 0.0268, Training Acc: 1.0000\n", "Epoch: 130, Loss: 0.0504, Training Acc: 0.9857\n", "Epoch: 140, Loss: 0.0245, Training Acc: 1.0000\n", "Epoch: 150, Loss: 0.0294, Training Acc: 1.0000\n", "Epoch: 160, Loss: 0.0378, Training Acc: 0.9929\n", "Epoch: 170, Loss: 0.0441, Training Acc: 1.0000\n", "Epoch: 180, Loss: 0.0223, Training Acc: 1.0000\n", "Epoch: 190, Loss: 0.0370, Training Acc: 0.9929\n", "Epoch: 200, Loss: 0.0224, Training Acc: 1.0000\n" ] } ], "source": [ "# train the model\n", "model.train()\n", "losses = []\n", "accuracies = []\n", "for epoch in range(200):\n", " optimizer.zero_grad()\n", " out = model(data)\n", "\n", " loss = F.nll_loss(out[data.train_mask], data.y[data.train_mask])\n", " correct = compute_accuracy(out.argmax(dim=1)[data.train_mask], data.y[data.train_mask])\n", " acc = int(correct) / int(data.train_mask.sum())\n", " losses.append(loss.item())\n", " accuracies.append(acc)\n", "\n", " loss.backward()\n", " optimizer.step()\n", " if (epoch+1) % 10 == 0:\n", " print('Epoch: {}, Loss: {:.4f}, Training Acc: {:.4f}'.format(epoch+1, loss.item(), acc))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 265 }, "id": "bUtwTwemLJGs", "outputId": "d351364f-f04a-4a75-b3b3-80bd517fe569" }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3dd3xUZb748c83kzLpHRIIIaGHEoqhrKjIVRF0FV11xcV63Yuua7nrNvzdu67r9uJdV9druXZd0V1srKKuKIqolCBNCCXUJCQkJKTXyTy/P84kDJCQSTJpM9/365VXZk79njNnvueZ5zznPGKMQSmllO8K6OsAlFJK9SxN9Eop5eM00SullI/TRK+UUj5OE71SSvm4wL4OoC0JCQkmLS2tr8NQSqkBY9OmTceMMYltjeuXiT4tLY3s7Oy+DkMppQYMETnU3jitulFKKR/XYaIXkWEislpEdorIDhG5p41pREQeEZFcEdkmItPcxt0kIntdfzd5ewOUUkqdmSdVNw7gh8aYr0QkEtgkIh8aY3a6TbMAGO36mwk8DswUkT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GYLV42ArsaNlPQDzwEbAXWAXE9UFs4Vgdyke7Dev1fYZ1oikEmrDqQm9tb/9gtYJ4zHXMbQey+iC2XKz625Zj7QnXtFe5PuMtwFfAZb0cV7ufHfBfrn22G1jQm3G5hj8P3H7KtL25v9rLET12nOkjEJRSysf5StWNUkqpdmiiV0opH6eJXimlfJwmeqWU8nGa6JVSysdpoldKKR+niV4ppXzc/werzw3QOTy/pgAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "# plot the loss and accuracy\n", "import matplotlib.pyplot as plt\n", "plt.plot(losses)\n", "plt.plot(accuracies)\n", "plt.legend(['Loss', 'Accuracy'])\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": { "id": "30cq1fmqK-my" }, "source": [ "It looks like the model achieves a very high accuracy and small loss on the training dataset. To see how well it generalizes, let's test on the testing nodes:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "_6Q354OSLVkG", "outputId": "8a86891a-bd2f-4d43-cb4f-d4773c8b6f00" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accuracy: 0.7900\n" ] } ], "source": [ "# evaluate the model on test set\n", "model.eval()\n", "pred = model(data).argmax(dim=1)\n", "correct = compute_accuracy(pred[data.test_mask], data.y[data.test_mask])\n", "acc = int(correct) / int(data.test_mask.sum())\n", "print(f'Accuracy: {acc:.4f}')" ] }, { "cell_type": "markdown", "metadata": { "id": "iwOLBEpgLW3p" }, "source": [ "Very cool! It seems we got a very nice accuracy for the test as well. Our model is doing okay. There are many ways you can go about trying to improve this model, but we will keep that for another time. Hopefully, with this tutorial you got a glimpse of graph data and how to use PyTorch Geometric to train GNNs on a very popular dataset. " ] }, { "cell_type": "markdown", "metadata": { "id": "NapVlc1wH_1Y" }, "source": [ "Note that I haven't tested if this code works with GPUs. I will leave that as an exercise for the learner. " ] }, { "cell_type": "markdown", "metadata": { "id": "ZtRNFO0mL2_b" }, "source": [ "If you are interested in the full tutorial and more examples, visit the [PyTorch Geomtric documentation](https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html) where I adapted the code from. \n", "\n", "Feel free to reach out on [Twitter](https://twitter.com/omarsar0) if you have any further questions." ] } ], "metadata": { "colab": { "name": "Introduction to GNNs with PyTorch Geometric.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 1 }