Spaces:
Sleeping
Sleeping
S-MurilloG
commited on
Commit
•
5ebf09b
1
Parent(s):
6c1478d
Fine-tuning completition
Browse files- CARSE_02_FineTuning.ipynb +85 -29
CARSE_02_FineTuning.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -11,7 +11,7 @@
|
|
11 |
},
|
12 |
{
|
13 |
"cell_type": "code",
|
14 |
-
"execution_count":
|
15 |
"metadata": {},
|
16 |
"outputs": [],
|
17 |
"source": [
|
@@ -29,7 +29,7 @@
|
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
-
"execution_count":
|
33 |
"metadata": {},
|
34 |
"outputs": [],
|
35 |
"source": [
|
@@ -39,7 +39,7 @@
|
|
39 |
},
|
40 |
{
|
41 |
"cell_type": "code",
|
42 |
-
"execution_count":
|
43 |
"metadata": {},
|
44 |
"outputs": [],
|
45 |
"source": [
|
@@ -55,7 +55,7 @@
|
|
55 |
},
|
56 |
{
|
57 |
"cell_type": "code",
|
58 |
-
"execution_count":
|
59 |
"metadata": {},
|
60 |
"outputs": [],
|
61 |
"source": [
|
@@ -88,12 +88,12 @@
|
|
88 |
},
|
89 |
{
|
90 |
"cell_type": "code",
|
91 |
-
"execution_count":
|
92 |
"metadata": {},
|
93 |
"outputs": [],
|
94 |
"source": [
|
95 |
"# Llamadas a la función para crear la separación\n",
|
96 |
-
"dividir_training_validation('Training_Data/Training_Prompts.jsonl')"
|
97 |
]
|
98 |
},
|
99 |
{
|
@@ -105,43 +105,55 @@
|
|
105 |
},
|
106 |
{
|
107 |
"cell_type": "code",
|
108 |
-
"execution_count":
|
109 |
"metadata": {},
|
110 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
"source": [
|
112 |
"# Para Training\n",
|
113 |
"upload_train_response = client.files.create(\n",
|
114 |
-
" file=open(\"Training_Data/
|
115 |
" purpose=\"fine-tune\"\n",
|
116 |
")\n",
|
117 |
"\n",
|
118 |
"# Para Validation\n",
|
|
|
119 |
"upload_val_response = client.files.create(\n",
|
120 |
" file=open(\"Training_Data/Training_Prompts_val.jsonl\", \"rb\"),\n",
|
121 |
" purpose=\"fine-tune\"\n",
|
122 |
-
")"
|
|
|
123 |
]
|
124 |
},
|
125 |
{
|
126 |
"cell_type": "code",
|
127 |
-
"execution_count":
|
128 |
"metadata": {},
|
129 |
"outputs": [
|
130 |
{
|
131 |
"name": "stdout",
|
132 |
"output_type": "stream",
|
133 |
"text": [
|
134 |
-
"Training file id:\tfile-
|
135 |
-
"Validation file id:\tfile-3LSttIrULCZUz5a4pXc3Fsk4\n"
|
136 |
]
|
137 |
}
|
138 |
],
|
139 |
"source": [
|
140 |
"train_file_id = upload_train_response.id\n",
|
141 |
-
"val_file_id = upload_val_response.id\n",
|
142 |
"\n",
|
143 |
"print(f'Training file id:\\t{train_file_id}')\n",
|
144 |
-
"print(f'Validation file id:\\t{val_file_id}')"
|
145 |
]
|
146 |
},
|
147 |
{
|
@@ -153,15 +165,15 @@
|
|
153 |
},
|
154 |
{
|
155 |
"cell_type": "code",
|
156 |
-
"execution_count":
|
157 |
"metadata": {},
|
158 |
"outputs": [],
|
159 |
"source": [
|
160 |
"fine_tune_response = client.fine_tuning.jobs.create(\n",
|
161 |
-
" training_file
|
162 |
-
" validation_file
|
163 |
-
" model=\"gpt-3.5-turbo-1106\", \n",
|
164 |
-
" suffix=\"CARSE\",\n",
|
165 |
" hyperparameters={\n",
|
166 |
" \"n_epochs\":5\n",
|
167 |
" }\n",
|
@@ -170,14 +182,14 @@
|
|
170 |
},
|
171 |
{
|
172 |
"cell_type": "code",
|
173 |
-
"execution_count":
|
174 |
"metadata": {},
|
175 |
"outputs": [
|
176 |
{
|
177 |
"name": "stdout",
|
178 |
"output_type": "stream",
|
179 |
"text": [
|
180 |
-
"Fine-tune id:\tftjob-
|
181 |
]
|
182 |
}
|
183 |
],
|
@@ -189,16 +201,16 @@
|
|
189 |
},
|
190 |
{
|
191 |
"cell_type": "code",
|
192 |
-
"execution_count":
|
193 |
"metadata": {},
|
194 |
"outputs": [
|
195 |
{
|
196 |
"data": {
|
197 |
"text/plain": [
|
198 |
-
"FineTuningJob(id='ftjob-
|
199 |
]
|
200 |
},
|
201 |
-
"execution_count":
|
202 |
"metadata": {},
|
203 |
"output_type": "execute_result"
|
204 |
}
|
@@ -210,16 +222,16 @@
|
|
210 |
},
|
211 |
{
|
212 |
"cell_type": "code",
|
213 |
-
"execution_count":
|
214 |
"metadata": {},
|
215 |
"outputs": [
|
216 |
{
|
217 |
"data": {
|
218 |
"text/plain": [
|
219 |
-
"SyncCursorPage[FineTuningJobEvent](data=[FineTuningJobEvent(id='ftevent-
|
220 |
]
|
221 |
},
|
222 |
-
"execution_count":
|
223 |
"metadata": {},
|
224 |
"output_type": "execute_result"
|
225 |
}
|
@@ -229,6 +241,50 @@
|
|
229 |
"client.fine_tuning.jobs.list_events(fine_tuning_job_id=fine_tune_id, limit=10)"
|
230 |
]
|
231 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
{
|
233 |
"cell_type": "code",
|
234 |
"execution_count": null,
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 43,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
11 |
},
|
12 |
{
|
13 |
"cell_type": "code",
|
14 |
+
"execution_count": 44,
|
15 |
"metadata": {},
|
16 |
"outputs": [],
|
17 |
"source": [
|
|
|
29 |
},
|
30 |
{
|
31 |
"cell_type": "code",
|
32 |
+
"execution_count": 45,
|
33 |
"metadata": {},
|
34 |
"outputs": [],
|
35 |
"source": [
|
|
|
39 |
},
|
40 |
{
|
41 |
"cell_type": "code",
|
42 |
+
"execution_count": 46,
|
43 |
"metadata": {},
|
44 |
"outputs": [],
|
45 |
"source": [
|
|
|
55 |
},
|
56 |
{
|
57 |
"cell_type": "code",
|
58 |
+
"execution_count": 47,
|
59 |
"metadata": {},
|
60 |
"outputs": [],
|
61 |
"source": [
|
|
|
88 |
},
|
89 |
{
|
90 |
"cell_type": "code",
|
91 |
+
"execution_count": 48,
|
92 |
"metadata": {},
|
93 |
"outputs": [],
|
94 |
"source": [
|
95 |
"# Llamadas a la función para crear la separación\n",
|
96 |
+
"#dividir_training_validation('Training_Data/Training_Prompts.jsonl')"
|
97 |
]
|
98 |
},
|
99 |
{
|
|
|
105 |
},
|
106 |
{
|
107 |
"cell_type": "code",
|
108 |
+
"execution_count": 49,
|
109 |
"metadata": {},
|
110 |
+
"outputs": [
|
111 |
+
{
|
112 |
+
"data": {
|
113 |
+
"text/plain": [
|
114 |
+
"'\\nupload_val_response = client.files.create(\\n file=open(\"Training_Data/Training_Prompts_val.jsonl\", \"rb\"),\\n purpose=\"fine-tune\"\\n)\\n'"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
"execution_count": 49,
|
118 |
+
"metadata": {},
|
119 |
+
"output_type": "execute_result"
|
120 |
+
}
|
121 |
+
],
|
122 |
"source": [
|
123 |
"# Para Training\n",
|
124 |
"upload_train_response = client.files.create(\n",
|
125 |
+
" file=open(\"Training_Data/Training_Prompts.jsonl\", \"rb\"),\n",
|
126 |
" purpose=\"fine-tune\"\n",
|
127 |
")\n",
|
128 |
"\n",
|
129 |
"# Para Validation\n",
|
130 |
+
"\"\"\"\n",
|
131 |
"upload_val_response = client.files.create(\n",
|
132 |
" file=open(\"Training_Data/Training_Prompts_val.jsonl\", \"rb\"),\n",
|
133 |
" purpose=\"fine-tune\"\n",
|
134 |
+
")\n",
|
135 |
+
"\"\"\""
|
136 |
]
|
137 |
},
|
138 |
{
|
139 |
"cell_type": "code",
|
140 |
+
"execution_count": 51,
|
141 |
"metadata": {},
|
142 |
"outputs": [
|
143 |
{
|
144 |
"name": "stdout",
|
145 |
"output_type": "stream",
|
146 |
"text": [
|
147 |
+
"Training file id:\tfile-exTRUxeCWwPXQRRThzhgWIM3\n"
|
|
|
148 |
]
|
149 |
}
|
150 |
],
|
151 |
"source": [
|
152 |
"train_file_id = upload_train_response.id\n",
|
153 |
+
"#val_file_id = upload_val_response.id\n",
|
154 |
"\n",
|
155 |
"print(f'Training file id:\\t{train_file_id}')\n",
|
156 |
+
"#print(f'Validation file id:\\t{val_file_id}')"
|
157 |
]
|
158 |
},
|
159 |
{
|
|
|
165 |
},
|
166 |
{
|
167 |
"cell_type": "code",
|
168 |
+
"execution_count": 52,
|
169 |
"metadata": {},
|
170 |
"outputs": [],
|
171 |
"source": [
|
172 |
"fine_tune_response = client.fine_tuning.jobs.create(\n",
|
173 |
+
" training_file=train_file_id, \n",
|
174 |
+
" #validation_file=val_file_id,\n",
|
175 |
+
" model=\"ft:gpt-3.5-turbo-1106:personal:carse:8U71tg31\", \n",
|
176 |
+
" #suffix=\"CARSE\",\n",
|
177 |
" hyperparameters={\n",
|
178 |
" \"n_epochs\":5\n",
|
179 |
" }\n",
|
|
|
182 |
},
|
183 |
{
|
184 |
"cell_type": "code",
|
185 |
+
"execution_count": 55,
|
186 |
"metadata": {},
|
187 |
"outputs": [
|
188 |
{
|
189 |
"name": "stdout",
|
190 |
"output_type": "stream",
|
191 |
"text": [
|
192 |
+
"Fine-tune id:\tftjob-Q2icwONwvwSm87GrJwKWz7iC\n"
|
193 |
]
|
194 |
}
|
195 |
],
|
|
|
201 |
},
|
202 |
{
|
203 |
"cell_type": "code",
|
204 |
+
"execution_count": 60,
|
205 |
"metadata": {},
|
206 |
"outputs": [
|
207 |
{
|
208 |
"data": {
|
209 |
"text/plain": [
|
210 |
+
"FineTuningJob(id='ftjob-Q2icwONwvwSm87GrJwKWz7iC', created_at=1702193022, error=None, fine_tuned_model=None, finished_at=None, hyperparameters=Hyperparameters(n_epochs=5, batch_size=2, learning_rate_multiplier=2), model='ft:gpt-3.5-turbo-1106:personal:carse:8U71tg31', object='fine_tuning.job', organization_id='org-IXFDgE8ZZcQzb9yKJmEuFxvC', result_files=[], status='running', trained_tokens=None, training_file='file-exTRUxeCWwPXQRRThzhgWIM3', validation_file=None)"
|
211 |
]
|
212 |
},
|
213 |
+
"execution_count": 60,
|
214 |
"metadata": {},
|
215 |
"output_type": "execute_result"
|
216 |
}
|
|
|
222 |
},
|
223 |
{
|
224 |
"cell_type": "code",
|
225 |
+
"execution_count": 61,
|
226 |
"metadata": {},
|
227 |
"outputs": [
|
228 |
{
|
229 |
"data": {
|
230 |
"text/plain": [
|
231 |
+
"SyncCursorPage[FineTuningJobEvent](data=[FineTuningJobEvent(id='ftevent-croFh7WoWockQEWeBDvXwGiS', created_at=1702194442, level='info', message='Step 701/1875: training loss=1.77', object='fine_tuning.job.event', data={'step': 701, 'train_loss': 1.7663604021072388, 'train_mean_token_accuracy': 0.4166666567325592}, type='metrics'), FineTuningJobEvent(id='ftevent-NP6nA8Xl5wRSbywnScVrjPbo', created_at=1702194263, level='info', message='Step 601/1875: training loss=1.06', object='fine_tuning.job.event', data={'step': 601, 'train_loss': 1.0635706186294556, 'train_mean_token_accuracy': 0.7547169923782349}, type='metrics'), FineTuningJobEvent(id='ftevent-GStfnspE3KFJZcgVJJfwQUym', created_at=1702194085, level='info', message='Step 501/1875: training loss=1.98', object='fine_tuning.job.event', data={'step': 501, 'train_loss': 1.9760814905166626, 'train_mean_token_accuracy': 0.6052631735801697}, type='metrics'), FineTuningJobEvent(id='ftevent-t8KEMvBhN4GpbjolgnF4FhxY', created_at=1702193910, level='info', message='Step 401/1875: training loss=1.30', object='fine_tuning.job.event', data={'step': 401, 'train_loss': 1.2954835891723633, 'train_mean_token_accuracy': 0.6326530575752258}, type='metrics'), FineTuningJobEvent(id='ftevent-DEfvjFzsJGHPY4nec8drnQfw', created_at=1702193733, level='info', message='Step 301/1875: training loss=1.69', object='fine_tuning.job.event', data={'step': 301, 'train_loss': 1.6948037147521973, 'train_mean_token_accuracy': 0.4871794879436493}, type='metrics'), FineTuningJobEvent(id='ftevent-MnFJc3qTZ2EvaBBwzLrDJs9v', created_at=1702193558, level='info', message='Step 201/1875: training loss=2.27', object='fine_tuning.job.event', data={'step': 201, 'train_loss': 2.2718074321746826, 'train_mean_token_accuracy': 0.5102040767669678}, type='metrics'), FineTuningJobEvent(id='ftevent-V3xt82MrAL6jryV0UDcDzW1k', created_at=1702193385, level='info', message='Step 101/1875: training loss=1.79', object='fine_tuning.job.event', data={'step': 101, 'train_loss': 1.7939976453781128, 'train_mean_token_accuracy': 0.5}, type='metrics'), FineTuningJobEvent(id='ftevent-v3izLGiuwF9VcFITMFhqOgWz', created_at=1702193215, level='info', message='Step 1/1875: training loss=1.27', object='fine_tuning.job.event', data={'step': 1, 'train_loss': 1.274328351020813, 'train_mean_token_accuracy': 0.75}, type='metrics'), FineTuningJobEvent(id='ftevent-gjF6biaEA6HFpX4zAnreVR14', created_at=1702193115, level='info', message='Fine-tuning job started', object='fine_tuning.job.event', data=None, type='message'), FineTuningJobEvent(id='ftevent-0nQ0YxnmfiSDDboQZPm9h2nG', created_at=1702193114, level='info', message='Files validated, moving job to queued state', object='fine_tuning.job.event', data={}, type='message')], object='list', has_more=True)"
|
232 |
]
|
233 |
},
|
234 |
+
"execution_count": 61,
|
235 |
"metadata": {},
|
236 |
"output_type": "execute_result"
|
237 |
}
|
|
|
241 |
"client.fine_tuning.jobs.list_events(fine_tuning_job_id=fine_tune_id, limit=10)"
|
242 |
]
|
243 |
},
|
244 |
+
{
|
245 |
+
"cell_type": "markdown",
|
246 |
+
"metadata": {},
|
247 |
+
"source": [
|
248 |
+
"### Probamos modelo aquí"
|
249 |
+
]
|
250 |
+
},
|
251 |
+
{
|
252 |
+
"cell_type": "code",
|
253 |
+
"execution_count": 86,
|
254 |
+
"metadata": {},
|
255 |
+
"outputs": [],
|
256 |
+
"source": [
|
257 |
+
"system_content = \"CARSE es un chatbot que imita el estilo en que Sebas conversa. Fue creado con amor solo para Carmen. Su objetivo es ofrecer una experiencia de chat divertida y familiar que exprese la personalidad, el humor y el amor de Sebas hacia Carmen.\"\n",
|
258 |
+
"\n",
|
259 |
+
"response = client.chat.completions.create(\n",
|
260 |
+
" model=\"ft:gpt-3.5-turbo-1106:personal::8U9RIZTw\",\n",
|
261 |
+
" messages=[\n",
|
262 |
+
" {\"role\": \"system\", \"content\": system_content},\n",
|
263 |
+
" {\"role\": \"user\", \"content\": \"Dime algo bonito\"}\n",
|
264 |
+
" ]\n",
|
265 |
+
")"
|
266 |
+
]
|
267 |
+
},
|
268 |
+
{
|
269 |
+
"cell_type": "code",
|
270 |
+
"execution_count": 87,
|
271 |
+
"metadata": {},
|
272 |
+
"outputs": [
|
273 |
+
{
|
274 |
+
"data": {
|
275 |
+
"text/plain": [
|
276 |
+
"'Hmmmmm mejor no, ve a bañarte JAJAJAJ\\\\nEs broma mi amor, dame chance de llegar y respirar un poco y te digo lo que quieras en casita'"
|
277 |
+
]
|
278 |
+
},
|
279 |
+
"execution_count": 87,
|
280 |
+
"metadata": {},
|
281 |
+
"output_type": "execute_result"
|
282 |
+
}
|
283 |
+
],
|
284 |
+
"source": [
|
285 |
+
"response.choices[0].message.content"
|
286 |
+
]
|
287 |
+
},
|
288 |
{
|
289 |
"cell_type": "code",
|
290 |
"execution_count": null,
|