Fine Tuning (OpenAI)
Jupyter Notebook for fine tuning. docker run -p 8888:8888 -v /Users/claudioteixeira/dev/notebooks:/home/jovyan/work jupyter/datascience-notebook:1692788777:0;docker run -p 8888:8888 -v /Users/claudioteixeira/dev/notebooks:/home/jovyan/work jupyter/datascience-notebook
{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "014a72bf-727b-43db-9224-ae58a6beaa2c", "metadata": {}, "outputs": [], "source": [ "import os\n", "import openai\n", "import random" ] }, { "cell_type": "code", "execution_count": 3, "id": "b2967405-9dbe-4525-bf55-c83d363daf20", "metadata": {}, "outputs": [], "source": [ "openai.api_key = "sk-xxx" " ] }, { "cell_type": "code", "execution_count": 5, "id": "2c030511-925e-49e2-8a55-ce4ca912ecdd", "metadata": {}, "outputs": [], "source": [ "# Warning: JSON-L Training File must have at least 10 examples. ⚠️\n", "upload_file = openai.File.create(\n", " file=open("sample-10.jsonl", "rb"),\n", " purpose='fine-tune'\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "7064110d-9305-4d64-8e0e-2c800e3b16b7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " "object": "fine_tuning.job",\n", " "id": "ftjob-puR5H6oaLQHVYaQxgcDvcevO",\n", " "model": "gpt-3.5-turbo-0613",\n", " "created_at": 1697130095,\n", " "finished_at": null,\n", " "fine_tuned_model": null,\n", " "organization_id": "org-nu4FftiyogCFYA5N9Zf54Jc2",\n", " "result_files": [],\n", " "status": "validating_files",\n", " "validation_file": null,\n", " "training_file": "file-JVma6h5zmuGeAYeWKarqziJX",\n", " "hyperparameters": {\n", " "n_epochs": "auto"\n", " },\n", " "trained_tokens": null,\n", " "error": null\n", "}\n" ] } ], "source": [ "# Finte Tune GPT-3.5 Turbo\n", "suffix_name = "S-CX_20230916v2"\n", "\n", "response = openai.FineTuningJob.create(\n", " training_file=upload_file["id"],\n", " #validation_file=validation_file_id,\n", " model="gpt-3.5-turbo-0613",\n", " suffix=suffix_name,\n", ")\n", "\n", "job_id = response["id"]\n", "\n", "print(response)" ] }, { "cell_type": "code", "execution_count": 12, "id": "25376ab7-ab2d-4d97-808d-19c9c20aa44c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'running'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "status = openai.FineTuningJob.list(limit=10)\n", "status["data"][0]["status"]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" } }, "nbformat": 4, "nbformat_minor": 5 }
Created on 11/28/2023