{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "widgets": { "application/vnd.jupyter.widget-state+json": { "3e76dac8c62a4bb79bb7cc825b0d7308": { "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_9efa746b2b424004bc2230fd66a0b537", "IPY_MODEL_946eb36eee944b18b39f0a61c9a70fa5", "IPY_MODEL_56ee7c9fa08d4d1789cb77cb7687588e", "IPY_MODEL_f3c4eb920aa0437ab82b9f9cb59a0ad6" ], "layout": "IPY_MODEL_51674165061d45309447c321dd66f973" } }, "40679f08e9a04b40aadf0bb32d5f69fb": { "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_ad2c9b7628aa4352ae14bb267e51e51d", "placeholder": "", "style": "IPY_MODEL_e9eb3dee9b1e44a7af8e98fc7c7f37a4", "value": "
Epoch | \n", "Training Loss | \n", "Validation Loss | \n", "Rouge1 | \n", "Rouge2 | \n", "Rougel | \n", "Rougelsum | \n", "Gen Len | \n", "
---|---|---|---|---|---|---|---|
1 | \n", "No log | \n", "0.874840 | \n", "0.616600 | \n", "0.382700 | \n", "0.505800 | \n", "0.505500 | \n", "77.658300 | \n", "
2 | \n", "No log | \n", "0.877407 | \n", "0.630700 | \n", "0.406400 | \n", "0.530200 | \n", "0.531000 | \n", "77.511100 | \n", "
3 | \n", "0.676100 | \n", "0.906377 | \n", "0.635000 | \n", "0.405200 | \n", "0.530900 | \n", "0.531100 | \n", "76.283300 | \n", "
4 | \n", "0.676100 | \n", "1.038586 | \n", "0.632900 | \n", "0.403800 | \n", "0.526100 | \n", "0.526200 | \n", "78.488900 | \n", "
5 | \n", "0.676100 | \n", "1.099272 | \n", "0.628500 | \n", "0.401600 | \n", "0.523900 | \n", "0.524600 | \n", "77.008300 | \n", "
6 | \n", "0.201600 | \n", "1.202453 | \n", "0.635100 | \n", "0.412600 | \n", "0.535100 | \n", "0.535600 | \n", "76.072200 | \n", "
7 | \n", "0.201600 | \n", "1.239893 | \n", "0.635600 | \n", "0.410800 | \n", "0.536200 | \n", "0.536800 | \n", "78.536100 | \n", "
8 | \n", "0.201600 | \n", "1.263763 | \n", "0.637600 | \n", "0.414300 | \n", "0.538000 | \n", "0.538700 | \n", "76.841700 | \n", "
" ] }, "metadata": {} }, { "output_type": "stream", "name": "stderr", "text": [ "Some non-default generation parameters are set in the model config. These should go into a GenerationConfig file (https://huggingface.co./docs/transformers/generation_strategies#save-a-custom-decoding-strategy-with-your-model) instead. This warning will be raised to an exception in v4.41.\n", "Non-default generation parameters: {'max_length': 142, 'min_length': 56, 'early_stopping': True, 'num_beams': 4, 'length_penalty': 2.0, 'no_repeat_ngram_size': 3, 'forced_bos_token_id': 0, 'forced_eos_token_id': 2}\n", "Some non-default generation parameters are set in the model config. These should go into a GenerationConfig file (https://huggingface.co./docs/transformers/generation_strategies#save-a-custom-decoding-strategy-with-your-model) instead. This warning will be raised to an exception in v4.41.\n", "Non-default generation parameters: {'max_length': 142, 'min_length': 56, 'early_stopping': True, 'num_beams': 4, 'length_penalty': 2.0, 'no_repeat_ngram_size': 3, 'forced_bos_token_id': 0, 'forced_eos_token_id': 2}\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "TrainOutput(global_step=1440, training_loss=0.32941916783650715, metrics={'train_runtime': 2574.9157, 'train_samples_per_second': 4.471, 'train_steps_per_second': 0.559, 'total_flos': 7806107593924608.0, 'train_loss': 0.32941916783650715, 'epoch': 8.0})" ] }, "metadata": {}, "execution_count": 13 } ] }, { "cell_type": "code", "source": [ "trainer.push_to_hub()" ], "metadata": { "id": "5OgdT1JkKOp9", "colab": { "base_uri": "https://localhost:8080/", "height": 202, "referenced_widgets": [ "310b7a68909849bea6409d745fb94843", "2f40e27f15484ffeae83a57c74e34301", "6a912852eecc47ae845ab0ddff36c346", "ae7cf0194e2b4ad1a0035a2dfa7b408f", "f8c2f325ba544f2aa3722c434e61bbef", "b58787b6bbc440f3a9efb245788a791d", "120c952742094fa5b62eed4b40c56087", "5301dea789ac4b739a9192c242823cfc", "ad962689440f4b96a3389e5400c56a14", "66e2c16f658a463daad8ca8a2ba8e4f9", "e74e83b3e87e4fda96d23c66f8599a8f", "92202c99a959409384922775071d3afc", "f8bec101128d4c159becdba32d56c0ac", "db2071df44d34e9fb1178f87bb160e65", "421d86212c4a42969fce51bc62a9520f", "3f8c0c75001c4f38bcbfa77c6b2239d5", "be10e83695144d3082618b49f8ba7d5a", "86cfd6a246e249af935d81bac307826b", "63d87698d53c4a518dceb265c96364c7", "041a45d016f8460193471e2af1e7a134", "1e365511bd93413eb8e6d7593b44bb7e", "d6d65661120f44b9b0482023d3244ab5", "dba0c55bcc4b4c7182bda14c9a5538a7", "025d28cac01c4708ae05abb353969e9b", "35e2abaf5ec54769b5b556065d64e3e5", "1adb838bac074e7abb2e0312e5a43b19", "b2f6d5811f2a46f89d1613d56a7cbe03", "8100a3a4d6a7449fbf07ea05fdf3581f", "8b8f747cd35648848e23254672ebb921", "c75bf857d55a4883b856675544c2ee19", "ca6059d75da2435792121a493b298dd8", "0260d9c200884151a00aa972794febe4", "c4662f9a8af349f7a2c6a6940a6468db" ] }, "outputId": "c623f049-69fc-402d-9c49-b5140276428d" }, "execution_count": 14, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "Some non-default generation parameters are set in the model config. These should go into a GenerationConfig file (https://huggingface.co./docs/transformers/generation_strategies#save-a-custom-decoding-strategy-with-your-model) instead. This warning will be raised to an exception in v4.41.\n", "Non-default generation parameters: {'max_length': 142, 'min_length': 56, 'early_stopping': True, 'num_beams': 4, 'length_penalty': 2.0, 'no_repeat_ngram_size': 3, 'forced_bos_token_id': 0, 'forced_eos_token_id': 2}\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "Upload 2 LFS files: 0%| | 0/2 [00:00, ?it/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "310b7a68909849bea6409d745fb94843" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "model.safetensors: 0%| | 0.00/1.63G [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "92202c99a959409384922775071d3afc" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "events.out.tfevents.1718450841.4441297fbb55.7613.0: 0%| | 0.00/10.9k [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "dba0c55bcc4b4c7182bda14c9a5538a7" } }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co./ahmedmbutt/PTS-Bart-Large-CNN/commit/b9ea22455049729a8466c7c45d60e82b72adfe10', commit_message='End of training', commit_description='', oid='b9ea22455049729a8466c7c45d60e82b72adfe10', pr_url=None, pr_revision=None, pr_num=None)" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 14 } ] }, { "cell_type": "markdown", "source": [ "# Inference" ], "metadata": { "id": "T-qjQUmyy128" } }, { "cell_type": "code", "source": [ "original_text = dataset['test'][0]['Text']\n", "original_text" ], "metadata": { "id": "GtY21x97tIPo", "colab": { "base_uri": "https://localhost:8080/", "height": 87 }, "outputId": "9bb7951c-9b82-4dc8-a71e-a8eb100ead00" }, "execution_count": 15, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "'One step toward changing your beliefs is undergoing a process called disputation. Disputation is meant to teach you life-long skills to help you manage your emotional response and overall mental health. During disputation, your therapist will challenge your irrational beliefs using direct methods. They may question your beliefs head-on, causing you to rethink them, or they could ask you to imagine another point of view that you haven’t considered before. '" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 15 } ] }, { "cell_type": "code", "source": [ "from transformers import pipeline\n", "\n", "summarizer = pipeline(\"summarization\", model=\"PTS-Bart-Large-CNN\")\n", "summarized_text = summarizer(original_text)\n", "summarized_text = summarized_text[0]['summary_text']\n", "summarized_text" ], "metadata": { "id": "ATRAd0FwzIjh", "colab": { "base_uri": "https://localhost:8080/", "height": 107 }, "outputId": "20f7c0d3-0934-44b0-b007-335d5789cc42" }, "execution_count": 16, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "Your max_length is set to 142, but your input_length is only 93. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=46)\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "'Disputation is a process that challenges irrational beliefs by using direct methods and challenging beliefs, teaching life-long skills to manage emotional response and mental health. It involves questioning beliefs head-on or asking for alternative perspectives, challenging irrational beliefs and promoting new perspectives.'" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 16 } ] } ] }