diff --git "a/finetuneFlanT5.ipynb" "b/finetuneFlanT5.ipynb" new file mode 100644--- /dev/null +++ "b/finetuneFlanT5.ipynb" @@ -0,0 +1,3996 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "machine_shape": "hm", + "gpuType": "A100" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU", + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "d62308b1dd694ee6b5a127b463988e3b": { + "model_module": "@jupyter-widgets/controls", + "model_name": "VBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "VBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "VBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_9080ca59f39f429488ed2d0309d88ce6", + "IPY_MODEL_fb999b3f65b34b03b77aa5eb3d0efd50", + "IPY_MODEL_d8271019ade5452ba72263911fa4a0f9", + "IPY_MODEL_f613196aa7a349a6b64ef54508cd0aa7", + "IPY_MODEL_429ed7787b7143da80bf68a279e14898" + ], + "layout": "IPY_MODEL_3ea6a086b7c44031b4ccc4a91f3d6af6" + } + }, + "9080ca59f39f429488ed2d0309d88ce6": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_4cc52dab960644d2870e557892f86e61", + "placeholder": "", + "style": "IPY_MODEL_4722d29605584fd9ad5312b16758aab9", + "value": "
Epoch | \n", + "Training Loss | \n", + "Validation Loss | \n", + "Rouge1 | \n", + "Rouge2 | \n", + "Rougel | \n", + "Rougelsum | \n", + "Gen Len | \n", + "
---|---|---|---|---|---|---|---|
1 | \n", + "1.439000 | \n", + "1.381694 | \n", + "47.236000 | \n", + "23.568400 | \n", + "39.745000 | \n", + "43.495300 | \n", + "17.134310 | \n", + "
2 | \n", + "1.355200 | \n", + "1.371634 | \n", + "46.913200 | \n", + "23.134100 | \n", + "39.428800 | \n", + "43.234700 | \n", + "17.416361 | \n", + "
3 | \n", + "1.280100 | \n", + "1.370761 | \n", + "47.476000 | \n", + "23.812500 | \n", + "40.079200 | \n", + "43.582600 | \n", + "17.134310 | \n", + "
4 | \n", + "1.231200 | \n", + "1.372878 | \n", + "47.429500 | \n", + "23.850800 | \n", + "40.067500 | \n", + "43.599700 | \n", + "17.203907 | \n", + "
5 | \n", + "1.193500 | \n", + "1.376878 | \n", + "47.378900 | \n", + "23.925500 | \n", + "40.027400 | \n", + "43.725000 | \n", + "17.221001 | \n", + "
"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "TrainOutput(global_step=9210, training_loss=1.3033124296206993, metrics={'train_runtime': 3255.6159, 'train_samples_per_second': 22.626, 'train_steps_per_second': 2.829, 'total_flos': 5.043922658131968e+16, 'train_loss': 1.3033124296206993, 'epoch': 5.0})"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 15
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "trainer.evaluate()"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 211
+ },
+ "id": "xoqs0hXRoj_w",
+ "outputId": "eeb09c6e-cee3-443d-ab99-41af0749a848"
+ },
+ "execution_count": 16,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "╭─────────────────────────────── Traceback (most recent call last) ──────────���─────────────────────╮\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py:261 in │\n",
+ "│ hf_raise_for_status │\n",
+ "│ │\n",
+ "│ 258 │ </Tip> │\n",
+ "│ 259 │ \"\"\" │\n",
+ "│ 260 │ try: │\n",
+ "│ ❱ 261 │ │ response.raise_for_status() │\n",
+ "│ 262 │ except HTTPError as e: │\n",
+ "│ 263 │ │ error_code = response.headers.get(\"X-Error-Code\") │\n",
+ "│ 264 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/requests/models.py:960 in raise_for_status │\n",
+ "│ │\n",
+ "│ 957 │ │ │ http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, rea │\n",
+ "│ 958 │ │ │\n",
+ "│ 959 │ │ if http_error_msg: │\n",
+ "│ ❱ 960 │ │ │ raise HTTPError(http_error_msg, response=self) │\n",
+ "│ 961 │ │\n",
+ "│ 962 │ def close(self): │\n",
+ "│ 963 │ │ \"\"\"Releases the connection back to the pool. Once this method has been │\n",
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\n",
+ "HTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/api/repos/create\n",
+ "\n",
+ "The above exception was the direct cause of the following exception:\n",
+ "\n",
+ "╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py:2308 in create_repo │\n",
+ "│ │\n",
+ "│ 2305 │ │ r = get_session().post(path, headers=headers, json=json) │\n",
+ "│ 2306 │ │ │\n",
+ "│ 2307 │ │ try: │\n",
+ "│ ❱ 2308 │ │ │ hf_raise_for_status(r) │\n",
+ "│ 2309 │ │ except HTTPError as err: │\n",
+ "│ 2310 │ │ │ if exist_ok and err.response.status_code == 409: │\n",
+ "│ 2311 │ │ │ │ # Repo already exists and `exist_ok=True` │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py:303 in │\n",
+ "│ hf_raise_for_status │\n",
+ "│ │\n",
+ "│ 300 │ │ │\n",
+ "│ 301 │ │ # Convert `HTTPError` into a `HfHubHTTPError` to display request information │\n",
+ "│ 302 │ │ # as well (request id and/or server error message) │\n",
+ "│ ❱ 303 │ │ raise HfHubHTTPError(str(e), response=response) from e │\n",
+ "│ 304 │\n",
+ "│ 305 │\n",
+ "│ 306 def _format_error_message(message: str, request_id: Optional[str], server_message: Optio │\n",
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\n",
+ "HfHubHTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/api/repos/create (Request ID: \n",
+ "Root=1-64a9f7dc-08f648210c1658f20642bcba;3e3a5cd7-ea5a-4a1b-b450-a06ae15315ec)\n",
+ "\n",
+ "You don't have the rights to create a model under this namespace\n",
+ "\n",
+ "During handling of the above exception, another exception occurred:\n",
+ "\n",
+ "╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py:261 in │\n",
+ "│ hf_raise_for_status │\n",
+ "│ │\n",
+ "│ 258 │ </Tip> │\n",
+ "│ 259 │ \"\"\" │\n",
+ "│ 260 │ try: │\n",
+ "│ ❱ 261 │ │ response.raise_for_status() │\n",
+ "│ 262 │ except HTTPError as e: │\n",
+ "│ 263 │ │ error_code = response.headers.get(\"X-Error-Code\") │\n",
+ "│ 264 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/requests/models.py:960 in raise_for_status │\n",
+ "│ │\n",
+ "│ 957 │ │ │ http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, rea │\n",
+ "│ 958 │ │ │\n",
+ "│ 959 │ │ if http_error_msg: │\n",
+ "│ ❱ 960 │ │ │ raise HTTPError(http_error_msg, response=self) │\n",
+ "│ 961 │ │\n",
+ "│ 962 │ def close(self): │\n",
+ "│ 963 │ │ \"\"\"Releases the connection back to the pool. Once this method has been │\n",
+ "╰─────────────────────────────────────────────────────────────────────────────────────────���────────╯\n",
+ "HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/api/models/JeffGuo/flan-t5-base-samsum\n",
+ "\n",
+ "The above exception was the direct cause of the following exception:\n",
+ "\n",
+ "╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮\n",
+ "│ in <cell line: 5>:5 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/transformers/trainer.py:3716 in push_to_hub │\n",
+ "│ │\n",
+ "│ 3713 │ │ # If a user calls manually `push_to_hub` with `self.args.push_to_hub = False`, w │\n",
+ "│ 3714 │ │ # it might fail. │\n",
+ "│ 3715 │ │ if not hasattr(self, \"repo\"): │\n",
+ "│ ❱ 3716 │ │ │ self.init_git_repo() │\n",
+ "│ 3717 │ │ │\n",
+ "│ 3718 │ │ model_name = kwargs.pop(\"model_name\", None) │\n",
+ "│ 3719 │ │ if model_name is None and self.args.should_save: │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/transformers/trainer.py:3569 in init_git_repo │\n",
+ "│ │\n",
+ "│ 3566 │ │ │ repo_name = get_full_repo_name(repo_name, token=self.args.hub_token) │\n",
+ "│ 3567 │ │ │\n",
+ "│ 3568 │ │ # Make sure the repo exists. │\n",
+ "│ ❱ 3569 │ │ create_repo(repo_name, token=self.args.hub_token, private=self.args.hub_private_ │\n",
+ "│ 3570 │ │ try: │\n",
+ "│ 3571 │ │ │ self.repo = Repository(self.args.output_dir, clone_from=repo_name, token=sel │\n",
+ "│ 3572 │ │ except EnvironmentError: │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py:118 in _inner_fn │\n",
+ "│ │\n",
+ "│ 115 │ │ if check_use_auth_token: │\n",
+ "│ 116 │ │ │ kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=ha │\n",
+ "│ 117 │ │ │\n",
+ "│ ❱ 118 │ │ return fn(*args, **kwargs) │\n",
+ "│ 119 │ │\n",
+ "│ 120 │ return _inner_fn # type: ignore │\n",
+ "│ 121 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py:2316 in create_repo │\n",
+ "│ │\n",
+ "│ 2313 │ │ │ elif exist_ok and err.response.status_code == 403: │\n",
+ "│ 2314 │ │ │ │ # No write permission on the namespace but repo might already exist │\n",
+ "│ 2315 │ │ │ │ try: │\n",
+ "│ ❱ 2316 │ │ │ │ │ self.repo_info(repo_id=repo_id, repo_type=repo_type, token=token) │\n",
+ "│ 2317 │ │ │ │ │ if repo_type is None or repo_type == REPO_TYPE_MODEL: │\n",
+ "│ 2318 │ │ │ │ │ │ return RepoUrl(f\"{self.endpoint}/{repo_id}\") │\n",
+ "│ 2319 │ │ │ │ │ return RepoUrl(f\"{self.endpoint}/{repo_type}/{repo_id}\") │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py:118 in _inner_fn │\n",
+ "│ │\n",
+ "│ 115 │ │ if check_use_auth_token: │\n",
+ "│ 116 │ │ │ kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=ha │\n",
+ "│ 117 │ │ │\n",
+ "│ ❱ 118 │ │ return fn(*args, **kwargs) │\n",
+ "│ 119 │ │\n",
+ "│ 120 │ return _inner_fn # type: ignore │\n",
+ "│ 121 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py:1868 in repo_info │\n",
+ "│ │\n",
+ "│ 1865 │ │ │ method = self.space_info # type: ignore │\n",
+ "│ 1866 │ │ else: │\n",
+ "│ 1867 │ │ │ raise ValueError(\"Unsupported repo type.\") │\n",
+ "│ ❱ 1868 │ │ return method( │\n",
+ "│ 1869 │ │ │ repo_id, │\n",
+ "│ 1870 │ │ │ revision=revision, │\n",
+ "│ 1871 │ │ │ token=token, │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py:118 in _inner_fn │\n",
+ "│ │\n",
+ "│ 115 │ │ if check_use_auth_token: │\n",
+ "│ 116 │ │ │ kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=ha │\n",
+ "│ 117 │ │ │\n",
+ "│ ❱ 118 │ │ return fn(*args, **kwargs) │\n",
+ "│ 119 │ │\n",
+ "│ 120 │ return _inner_fn # type: ignore │\n",
+ "│ 121 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/hf_api.py:1678 in model_info │\n",
+ "│ │\n",
+ "│ 1675 │ │ if files_metadata: │\n",
+ "│ 1676 │ │ │ params[\"blobs\"] = True │\n",
+ "│ 1677 │ │ r = get_session().get(path, headers=headers, timeout=timeout, params=params) │\n",
+ "│ ❱ 1678 │ │ hf_raise_for_status(r) │\n",
+ "│ 1679 │ │ d = r.json() │\n",
+ "│ 1680 │ │ return ModelInfo(**d) │\n",
+ "│ 1681 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py:293 in │\n",
+ "│ hf_raise_for_status │\n",
+ "│ │\n",
+ "│ 290 │ │ │ │ \" `repo_type`.\\nIf you are trying to access a private or gated repo,\" │\n",
+ "│ 291 │ │ │ │ \" make sure you are authenticated.\" │\n",
+ "│ 292 │ │ │ ) │\n",
+ "│ ❱ 293 │ │ │ raise RepositoryNotFoundError(message, response) from e │\n",
+ "│ 294 │ │ │\n",
+ "│ 295 │ │ elif response.status_code == 400: │\n",
+ "│ 296 │ │ │ message = ( │\n",
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\n",
+ "RepositoryNotFoundError: 404 Client Error. (Request ID: \n",
+ "Root=1-64a9f7dd-665988123c3b7a88361ad5a9;8254f7f7-f061-405e-aa6b-5911f96d65dc)\n",
+ "\n",
+ "Repository Not Found for url: https://huggingface.co/api/models/JeffGuo/flan-t5-base-samsum.\n",
+ "Please make sure you specified the correct `repo_id` and `repo_type`.\n",
+ "If you are trying to access a private or gated repo, make sure you are authenticated.\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "from transformers import pipeline\n",
+ "from random import randrange\n",
+ "\n",
+ "# load model and tokenizer from huggingface hub with pipeline\n",
+ "summarizer = pipeline(\"summarization\", model=\"/content/flan-t5-base-samsum/checkpoint-5526\", device=0)\n",
+ "#summarizer = pipeline(\"summarization\", model=\"/content/flan-t5-base-samsum/checkpoint-5526/content/t5-small-finetuned-xsum/checkpoint-12500\", device=0)\n",
+ "\n",
+ "# select a random test sample\n",
+ "sample = dataset['test'][randrange(len(dataset[\"test\"]))]\n",
+ "print(f\"dialogue: \\n{sample['dialogue']}\\n---------------\")\n",
+ "\n",
+ "# summarize dialogue\n",
+ "res = summarizer(sample[\"dialogue\"])\n",
+ "\n",
+ "print(f\"flan-t5-base summary:\\n{res[0]['summary_text']}\")"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 666
+ },
+ "id": "kcsZspp_ovD3",
+ "outputId": "aea9b08c-16ca-40bf-f944-2639f784ec15"
+ },
+ "execution_count": 29,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "\u001b[31m╭─\u001b[0m\u001b[31m──────────────────────────────\u001b[0m\u001b[31m \u001b[0m\u001b[1;31mTraceback \u001b[0m\u001b[1;2;31m(most recent call last)\u001b[0m\u001b[31m \u001b[0m\u001b[31m─────────────────���─────────────\u001b[0m\u001b[31m─╮\u001b[0m\n",
+ "\u001b[31m│\u001b[0m in \u001b[92m╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮\n",
+ "│ in <cell line: 5>:5 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/transformers/pipelines/__init__.py:885 in pipeline │\n",
+ "│ │\n",
+ "│ 882 │ │ │ │ tokenizer_kwargs = model_kwargs.copy() │\n",
+ "│ 883 │ │ │ │ tokenizer_kwargs.pop(\"torch_dtype\", None) │\n",
+ "│ 884 │ │ │ │\n",
+ "│ ❱ 885 │ │ │ tokenizer = AutoTokenizer.from_pretrained( │\n",
+ "│ 886 │ │ │ │ tokenizer_identifier, use_fast=use_fast, _from_pipeline=task, **hub_kwar │\n",
+ "│ 887 │ │ │ ) │\n",
+ "│ 888 │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/transformers/models/auto/tokenization_auto.py:709 in │\n",
+ "│ from_pretrained │\n",
+ "│ │\n",
+ "│ 706 │ │ if model_type is not None: │\n",
+ "│ 707 │ │ │ tokenizer_class_py, tokenizer_class_fast = TOKENIZER_MAPPING[type(config)] │\n",
+ "│ 708 │ │ │ if tokenizer_class_fast and (use_fast or tokenizer_class_py is None): │\n",
+ "│ ❱ 709 │ │ │ │ return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_pat │\n",
+ "│ 710 │ │ │ else: │\n",
+ "│ 711 │ │ │ │ if tokenizer_class_py is not None: │\n",
+ "│ 712 │ │ │ │ │ return tokenizer_class_py.from_pretrained(pretrained_model_name_or_p │\n",
+ "│ │\n",
+ "│ /usr/local/lib/python3.10/dist-packages/transformers/tokenization_utils_base.py:1809 in │\n",
+ "│ from_pretrained │\n",
+ "│ │\n",
+ "│ 1806 │ │ │ ) │\n",
+ "│ 1807 │ │ │\n",
+ "│ 1808 │ │ if all(full_file_name is None for full_file_name in resolved_vocab_files.values( │\n",
+ "│ ❱ 1809 │ │ │ raise EnvironmentError( │\n",
+ "│ 1810 │ │ │ │ f\"Can't load tokenizer for '{pretrained_model_name_or_path}'. If you wer │\n",
+ "│ 1811 │ │ │ │ \"'https://huggingface.co/models', make sure you don't have a local direc │\n",
+ "│ 1812 │ │ │ │ f\"Otherwise, make sure '{pretrained_model_name_or_path}' is the correct │\n",
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯\n",
+ "OSError: Can't load tokenizer for '/content/flan-t5-base-samsum/checkpoint-5526'. If you were trying to load it \n",
+ "from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, \n",
+ "make sure '/content/flan-t5-base-samsum/checkpoint-5526' is the correct path to a directory containing all relevant\n",
+ "files for a T5TokenizerFast tokenizer.\n",
+ "
\n"
+ ]
+ },
+ "metadata": {}
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file