File size: 3,945 Bytes
abf7d79 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chatbot Development\n",
"\n",
"Use this notebook to load the model and then initialize, update, and test the chatbot."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setup and Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.11.6' requires the ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/usr/local/bin/python3 -m pip install ipykernel -U --user --force-reinstall'"
]
}
],
"source": [
"import torch\n",
"from huggingface_hub import login\n",
"\n",
"\n",
"from model import load_model, save_model\n",
"from chat import SchoolChatbot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"TODO: Add your Hugging Face token\n",
"Options:\n",
"1. Use login() and enter token when prompted\n",
"2. Set environment variable HUGGINGFACE_TOKEN\n",
"3. Pass token directly (not recommended for shared notebooks)\n",
"\"\"\"\n",
"\n",
"# login() # Uncomment this line and add your token\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load model and tokenizer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Load the model using functions from model.py\n",
"Note: This might take a few minutes depending on your hardware\n",
"\"\"\"\n",
"\n",
"model, tokenizer = load_model()\n",
"\n",
"# Test model loading\n",
"print(\"Model loaded:\", type(model))\n",
"print(\"Tokenizer loaded:\", type(tokenizer))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Initialize and test chatbot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Create chatbot instance using chat.py\n",
"\"\"\"\n",
"chatbot = SchoolChatbot(model, tokenizer)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Test out generating some responses from the chatbot\n",
"\"\"\"\n",
"test_questions = [\n",
" \"What schools in Jamaica Plain offer Spanish programs?\",\n",
" \"How do I schedule a tour of the Hernandez School?\"\n",
"]\n",
"\n",
"for question in test_questions:\n",
" print(f\"\\nQuestion: {question}\")\n",
" response = chatbot.get_response(question)\n",
" print(f\"Response: {response}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TODO: Update pre-trained Llama to be a school choice chatbot\n",
"\n",
"This part is up to you! You might want to finetune the model, simply make a really good system prompt, use RAG, provide it boston school choice data somehow, etc. Be creative! You can also feel free to do this in another script and then evaluate the model here."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# If you update the model, you can use the `save_model` function from model.py to save the new model\n",
"save_model(model, tokenizer)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|