diff --git "a/Week15_\353\263\265\354\212\265\352\263\274\354\240\234_\353\260\225\354\230\210\353\202\230.ipynb" "b/Week15_\353\263\265\354\212\265\352\263\274\354\240\234_\353\260\225\354\230\210\353\202\230.ipynb" new file mode 100644 index 0000000..9ecf9c5 --- /dev/null +++ "b/Week15_\353\263\265\354\212\265\352\263\274\354\240\234_\353\260\225\354\230\210\353\202\230.ipynb" @@ -0,0 +1,9247 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4644be45", + "metadata": { + "id": "4644be45" + }, + "source": [ + "# BERT와 ELECTRA 모델 비교 실습\n", + "\n", + "- 이번 복습과제에서는 SST-2 데이터셋을 기반으로 BERT와 ELECTRA 모델을 학습시켜보고 성능과 구조의 차이를 알아보겠습니다.\n", + "- 코드 실행시간이 매우 길 수 있습니다.\n", + " - 최대한 끝까지 실행해보시되, 시간 부족으로 인해 중간에 중지하신 실행 결과를 제출하셔도 괜찮습니다.\n", + " - 제출 이후에는 꼭 끝까지 실행시켜 비교해보시기 바랍니다!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2eSXxqg4a9SF", + "metadata": { + "id": "2eSXxqg4a9SF" + }, + "outputs": [], + "source": [ + "!pip install --upgrade --quiet datasets fsspec huggingface_hub" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "Pe9t4ac76iP8", + "metadata": { + "id": "Pe9t4ac76iP8" + }, + "outputs": [], + "source": [ + "!pip uninstall transformers huggingface-hub -y\n", + "!pip install transformers\n" + ] + }, + { + "cell_type": "markdown", + "id": "4rq77NfBbByn", + "metadata": { + "id": "4rq77NfBbByn" + }, + "source": [ + "---------------\n", + "여기까지만 실행\n", + "---------------\n", + "그 다음, 런타임 > 세션 다시 시작 > 아래 셀부터 실행" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ac52f320", + "metadata": { + "id": "ac52f320" + }, + "outputs": [], + "source": [ + "import torch\n", + "from torch.utils.data import DataLoader\n", + "from transformers import AutoTokenizer, AutoModelForSequenceClassification\n", + "from datasets import load_dataset\n", + "from torch.optim import AdamW\n", + "from tqdm import tqdm" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "393f4136", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "393f4136", + "outputId": "a334045f-0d81-4be2-963f-501fd3f0598c" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Using device: cuda\n" + ] + } + ], + "source": [ + "# batch_size와 epochs를 조정해보세요!\n", + "batch_size = 16\n", + "epochs = 2\n", + "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", + "print(f\"Using device: {device}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "QTVKkGiIflzk", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 615, + "referenced_widgets": [ + "10c02cbc562c4f49bc7a3821d0628f87", + "9112ce4456854e1e840ac32b02c1f81b", + "292ee9a36c814b5cb0ae21fb4040fa7c", + "4916546a079544338e57c8413c8d2026", + "eb3a973cb9584a03825846bf6d39219b", + "45b4b558e0024192ad44654c256b797d", + "7a5bd3548aef439c9cbc4b1a2605241f", + "2fe2b08075454e358cd0812f38c0db00", + "498f0890ffe2475c9440c48d7de08506", + "2d2e6843713b4a9bbfb9428a68e2117a", + "24ef5dce6693456584c1441bfec8daa1", + "560fa346d8d04e12ad202497534b19c0", + "cf1124771e7a4e9c8d2b8d30c5174574", + "f3ac5fad91684defb06a1018c0c2de88", + "4e6431432a78478ea69cfcc644b83e0d", + "92454f7164534960aaaae378f950cea1", + "281b5da80dc4437fa06652c4e51fc779", + "185afb446465459bbebb87556490699a", + "7218525998a84a97ad236cf2a37e978a", + "793033001bc740f0bfa8e14712101535", + "7a4e83f66fd7406585a58089d5ad2099", + "3e865e679ae04f0a8ce6be0276eeb287", + "314e0752ac2b4c09a494ab1a80922ae4", + "b44d3d74d3af4c9b9f296c1c14b62dce", + "a31069da79b14ee584bea77d95d63add", + "adcf26d3f44d45248137e32e77ad2bd5", + "145f466735fc497db783f434f77908d7", + "631c21685182469098ab9489f8239a19", + "bf1e365cd4584c76803f05f5cc21a172", + "cc93ac9323d64fa4a77e697b08d03ac1", + "9a87ee371f4443e48f3bf3011bd04bfb", + "6b27fb230aa24014bf85aba5c2bc731f", + "8262f7b7e76f4d558b25f82a7aadbd76", + "7275a3b45170494d830c05d90dbba5af", + "475e6fb070f743d69246b854a79a5f44", + "8ff907a67cad409d91d5a7c9d0327349", + "1a92916037e24a06a950dfc15695537f", + "c252211cd3634b58bc2985c02f18b858", + "bc1defed96b648f4b4105a98d3cccf9c", + "72e5adfae4844c26a6fb4c7382e7c3be", + "4f779144707f4024a25f8f8a295a5dc5", + "9b951f120ca6496091720fd5951a3fab", + "fae66422a57b4905a3bbec6904a61626", + "a7287d2482cf4fe78f109ae24eec0f34", + "76bec94149b5405da20788ca84afb706", + "432c64eb647e4a2b943a0a7aebcbe3d6", + "55a5102961404228a00913d537bf81ea", + "6c151ae5ed72413dac1af7be762761d5", + "4d241746df714191ae42e2dd943d1345", + "67c96d9417d8455c973d098b4db7f419", + "9d03214957674e03a479daf22c684306", + "4cb10de0ad7141adb1571d16827e729c", + "184fc4ceee3b4083a53e82ea866cd614", + "4cadaaab72494011a692d439943e1382", + "06140e6aebe342479cd299edc3a67a95", + "5e6656a52d4c4805a57f7b61fc5b487e", + "643a695a02de4ff288d4a7736641cc0e", + "49a4e5aee5d54320a8c0a20323de199a", + "30af7f3dc5bd479a92ca2eff940a1b84", + "356ec04c84ca4dee80bc8a3a9642c60c", + "934f6fe3b70d47219741139616945aa2", + "01fa64d3bdc14f23b19644966f989313", + "ad66da6bcc7545acbdbd86f371e9f504", + "74c2b87198464f67a6dfa3d32328345d", + "b81c657e203a424f8f7fef7baa6394c1", + "86b6e272f4ba4f2b95194310cb6bc700", + "65f2d5d60f8a48be8e824fe7ca87dead", + "b5d9ef1f78734191a146eaec320e85db", + "546415cafb0d4604bc87d486e5525bfb", + "24d58f10b6124049b51a137ebd2a7e67", + "4acb1374eeac402eadf79011641f8078", + "d167fc86cf68411ea04987fa517381ae", + "89818e7b5f664b0fb0570a90bb0b0f35", + "98df608650c84a108caa8fa349d11814", + "c69f146f08884177aa31ae83b2ba327f", + "5dabf132e7cb49299ca0f840b6b127bb", + "49bac82e0016468bab4290b4ce314736" + ] + }, + "id": "QTVKkGiIflzk", + "outputId": "2d09f6ef-7f10-4ec5-dc7c-5fbd5da148e1" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: \n", + "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", + "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", + "You will be able to reuse this secret in all of your notebooks.\n", + "Please note that authentication is recommended but still optional to access public models or datasets.\n", + " warnings.warn(\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "README.md: 0.00B [00:00, ?B/s]" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "10c02cbc562c4f49bc7a3821d0628f87" + } + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "data/train-00000-of-00001.parquet: 0%| | 0.00/3.11M [00:00