{"cells": [{"cell_type": "markdown", "id": "b15ebccc", "metadata": {"papermill": {"duration": 0.021786, "end_time": "2025-04-03T19:34:48.860019", "exception": false, "start_time": "2025-04-03T19:34:48.838233", "status": "completed"}, "tags": []}, "source": ["\n", "# Tutorial 12: Meta-Learning - Learning to Learn\n", "\n", "* **Author:** Phillip Lippe\n", "* **License:** CC BY-SA\n", "* **Generated:** 2025-04-03T19:34:42.067657\n", "\n", "In this tutorial, we will discuss algorithms that learn models which can quickly adapt to new classes and/or tasks with few samples.\n", "This area of machine learning is called _Meta-Learning_ aiming at \"learning to learn\".\n", "Learning from very few examples is a natural task for humans. In contrast to current deep learning models, we need to see only a few examples of a police car or firetruck to recognize them in daily traffic.\n", "This is crucial ability since in real-world application, it is rarely the case that the data stays static and does not change over time.\n", "For example, an object detection system for mobile phones trained on data from 2000 will have troubles detecting today's common mobile phones, and thus, needs to adapt to new data without excessive label effort.\n", "The optimization techniques we have discussed so far struggle with this because they only aim at obtaining a good performance on a test set that had similar data.\n", "However, what if the test set has classes that we do not have in the training set?\n", "Or what if we want to test the model on a completely different task?\n", "We will discuss and implement three common Meta-Learning algorithms for such situations.\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/12-meta-learning.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": "3c7e16ba", "metadata": {"papermill": {"duration": 0.015974, "end_time": "2025-04-03T19:34:48.897937", "exception": false, "start_time": "2025-04-03T19:34:48.881963", "status": "completed"}, "tags": []}, "source": ["## Setup\n", "This notebook requires some packages besides pytorch-lightning."]}, {"cell_type": "code", "execution_count": 1, "id": "8a2d3960", "metadata": {"colab": {}, "colab_type": "code", "execution": {"iopub.execute_input": "2025-04-03T19:34:48.924585Z", "iopub.status.busy": "2025-04-03T19:34:48.923867Z", "iopub.status.idle": "2025-04-03T19:34:50.125860Z", "shell.execute_reply": "2025-04-03T19:34:50.124566Z"}, "id": "LfrJLKPFyhsK", "lines_to_next_cell": 0, "papermill": {"duration": 1.218057, "end_time": "2025-04-03T19:34:50.128446", "exception": false, "start_time": "2025-04-03T19:34:48.910389", "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 \"torchmetrics >=1.0,<1.8\" \"tensorboard\" \"scipy\" \"torch >=1.8.1,<2.7\" \"pytorch-lightning >=2.0,<2.6\" \"matplotlib\" \"numpy <3.0\" \"seaborn\" \"torchvision\""]}, {"cell_type": "markdown", "id": "b0ba385a", "metadata": {"papermill": {"duration": 0.020125, "end_time": "2025-04-03T19:34:50.170026", "exception": false, "start_time": "2025-04-03T19:34:50.149901", "status": "completed"}, "tags": []}, "source": ["