{"cells": [{"cell_type": "markdown", "id": "d7d80d1d", "metadata": {"papermill": {"duration": 0.010924, "end_time": "2025-04-03T19:21:54.421357", "exception": false, "start_time": "2025-04-03T19:21:54.410433", "status": "completed"}, "tags": []}, "source": ["\n", "# Tutorial 6: Basics of Graph Neural Networks\n", "\n", "* **Author:** Phillip Lippe\n", "* **License:** CC BY-SA\n", "* **Generated:** 2025-04-03T19:21:47.666045\n", "\n", "In this tutorial, we will discuss the application of neural networks on graphs.\n", "Graph Neural Networks (GNNs) have recently gained increasing popularity in both applications and research,\n", "including domains such as social networks, knowledge graphs, recommender systems, and bioinformatics.\n", "While the theory and math behind GNNs might first seem complicated,\n", "the implementation of those models is quite simple and helps in understanding the methodology.\n", "Therefore, we will discuss the implementation of basic network layers of a GNN,\n", "namely graph convolutions, and attention layers.\n", "Finally, we will apply a GNN on semi-supervised node classification and molecule categorization.\n", "This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.\n", "The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.\n", "\n", "\n", "---\n", "Open in [{height=\"20px\" width=\"117px\"}](https://colab.research.google.com/github/PytorchLightning/lightning-tutorials/blob/publication/.notebooks/course_UvA-DL/06-graph-neural-networks.ipynb)\n", "\n", "Give us a \u2b50 [on Github](https://www.github.com/Lightning-AI/lightning/)\n", "| Check out [the documentation](https://lightning.ai/docs/)\n", "| Join us [on Discord](https://discord.com/invite/tfXFetEZxv)"]}, {"cell_type": "markdown", "id": "2dfb1b05", "metadata": {"papermill": {"duration": 0.009962, "end_time": "2025-04-03T19:21:54.440719", "exception": false, "start_time": "2025-04-03T19:21:54.430757", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "547763be", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2025-04-03T19:21:54.460267Z", "iopub.status.busy": "2025-04-03T19:21:54.459963Z", "iopub.status.idle": "2025-04-03T19:21:55.663186Z", "shell.execute_reply": "2025-04-03T19:21:55.662317Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 1.216165, "end_time": "2025-04-03T19:21:55.666016", "exception": false, "start_time": "2025-04-03T19:21:54.449851", "status": "completed"}, "tags": []}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.\u001b[0m\u001b[33m\r\n", "\u001b[0m"]}, {"name": "stdout", "output_type": "stream", "text": ["\r\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0.1\u001b[0m\r\n", "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\r\n"]}], "source": ["! pip install --quiet \"torch-sparse ==0.6.*\" \"matplotlib\" \"torch >=1.8.1,<2.7\" \"numpy <2.0\" \"torchmetrics >=1.0,<1.8\" \"torch-cluster ==1.6.*\" \"torch ==2.1.2\" \"pytorch-lightning >=2.0,<2.6\" \"seaborn\" \"numpy <3.0\" \"torch-geometric ==2.1.*\" \"torch-spline-conv ==1.2.*\" \"torch-scatter ==2.1.*\" \"torchvision\""]}, {"cell_type": "markdown", "id": "8f04aabe", "metadata": {"papermill": {"duration": 0.015019, "end_time": "2025-04-03T19:21:55.697050", "exception": false, "start_time": "2025-04-03T19:21:55.682031", "status": "completed"}, "tags": []}, "source": ["