{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "gpuType": "T4" }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "code", "source": [ "!pip install transformers" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "6_gaeY1UMPOv", "outputId": "470ea044-c9b1-400e-f322-aafbdbae4aea" }, "execution_count": 9, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (4.31.0)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers) (3.12.2)\n", "Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.16.4)\n", "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (1.22.4)\n", "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers) (23.1)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (6.0.1)\n", "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (2022.10.31)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers) (2.27.1)\n", "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.13.3)\n", "Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.3.1)\n", "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers) (4.65.0)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.14.1->transformers) (2023.6.0)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.14.1->transformers) (4.7.1)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2023.7.22)\n", "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2.0.12)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (3.4)\n" ] } ] }, { "cell_type": "code", "source": [ "!pip install peft" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UkDCPUBOMh-L", "outputId": "0c618ade-6b5b-4500-8063-a51c29880fb4" }, "execution_count": 13, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: peft in /usr/local/lib/python3.10/dist-packages (0.4.0)\n", "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from peft) (1.22.4)\n", "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from peft) (23.1)\n", "Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from peft) (5.9.5)\n", "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from peft) (6.0.1)\n", "Requirement already satisfied: torch>=1.13.0 in /usr/local/lib/python3.10/dist-packages (from peft) (2.0.1+cu118)\n", "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (from peft) (4.31.0)\n", "Requirement already satisfied: accelerate in /usr/local/lib/python3.10/dist-packages (from peft) (0.21.0)\n", "Requirement already satisfied: safetensors in /usr/local/lib/python3.10/dist-packages (from peft) (0.3.1)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (3.12.2)\n", "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (4.7.1)\n", "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (1.11.1)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (3.1)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (3.1.2)\n", "Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.13.0->peft) (2.0.0)\n", "Requirement already satisfied: cmake in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch>=1.13.0->peft) (3.25.2)\n", "Requirement already satisfied: lit in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch>=1.13.0->peft) (16.0.6)\n", "Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in /usr/local/lib/python3.10/dist-packages (from transformers->peft) (0.16.4)\n", "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers->peft) (2022.10.31)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers->peft) (2.27.1)\n", "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers->peft) (0.13.3)\n", "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers->peft) (4.65.0)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.14.1->transformers->peft) (2023.6.0)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch>=1.13.0->peft) (2.1.3)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->peft) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->peft) (2023.7.22)\n", "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->peft) (2.0.12)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->peft) (3.4)\n", "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=1.13.0->peft) (1.3.0)\n" ] } ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "id": "6YOhmSaCMK2M" }, "outputs": [], "source": [ "# from transformers import AutoModelForSeq2SeqLM\n", "# from peft import get_peft_config, get_peft_model, LoraConfig, TaskType\n", "# import torch\n", "# model_name_or_path = \"microsoft/GODEL-v1_1-large-seq2seq\"\n", "# tokenizer_name_or_path = \"microsoft/GODEL-v1_1-large-seq2seq\"" ] }, { "cell_type": "code", "source": [ "from transformers import AutoModelForSeq2SeqLM, AutoTokenizer\n", "\n", "# Replace 'microsoft/GODEL-v1_1-large-seq2seq' with the model name\n", "model_name = 'microsoft/GODEL-v1_1-large-seq2seq'\n", "\n", "# Load the model and tokenizer\n", "model = AutoModelForSeq2SeqLM.from_pretrained(model_name)\n", "tokenizer = AutoTokenizer.from_pretrained(model_name)" ], "metadata": { "id": "r1zRNhfYXN8T" }, "execution_count": 2, "outputs": [] }, { "cell_type": "code", "source": [ "# Output directory\n", "output_dir = \"medbot_model\"\n", "\n", "# Save the model and tokenizer using the standard Hugging Face naming convention\n", "model.save_pretrained(output_dir)\n", "tokenizer.save_pretrained(output_dir)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UjV85bPQXw7P", "outputId": "688d07cb-eddd-4a6a-819e-57efd837324b" }, "execution_count": 15, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "('medbot_model/tokenizer_config.json',\n", " 'medbot_model/special_tokens_map.json',\n", " 'medbot_model/tokenizer.json')" ] }, "metadata": {}, "execution_count": 15 } ] }, { "cell_type": "code", "source": [ "# # peft config\n", "\n", "# peft_config = LoraConfig(\n", "# task_type=TaskType.SEQ_2_SEQ_LM, inference_mode=False, r=6, lora_alpha=16, lora_dropout=0.2\n", "# )" ], "metadata": { "id": "qmIGSnctujOh" }, "execution_count": 12, "outputs": [] }, { "cell_type": "code", "source": [ "# model = get_peft_model(model, peft_config)\n", "# model.print_trainable_parameters()\n", "\n", "# output_dir = \"medbot_model_peft\"\n", "\n", "# model.save_pretrained(output_dir)\n", "# tokenizer.save_pretrained(output_dir)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "RulB42QiMOhi", "outputId": "e8e2d65d-8afa-4095-bf8b-93749e39b785" }, "execution_count": 14, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "trainable params: 1,769,472 || all params: 739,410,944 || trainable%: 0.23930833244469804\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "('medbot_model_peft/tokenizer_config.json',\n", " 'medbot_model_peft/special_tokens_map.json',\n", " 'medbot_model_peft/tokenizer.json')" ] }, "metadata": {}, "execution_count": 14 } ] }, { "cell_type": "code", "source": [ "# ============================== Load Dataset ==========================" ], "metadata": { "id": "Xj4K4WU-NYp8" }, "execution_count": 8, "outputs": [] }, { "cell_type": "code", "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv('/content/drive/MyDrive/Dataset/diseaseDataSetFull2.csv')\n", "df" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 607 }, "id": "Wc8bxpybNgFo", "outputId": "e5e960a5-e460-4b27-ea2f-bfb86dbbb06b" }, "execution_count": 3, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " disease \\\n", "0 Fungal infection \n", "1 Fungal infection \n", "2 Fungal infection \n", "3 Fungal infection \n", "4 Fungal infection \n", "... ... \n", "4915 (vertigo) Paroymsal Positional Vertigo \n", "4916 Acne \n", "4917 Urinary tract infection \n", "4918 Psoriasis \n", "4919 Impetigo \n", "\n", " symptoms \\\n", "0 itching,skin_rash,nodal_skin_eruptions,dischro... \n", "1 skin_rash,nodal_skin_eruptions,dischromic__pat... \n", "2 itching,nodal_skin_eruptions,dischromic__patches \n", "3 itching,skin_rash,dischromic__patches \n", "4 itching,skin_rash,nodal_skin_eruptions \n", "... ... \n", "4915 vomiting,headache,nausea,spinning_movements,lo... \n", "4916 skin_rash,pus_filled_pimples,blackheads,scurring \n", "4917 burning_micturition,bladder_discomfort,foul_sm... \n", "4918 skin_rash,joint_pain,skin_peeling,silver_like_... \n", "4919 skin_rash,high_fever,blister,red_sore_around_n... \n", "\n", " precautions \n", "0 bath twice, use detol or neem in bathing water... \n", "1 bath twice, use detol or neem in bathing water... \n", "2 bath twice, use detol or neem in bathing water... \n", "3 bath twice, use detol or neem in bathing water... \n", "4 bath twice, use detol or neem in bathing water... \n", "... ... \n", "4915 lie down, avoid sudden change in body, avoid a... \n", "4916 bath twice, avoid fatty spicy food, drink plen... \n", "4917 drink plenty of water, increase vitamin c inta... \n", "4918 wash hands with warm soapy water, stop bleedin... \n", "4919 soak affected area in warm water, use antibiot... \n", "\n", "[4920 rows x 3 columns]" ], "text/html": [ "\n", "\n", "
\n", " | disease | \n", "symptoms | \n", "precautions | \n", "
---|---|---|---|
0 | \n", "Fungal infection | \n", "itching,skin_rash,nodal_skin_eruptions,dischro... | \n", "bath twice, use detol or neem in bathing water... | \n", "
1 | \n", "Fungal infection | \n", "skin_rash,nodal_skin_eruptions,dischromic__pat... | \n", "bath twice, use detol or neem in bathing water... | \n", "
2 | \n", "Fungal infection | \n", "itching,nodal_skin_eruptions,dischromic__patches | \n", "bath twice, use detol or neem in bathing water... | \n", "
3 | \n", "Fungal infection | \n", "itching,skin_rash,dischromic__patches | \n", "bath twice, use detol or neem in bathing water... | \n", "
4 | \n", "Fungal infection | \n", "itching,skin_rash,nodal_skin_eruptions | \n", "bath twice, use detol or neem in bathing water... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
4915 | \n", "(vertigo) Paroymsal Positional Vertigo | \n", "vomiting,headache,nausea,spinning_movements,lo... | \n", "lie down, avoid sudden change in body, avoid a... | \n", "
4916 | \n", "Acne | \n", "skin_rash,pus_filled_pimples,blackheads,scurring | \n", "bath twice, avoid fatty spicy food, drink plen... | \n", "
4917 | \n", "Urinary tract infection | \n", "burning_micturition,bladder_discomfort,foul_sm... | \n", "drink plenty of water, increase vitamin c inta... | \n", "
4918 | \n", "Psoriasis | \n", "skin_rash,joint_pain,skin_peeling,silver_like_... | \n", "wash hands with warm soapy water, stop bleedin... | \n", "
4919 | \n", "Impetigo | \n", "skin_rash,high_fever,blister,red_sore_around_n... | \n", "soak affected area in warm water, use antibiot... | \n", "
4920 rows × 3 columns
\n", "