{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "gpuClass": "standard", "widgets": { "application/vnd.jupyter.widget-state+json": { "3f624c76d7ba4d6b9e67878d3d827b71": { "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_cfb8089dfa044b6fa1c0f535ffea7207", "IPY_MODEL_fb366169837e4b748b25077db3cdd26e", "IPY_MODEL_f4057a4d75c9429a995fd2b760fbc213", "IPY_MODEL_94225739eb9f4d0f8a39f09bee96b47e" ], "layout": "IPY_MODEL_9463d006f06043a8883ede1894f5ec37" } }, "9df7304e64bc4eba81c862c5260d3000": { "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_d66bd6b6088e4455bd8bc4b77b8b2de4", "placeholder": "", "style": "IPY_MODEL_6fa875ce79e24ba88f9d3873799f8e40", "value": "
Step | \n", "Training Loss | \n", "
---|---|
500 | \n", "0.723700 | \n", "
1000 | \n", "0.506900 | \n", "
1500 | \n", "0.382800 | \n", "
2000 | \n", "0.288800 | \n", "
2500 | \n", "0.229000 | \n", "
3000 | \n", "0.199800 | \n", "
3500 | \n", "0.176500 | \n", "
4000 | \n", "0.158800 | \n", "
4500 | \n", "0.147800 | \n", "
5000 | \n", "0.137900 | \n", "
5500 | \n", "0.131300 | \n", "
6000 | \n", "0.122500 | \n", "
6500 | \n", "0.119100 | \n", "
7000 | \n", "0.115000 | \n", "
7500 | \n", "0.109800 | \n", "
8000 | \n", "0.104800 | \n", "
8500 | \n", "0.102600 | \n", "
9000 | \n", "0.099100 | \n", "
9500 | \n", "0.095800 | \n", "
10000 | \n", "0.093900 | \n", "
10500 | \n", "0.090900 | \n", "
11000 | \n", "0.086600 | \n", "
11500 | \n", "0.083600 | \n", "
12000 | \n", "0.082800 | \n", "
12500 | \n", "0.079400 | \n", "
" ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "TrainOutput(global_step=12936, training_loss=0.1753516689670919, metrics={'train_runtime': 6288.4681, 'train_samples_per_second': 8.218, 'train_steps_per_second': 2.057, 'total_flos': 1.1998348622954496e+16, 'train_loss': 0.1753516689670919, 'epoch': 33.0})" ] }, "metadata": {}, "execution_count": 8 } ] }, { "cell_type": "code", "source": [ "# Save the model\n", "trainer.save_model(model_output_path)\n", "\n", "# Save the tokenizer\n", "tokenizer.save_pretrained(model_output_path)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 0 }, "id": "pEl7PMupTVWs", "outputId": "46cbdbe8-7c4a-47d3-c9fc-4e6eb92ff19d" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "('/content/my_trained_models/tokenizer_config.json',\n", " '/content/my_trained_models/special_tokens_map.json',\n", " '/content/my_trained_models/vocab.json',\n", " '/content/my_trained_models/merges.txt',\n", " '/content/my_trained_models/added_tokens.json')" ] }, "metadata": {}, "execution_count": 9 } ] }, { "cell_type": "code", "source": [ "print(\"SAVED MODELS LOCALLY YO!!!!!!\")" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 0 }, "id": "aI1-vpJDc7Sx", "outputId": "4d319aec-cc02-4be7-d356-08e43f13869a" }, "execution_count": 10, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "SAVED MODELS LOCALLY YO!!!!!!\n" ] } ] }, { "cell_type": "code", "source": [ "directory = \"/content/my_data/\" # Replace with the path to your directory containing the files\n", "model_output_path = \"/content/my_trained_models/\"\n", "\n", "model = GPT2LMHeadModel.from_pretrained(model_output_path)\n", "tokenizer = GPT2Tokenizer.from_pretrained(model_output_path)\n" ], "metadata": { "id": "r09pTefOgGPt" }, "execution_count": 11, "outputs": [] }, { "cell_type": "code", "source": [ "\n", "# Test the chatbot\n", "prompt = \"Write a TV show script for the TV show Futurama about Fry getting stuck in a hole.\" # Replace with your desired prompt\n", "# prompt = \"What is bulk metallic glass?\" # Replace with your desired prompt\n", "\n", "response = generate_response(model, tokenizer, prompt, max_length=1000)\n", "print(\"Generated response:\", response)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 0 }, "id": "ybZWymmrlTSk", "outputId": "04b23e45-775e-4c92-ff65-4042a6d72a76" }, "execution_count": 14, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Generated response: Write a TV show script for the TV show Futurama about Fry getting stuck in a hole.\n", " \n", " \n", " \n", " FRY\n", " Yeah, that'd be a timesaver.\n", " \n", " [Cut to: Planet Express: Fry's Bedroom. The crew are asleep.]\n", " \n", " BENDER\n", " Hey, you don't wanna hear about that \n", " trouble with the TV!\n", " \n", " \n", " BENDER\n", " Let's just say it'll put a smile on your \n", " face.\n", " \n", " BENDER\n", " OK, OK, keep your space pants on. I'll \n", " take care of this.\n", " \n", " \n", " [Cut to: Planet Express: Fry's Bedroom. The crew are asleep.]\n", " \n", " BENDER\n", " Alright, OK, I'll be in the escape pod. Hold on to \n", " your helmet.\n", " \n", " [Cut to: Outside Planet Express. The ship lands.]\n", " \n", " [Cut to: Planet Express: Lounge. The crew are sat around the table.]\n", " \n", " BENDER\n", " I know it's boring out there, but I need some \n", " to get away.\n", " \n", " \n", " BENDER\n", " I don't know about any of your previous \n", " previous captains,\n" ] } ] }, { "cell_type": "code", "source": [ "## PUSH THE MODELS TO YOUR HUGGING-FACE.\n", "\n", "model.push_to_hub(repo_id='KingZack/future-futurama-maker')\n", "tokenizer.push_to_hub('KingZack/future-futurama-maker')\n", "\n", "\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 101, "referenced_widgets": [ "a3fbdd7d222943ddaf9bda9ad5bfa5f6", "0799c57bce7d4acdad5bf69c798e422f", "ce81a63e33c041c9a655cebef323ba36", "66ed2d3283c548ed867d816b45254e6a", "2d16cc7b4780420fa17d6f0e2bfdb370", "c358e4bd56504e65b16badf84ef0a0a0", "d05eea349cbd45fe88f284ca44992d5e", "41482fa94f7f41f893522daeff85c0ba", "3be5cf688ba84b21be6f04fd14d541d5", "d91574f400e34ed6b4cd239d9d8f337d", "fa327cb7eb9748bd90556ae760171fab" ] }, "id": "q1hw5WG6wIva", "outputId": "6d50cd27-7fc8-42eb-a2dc-92c8bc424006" }, "execution_count": 15, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "model.safetensors: 0%| | 0.00/1.42G [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "a3fbdd7d222943ddaf9bda9ad5bfa5f6" } }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/KingZack/future-futurama-maker/commit/4f79dd3471035e7a73e4c8a509d1377f085f5dd4', commit_message='Upload tokenizer', commit_description='', oid='4f79dd3471035e7a73e4c8a509d1377f085f5dd4', pr_url=None, pr_revision=None, pr_num=None)" ] }, "metadata": {}, "execution_count": 15 } ] }, { "cell_type": "markdown", "source": [ "### check out the model you made in the offical hub. \n", "--> https://huggingface.co/KingZack/future-futurama-maker" ], "metadata": { "id": "e1KdL1mCdGb7" } }, { "cell_type": "markdown", "source": [ "## Now load it from the hub and test it out." ], "metadata": { "id": "HgNTL4RPdQl2" } }, { "cell_type": "code", "source": [ "# Use a pipeline as a high-level helper\n", "# from transformers import pipeline\n", "\n", "# pipe = pipeline(\"text-generation\", model=\"KingZack/future-futurama-maker\")\n", "\n", "\n", "# Load model directly\n", "from transformers import AutoTokenizer, AutoModelForCausalLM\n", "\n", "tokenizer = AutoTokenizer.from_pretrained(\"KingZack/future-futurama-maker\")\n", "model = AutoModelForCausalLM.from_pretrained(\"KingZack/future-futurama-maker\")" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "aeeab280f5d94b7c8ec2db3c024021d3", "5bbeb3d24696483cb0a8b77c80f58331", "10cb93cc9dd04376ada62211af66169b", "3368dfedbfd94ab0ad52ce7eda66bf65", "a8611a77aa424b3189a9674a2f100f57", "0281d96fb3024ca6a9feac614e88ce55", "30a8422696c24b999ac3ef15dcc9a44c", "8aa2fbe219ea4b2c9a48ebffb8ff8ac6", "602879da2fd54b9c8d3eeab5a9267658", "922382efa15a4286b5364189589209df", "03a3cb72a56f4755af54d8057e8e5c0c" ] }, "id": "4ZnsKeu-78As", "outputId": "8437c13a-dcc3-462b-c9bb-2ef6cf4feba0" }, "execution_count": 16, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Downloading model.safetensors: 0%| | 0.00/1.42G [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "aeeab280f5d94b7c8ec2db3c024021d3" } }, "metadata": {} } ] }, { "cell_type": "code", "source": [ "# Test the chatbot\n", "prompt = 'Write a script for the TV show Futurama about Fry getting stuck in a hole.'\n", "\n", "response = generate_response(model, tokenizer, prompt, max_length=1000)\n", "print(\"Generated response:\", response)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 0 }, "id": "z6i7TsCYmZc8", "outputId": "34b0856a-c473-4732-b61d-2108331ebd0a" }, "execution_count": 17, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Generated response: Write a script for the TV show Futurama about Fry getting stuck in a hole.\n", " \n", " \n", " \n", " FRY\n", " Maybe I should take Fry on the Luna \n", " Rover ride. You get to wear a space \n", " suit and drive around on the surface. \n", " \n", " \n", " [The ride takes Fry and Bender by rocket ship. They open the door \n", " and look around.]\n", " \n", " \n", " LEELA\n", " OK, guys, let's get to work! I'll be \n", " \n", " out in a second.\n", " \n", " \n", " [Cut to: Outside Luna Park. The crew walk across the surface, reading a map.]\n", " \n", " \n", " FARNSWORTH\n", " \n", " OK, guys, let's get to work! I'll be \n", " out in a second.\n", " \n", " [Cut to: Outside Luna Park. The crew walk across the surface, reading a map.]\n", " \n", " FARNSWORTH\n", " OK, guys, let's get to work! I'll be \n", " out in a second. Hurry, before we freeze!\n", " \n", " \n", " [Cut to: Outside Luna Park. The crew walk across the surface, reading a map.]\n", " \n", " [Cut to: Outside Luna Park. The crew walk across the surface, reading a map.]\n", " \n", " [Cut to: Outside Luna Park. The crew walk across the surface, reading a map.]\n", " \n", " FARNSWORTH\n", " I'm sure it'll work!\n", " \n", " \n" ] } ] }, { "cell_type": "code", "source": [], "metadata": { "id": "LQyHvOb-etJm" }, "execution_count": null, "outputs": [] } ] }