{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "Q-bj6K7Qv4ft" }, "source": [ "# Fine-Tuning a Generative Pretrained Transformer (`GPT`)\n", "\n", "1. Install required libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "OFWjSb_xDWja", "outputId": "bc3f57c5-8af7-4357-e063-a2e85b24856d" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.7/7.7 MB\u001b[0m \u001b[31m63.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m519.6/519.6 kB\u001b[0m \u001b[31m50.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.8/179.8 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m302.0/302.0 kB\u001b[0m \u001b[31m32.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.8/3.8 MB\u001b[0m \u001b[31m97.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m81.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m115.3/115.3 kB\u001b[0m \u001b[31m14.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m194.1/194.1 kB\u001b[0m \u001b[31m23.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m134.8/134.8 kB\u001b[0m \u001b[31m17.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.4/66.4 kB\u001b[0m \u001b[31m8.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.1/53.1 kB\u001b[0m \u001b[31m6.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m295.0/295.0 kB\u001b[0m \u001b[31m31.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hToken will not been saved to git credential helper. Pass `add_to_git_credential=True` if you want to set the git credential as well.\n", "Token is valid (permission: write).\n", "Your token has been saved to /root/.cache/huggingface/token\n", "Login successful\n" ] } ], "source": [ "!pip install transformers datasets codecarbon -q" ] }, { "cell_type": "markdown", "metadata": { "id": "pY6M4fSb8SY6" }, "source": [ "2. Load the data from the hub." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 961, "referenced_widgets": [ "e1af76b5983a4956b9fd748e583fdba2", "0985691b688d4469b8656af65ec6ab16", "4eedb618040e4c1c865e2ccafb7aa0ee", "2634a6ce9ef74596a7c1a3faad79f572", "5a2387f8509a4e2dbb7812b5687cf9c5", "73b6199c9dd2461fbb9953cd415b39c8", "2c1c0827df194609af2e097138abda5c", "ddcd058c884848f9a4295568d9c8710c", "cae0c782070745a8b6b26b6a0b03f7bb", "8ab0193e2c36494290a397b8cbbfe182", "e48c68d1ccc74e569c05969b974f6769", "ac6b7c5dfaec4093a39d4224bfec1bfd", "c0c3d0a2fde5479abdcd26c490b2757d", "8aec0a518bff475fb32affa3f2441fd2", "d0378eb51b804d29b3283ef24a350613", "e9e006669ca94ab5bc216ced1ddd75d3", "50f6c54b525d4d4db68ddd75f39412b6", "aa9f8dc423d9429fba66e5a24d11545c", "7b40d131e1b047f98df54775127d11a1", "994548e2f7124d0696fc0d3c37b93a12", "b75711eea3d74a118e7aeda81afc818a", "11372d95151d4502aa02bb5b1579d8b6", "04c4a2b8b9b24182972cce13b5caf09e", "d53601c46108409c9841f511fde282c2", "15f0e646dd90453e856a35b025fee570", "193ceed11d8c41559e2aa988c2e7a18d", "6af7679c9116425ba52c8aa80ff3d505", "e900cff8e7214d03a2aabbe9ffae51e9", "79b77e18d97946fb8678916b9c3e298c", "ee57d3f9a06a46d0bf9c4d007a5745d6", "e7a1bed142dc4e81859611eef8535934", "59f439dd6921451b8f7fa394dcc24819", "4dc597fbe80c49f98ddf52057cdec411", "0d79fdeb37204e858428a52eeeee447e", "5e78a4b40e5840309d62caa5323fb213", "73e8c6514d044411ab97ba1bd3339d39", "39489d871a364681a323c1ad09ab4ade", "8c1389d91d4b497e9d20dca1515a8955", "554b295ccc8b4fb2b4041616a60d4347", "0aa83f46107041ccac2207bab943bdf3", "8cb6f8df25524d6a87bda4539e3cff9c", "83ac3d041be440a1b3a34d0a0665f890", "684afa14be0c4073b881c89e42e31e06", "873062d9eaea40e69761adcd2d2242c8", "a045e7571a6a4f3e90f3849496ba4650", "b1ceb5a245d045c78b3f725bbae4eec4", "889bbaa0d33d4cc1bbd0a33a5c951b0c", "8f70a7a495e248d2bffd4dce3609e047", "cdb4dfcea9484fe0ad17bcb333e5a0bc", "69a8e3bf36c240f1a77be46f80e199e2", "057587f010ec4039a87e53e8dfcacdb6", "7a823748536b49ae917eb26a4726480c", "951de94db51f497296f91e5e92fd0204", "48411560357947c089521cc946db9cc2", "1e941903817a42f89e4961a8984c5f18", "52ee5d09f4c14bfe906fa38896596697", "e8263d80ec6c498a937dbb28f70c92f4", "ca90a87968d94d68a2a835e0e17b1ecf", "a30275a327f649a9a479ec4fcda3c922", "8d6725747ff84fd3acf718ac4c1c9548", "88868cae4e15442ea417ab0f4201e0bb", "6a1f4841eef54e1db80cfd27aa33efb1", "34c3c8a18b4c4ac4877b26ebb326557f", "567071fff80b4413a313054a3b09fd9b", "9050c64402d2404ab8f7cb28c0438eba", "887a798732534010a2ab6d21b97c3ae5", "465e574fcba6412886bedd2cf3adecb7", "b1bb5c57411943d79d4ddaa7de07e97c", "cc2de836527d4e539804d37dcaa5007b", "1c9fc211fc3947749cf491762ed8f2ca", "88208fdeaad9436bad3b38f38cb31d1a", "4e97368b4fd5489c8b210a8604d53edc", "3986f3c21395480cb93556b9b81113a3", "d0dca8fb82b34e02bbc96dd7f3421f8d", "6ceb5d1e28614f28bcb9b0717a57ce12", "282fbef7c5c64b76ad695e4b17d6ec14", "04f5f94739f940199b6bc6c7d639ba97" ] }, "id": "6shzxz6ExMs-", "outputId": "8c4e692b-a2df-46b7-a9fb-b237025bebf9" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e1af76b5983a4956b9fd748e583fdba2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading readme: 0%| | 0.00/2.81k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ac6b7c5dfaec4093a39d4224bfec1bfd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data files: 0%| | 0/2 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "04c4a2b8b9b24182972cce13b5caf09e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/26.7M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0d79fdeb37204e858428a52eeeee447e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/29.5M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a045e7571a6a4f3e90f3849496ba4650", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Extracting data files: 0%| | 0/2 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "52ee5d09f4c14bfe906fa38896596697", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating english split: 0%| | 0/41815 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "465e574fcba6412886bedd2cf3adecb7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating portuguese split: 0%| | 0/41815 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " | prompt | \n", "completion | \n", "
---|---|---|
0 | \n", "Por que os camelos conseguem sobreviver muito ... | \n", "Os camelos podem sobreviver por longos período... | \n", "
1 | \n", "Por que o celular é ruim para os humanos | \n", "Os telefones celulares como dispositivos tecno... | \n", "
2 | \n", "O que é um polígono? | \n", "Um polígono é uma figura geométrica bidimensio... | \n", "
3 | \n", "Como começo a correr? | \n", "Começar uma rotina de corrida pode ser uma óti... | \n", "
4 | \n", "Quais episódios da quarta temporada de Game of... | \n", "Michelle MacLaren dirigiu dois episódios da 4ª... | \n", "
... | \n", "... | \n", "... | \n", "
41810 | \n", "Como posso ligar para você? | \n", "Você pode me chamar de Aira. Como posso ajudá-... | \n", "
41811 | \n", "Qual é o seu nome de identificação? | \n", "Como inteligência artificial, não tenho nome d... | \n", "
41812 | \n", "Como você é chamado? | \n", "Olá! Meu nome é Aira. Como posso ajudá-lo hoje? | \n", "
41813 | \n", "Como você se apresenta? | \n", "Olá! Eu sou Aira, sua assistente prestativa, r... | \n", "
41814 | \n", "O que devo dizer quando me dirijo a você? | \n", "Ao se dirigir a mim, você pode simplesmente me... | \n", "
41815 rows × 2 columns
\n", "