File size: 35,441 Bytes
4f3e1b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9524095d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (2.3.0)\n",
      "Requirement already satisfied: numpy in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (2.3.1)\n",
      "Requirement already satisfied: matplotlib in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (3.10.3)\n",
      "Requirement already satisfied: seaborn in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (0.13.2)\n",
      "Requirement already satisfied: datasets in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (3.6.0)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from pandas) (2.9.0.post0)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from pandas) (2025.2)\n",
      "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from pandas) (2025.2)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (1.3.2)\n",
      "Requirement already satisfied: cycler>=0.10 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (0.12.1)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (4.58.4)\n",
      "Requirement already satisfied: kiwisolver>=1.3.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (1.4.8)\n",
      "Requirement already satisfied: packaging>=20.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (25.0)\n",
      "Requirement already satisfied: pillow>=8 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (11.2.1)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from matplotlib) (3.2.3)\n",
      "Requirement already satisfied: filelock in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (3.18.0)\n",
      "Requirement already satisfied: pyarrow>=15.0.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (20.0.0)\n",
      "Requirement already satisfied: dill<0.3.9,>=0.3.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (0.3.8)\n",
      "Requirement already satisfied: requests>=2.32.2 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (2.32.4)\n",
      "Requirement already satisfied: tqdm>=4.66.3 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (4.67.1)\n",
      "Requirement already satisfied: xxhash in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (3.5.0)\n",
      "Requirement already satisfied: multiprocess<0.70.17 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (0.70.16)\n",
      "Requirement already satisfied: fsspec<=2025.3.0,>=2023.1.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (2025.3.0)\n",
      "Requirement already satisfied: huggingface-hub>=0.24.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (0.33.1)\n",
      "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from datasets) (6.0.2)\n",
      "Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (3.12.13)\n",
      "Requirement already satisfied: aiohappyeyeballs>=2.5.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (2.6.1)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.3.2)\n",
      "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (25.3.0)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.7.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (6.6.0)\n",
      "Requirement already satisfied: propcache>=0.2.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (0.3.2)\n",
      "Requirement already satisfied: yarl<2.0,>=1.17.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.20.1)\n",
      "Requirement already satisfied: idna>=2.0 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from yarl<2.0,>=1.17.0->aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (3.10)\n",
      "Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from huggingface-hub>=0.24.0->datasets) (4.14.0)\n",
      "Requirement already satisfied: six>=1.5 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n",
      "Requirement already satisfied: charset_normalizer<4,>=2 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from requests>=2.32.2->datasets) (3.4.2)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from requests>=2.32.2->datasets) (2.5.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from requests>=2.32.2->datasets) (2025.6.15)\n",
      "Requirement already satisfied: colorama in c:\\users\\a.s.ivanov\\pycharmprojects\\1c_coder\\.venv\\lib\\site-packages (from tqdm>=4.66.3->datasets) (0.4.6)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\a.s.ivanov\\PycharmProjects\\1C_CODER\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "%pip install pandas numpy matplotlib seaborn datasets\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import datasets\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a889b205",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source</th>\n",
       "      <th>in_source_id</th>\n",
       "      <th>prompt</th>\n",
       "      <th>think_process</th>\n",
       "      <th>solution</th>\n",
       "      <th>is_answer_a_link</th>\n",
       "      <th>has_link</th>\n",
       "      <th>tags_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328184</td>\n",
       "      <td>Здравствуйте. УНФ, есть запрос\\n\\n```1c\\n    \"...</td>\n",
       "      <td>&lt;think&gt;\\nЗдравствуйте. УНФ, есть запрос\\n\\n```...</td>\n",
       "      <td># Код Реализации\\n```1c\\n    ВЫБРАТЬ\\n    Това...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>УТ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328235</td>\n",
       "      <td>Задача простая. Необходимо заполнить документ ...</td>\n",
       "      <td>&lt;think&gt;\\nЗадача простая. Необходимо заполнить ...</td>\n",
       "      <td>Для РН можно получить только весь набор регист...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic327650</td>\n",
       "      <td>Доброго времени суток.\\nПосле обновления УТ на...</td>\n",
       "      <td>&lt;think&gt;\\nДоброго времени суток.\\nПосле обновле...</td>\n",
       "      <td>Может кому пригодится в последнем релизе не уд...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ERP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328246</td>\n",
       "      <td>Здравствуйте, столкнулся с такой проблемой. Пр...</td>\n",
       "      <td>&lt;think&gt;\\nЗдравствуйте, столкнулся с такой проб...</td>\n",
       "      <td>Если оплата кредита, тогда без НДС.</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Бухгалтерия</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328236</td>\n",
       "      <td>Доброго дня всем!\\n\\nСохраняю данные Таблицы з...</td>\n",
       "      <td>&lt;think&gt;\\nДоброго дня всем!\\n\\nСохраняю данные ...</td>\n",
       "      <td>Да зачем все эти построители-шмостроители для ...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            source in_source_id  \\\n",
       "0  forum_infostart  topic328184   \n",
       "1  forum_infostart  topic328235   \n",
       "2  forum_infostart  topic327650   \n",
       "3  forum_infostart  topic328246   \n",
       "4  forum_infostart  topic328236   \n",
       "\n",
       "                                              prompt  \\\n",
       "0  Здравствуйте. УНФ, есть запрос\\n\\n```1c\\n    \"...   \n",
       "1  Задача простая. Необходимо заполнить документ ...   \n",
       "2  Доброго времени суток.\\nПосле обновления УТ на...   \n",
       "3  Здравствуйте, столкнулся с такой проблемой. Пр...   \n",
       "4  Доброго дня всем!\\n\\nСохраняю данные Таблицы з...   \n",
       "\n",
       "                                       think_process  \\\n",
       "0  <think>\\nЗдравствуйте. УНФ, есть запрос\\n\\n```...   \n",
       "1  <think>\\nЗадача простая. Необходимо заполнить ...   \n",
       "2  <think>\\nДоброго времени суток.\\nПосле обновле...   \n",
       "3  <think>\\nЗдравствуйте, столкнулся с такой проб...   \n",
       "4  <think>\\nДоброго дня всем!\\n\\nСохраняю данные ...   \n",
       "\n",
       "                                            solution  is_answer_a_link  \\\n",
       "0  # Код Реализации\\n```1c\\n    ВЫБРАТЬ\\n    Това...             False   \n",
       "1  Для РН можно получить только весь набор регист...             False   \n",
       "2  Может кому пригодится в последнем релизе не уд...             False   \n",
       "3                Если оплата кредита, тогда без НДС.             False   \n",
       "4  Да зачем все эти построители-шмостроители для ...             False   \n",
       "\n",
       "   has_link tags_service  \n",
       "0       NaN           УТ  \n",
       "1       NaN          NaN  \n",
       "2       NaN          ERP  \n",
       "3       NaN  Бухгалтерия  \n",
       "4       NaN          NaN  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_think = pd.read_csv('result_forums_infostart_WITH_CODE.csv')\n",
    "df_think.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6078c4af",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_regular = pd.read_csv('result_forums_fastcode.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "aa0275f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source</th>\n",
       "      <th>in_source_id</th>\n",
       "      <th>prompt</th>\n",
       "      <th>think_process</th>\n",
       "      <th>solution</th>\n",
       "      <th>is_answer_a_link</th>\n",
       "      <th>has_link</th>\n",
       "      <th>tags_service</th>\n",
       "      <th>tags</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328184</td>\n",
       "      <td>Здравствуйте. УНФ, есть запрос\\n\\n```1c\\n    \"...</td>\n",
       "      <td>&lt;think&gt;\\nЗдравствуйте. УНФ, есть запрос\\n\\n```...</td>\n",
       "      <td># Код Реализации\\n```1c\\n    ВЫБРАТЬ\\n    Това...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>УТ</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328235</td>\n",
       "      <td>Задача простая. Необходимо заполнить документ ...</td>\n",
       "      <td>&lt;think&gt;\\nЗадача простая. Необходимо заполнить ...</td>\n",
       "      <td>Для РН можно получить только весь набор регист...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic327650</td>\n",
       "      <td>Доброго времени суток.\\nПосле обновления УТ на...</td>\n",
       "      <td>&lt;think&gt;\\nДоброго времени суток.\\nПосле обновле...</td>\n",
       "      <td>Может кому пригодится в последнем релизе не уд...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ERP</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328246</td>\n",
       "      <td>Здравствуйте, столкнулся с такой проблемой. Пр...</td>\n",
       "      <td>&lt;think&gt;\\nЗдравствуйте, столкнулся с такой проб...</td>\n",
       "      <td>Если оплата кредита, тогда без НДС.</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Бухгалтерия</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>forum_infostart</td>\n",
       "      <td>topic328236</td>\n",
       "      <td>Доброго дня всем!\\n\\nСохраняю данные Таблицы з...</td>\n",
       "      <td>&lt;think&gt;\\nДоброго дня всем!\\n\\nСохраняю данные ...</td>\n",
       "      <td>Да зачем все эти построители-шмостроители для ...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19036</th>\n",
       "      <td>fastcode_Templates</td>\n",
       "      <td>13</td>\n",
       "      <td>ЗаполнитьМассивУникальнымиЗначениями</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Заполняет массив-приемник уникальными значения...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ЗУП</td>\n",
       "      <td>1С,Коллекции</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19037</th>\n",
       "      <td>fastcode_Templates</td>\n",
       "      <td>12</td>\n",
       "      <td>ДобавитьИтераторТаблице</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Добавляет колонку в таблицу значений. Заполняе...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1С</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19038</th>\n",
       "      <td>fastcode_Templates</td>\n",
       "      <td>7</td>\n",
       "      <td>ТаблицаЗначенийВМассив</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Преобразует таблицу значений в массив.\\n\\n# Ко...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>УТ</td>\n",
       "      <td>1С,Коллекции</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19039</th>\n",
       "      <td>fastcode_Templates</td>\n",
       "      <td>5</td>\n",
       "      <td>Получить дату файла</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Функция определяет дату последней модификации ...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Розница</td>\n",
       "      <td>1С,Дата</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19040</th>\n",
       "      <td>fastcode_Templates</td>\n",
       "      <td>4</td>\n",
       "      <td>Получить имя файла</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Составляет полное имя файла из имени каталога ...</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>УТ</td>\n",
       "      <td>1С</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>19041 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   source in_source_id  \\\n",
       "0         forum_infostart  topic328184   \n",
       "1         forum_infostart  topic328235   \n",
       "2         forum_infostart  topic327650   \n",
       "3         forum_infostart  topic328246   \n",
       "4         forum_infostart  topic328236   \n",
       "...                   ...          ...   \n",
       "19036  fastcode_Templates           13   \n",
       "19037  fastcode_Templates           12   \n",
       "19038  fastcode_Templates            7   \n",
       "19039  fastcode_Templates            5   \n",
       "19040  fastcode_Templates            4   \n",
       "\n",
       "                                                  prompt  \\\n",
       "0      Здравствуйте. УНФ, есть запрос\\n\\n```1c\\n    \"...   \n",
       "1      Задача простая. Необходимо заполнить документ ...   \n",
       "2      Доброго времени суток.\\nПосле обновления УТ на...   \n",
       "3      Здравствуйте, столкнулся с такой проблемой. Пр...   \n",
       "4      Доброго дня всем!\\n\\nСохраняю данные Таблицы з...   \n",
       "...                                                  ...   \n",
       "19036               ЗаполнитьМассивУникальнымиЗначениями   \n",
       "19037                            ДобавитьИтераторТаблице   \n",
       "19038                             ТаблицаЗначенийВМассив   \n",
       "19039                                Получить дату файла   \n",
       "19040                                 Получить имя файла   \n",
       "\n",
       "                                           think_process  \\\n",
       "0      <think>\\nЗдравствуйте. УНФ, есть запрос\\n\\n```...   \n",
       "1      <think>\\nЗадача простая. Необходимо заполнить ...   \n",
       "2      <think>\\nДоброго времени суток.\\nПосле обновле...   \n",
       "3      <think>\\nЗдравствуйте, столкнулся с такой проб...   \n",
       "4      <think>\\nДоброго дня всем!\\n\\nСохраняю данные ...   \n",
       "...                                                  ...   \n",
       "19036                                                NaN   \n",
       "19037                                                NaN   \n",
       "19038                                                NaN   \n",
       "19039                                                NaN   \n",
       "19040                                                NaN   \n",
       "\n",
       "                                                solution  is_answer_a_link  \\\n",
       "0      # Код Реализации\\n```1c\\n    ВЫБРАТЬ\\n    Това...             False   \n",
       "1      Для РН можно получить только весь набор регист...             False   \n",
       "2      Может кому пригодится в последнем релизе не уд...             False   \n",
       "3                    Если оплата кредита, тогда без НДС.             False   \n",
       "4      Да зачем все эти построители-шмостроители для ...             False   \n",
       "...                                                  ...               ...   \n",
       "19036  Заполняет массив-приемник уникальными значения...             False   \n",
       "19037  Добавляет колонку в таблицу значений. Заполняе...             False   \n",
       "19038  Преобразует таблицу значений в массив.\\n\\n# Ко...             False   \n",
       "19039  Функция определяет дату последней модификации ...             False   \n",
       "19040  Составляет полное имя файла из имени каталога ...             False   \n",
       "\n",
       "       has_link tags_service          tags  \n",
       "0           NaN           УТ           NaN  \n",
       "1           NaN          NaN           NaN  \n",
       "2           NaN          ERP           NaN  \n",
       "3           NaN  Бухгалтерия           NaN  \n",
       "4           NaN          NaN           NaN  \n",
       "...         ...          ...           ...  \n",
       "19036       NaN          ЗУП  1С,Коллекции  \n",
       "19037       NaN          NaN            1С  \n",
       "19038       NaN           УТ  1С,Коллекции  \n",
       "19039       NaN      Розница       1С,Дата  \n",
       "19040       NaN           УТ            1С  \n",
       "\n",
       "[19041 rows x 9 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_df = pd.concat([df_think, df_regular], ignore_index=True)\n",
    "result_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "41fce790",
   "metadata": {},
   "outputs": [],
   "source": [
    "result_df.drop(columns=['tags_service'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2fd66671",
   "metadata": {},
   "outputs": [],
   "source": [
    "result_df.to_csv('result_parsing_forums.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9788c8b5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd259c4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Make dataset from forums to learn LLM\n",
    "\n",
    "[\n",
    "{\n",
    "\"content\": \"Please summarize the goals for scientists in this text:\\n\\nWithin three days, the intertwined cup nest of grasses was complete, featuring a canopy of overhanging grasses to conceal it. And decades later, it served as Rinkert’s portal to the past inside the California Academy of Sciences. Information gleaned from such nests, woven long ago from species in plant communities called transitional habitat, could help restore the shoreline in the future. Transitional habitat has nearly disappeared from the San Francisco Bay, and scientists need a clearer picture of its original species composition—which was never properly documented. With that insight, conservation research groups like the San Francisco Bay Bird Observatory can help guide best practices when restoring the native habitat that has long served as critical refuge for imperiled birds and animals as adjacent marshes flood more with rising sea levels. “We can’t ask restoration ecologists to plant nonnative species or to just take their best guess and throw things out there,” says Rinkert.\",\n",
    "\"role\": \"user\"\n",
    "},\n",
    "{\n",
    "\"content\": \"Scientists are studying nests hoping to learn about transitional habitats that could help restore the shoreline of San Francisco Bay.\",\n",
    "\"role\": \"assistant\"\n",
    "}\n",
    "]\n",
    "\"\"\"\n",
    "\n",
    "\"\"\"\n",
    "For this task, you can use CSV or JSONL data. If you are formatting the data yourself (adding start, end tokens, etc.), you can use CSV or JSONL format. If you do not want to format the data yourself and want --chat-template parameter to format the data for you, you must use JSONL format. In both cases, CSV and JSONL can be used interchangeably but JSONL is the most preferred format.\n",
    "\n",
    "To train a chatbot, your data will have content and role. Some models support system role as well.\n",
    "\n",
    "Here is an example of a chatbot dataset (single sample):\n",
    "\n",
    "Copied\n",
    "[{'content': 'Help write a letter of 100 -200 words to my future self for '\n",
    "             'Kyra, reflecting on her goals and aspirations.',\n",
    "  'role': 'user'},\n",
    " {'content': 'Dear Future Self,\\n'\n",
    "             '\\n'\n",
    "             \"I hope you're happy and proud of what you've achieved. As I \"\n",
    "             \"write this, I'm excited to think about our goals and how far \"\n",
    "             \"you've come. One goal was to be a machine learning engineer. I \"\n",
    "             \"hope you've worked hard and become skilled in this field. Keep \"\n",
    "             'learning and innovating. Traveling was important to us. I hope '\n",
    "             \"you've seen different places and enjoyed the beauty of our \"\n",
    "             'world. Remember the memories and lessons. Starting a family '\n",
    "             'mattered to us. If you have kids, treasure every moment. Be '\n",
    "             'patient, loving, and grateful for your family.\\n'\n",
    "             '\\n'\n",
    "             'Take care of yourself. Rest, reflect, and cherish the time you '\n",
    "             'spend with loved ones. Remember your dreams and celebrate what '\n",
    "             \"you've achieved. Your determination brought you here. I'm \"\n",
    "             \"excited to see the person you've become, the impact you've made, \"\n",
    "             'and the love and joy in your life. Embrace opportunities and '\n",
    "             'keep dreaming big.\\n'\n",
    "             '\\n'\n",
    "             'With love,\\n'\n",
    "             'Kyra',\n",
    "  'role': 'assistant'}]\n",
    "As you can see, the data has content and role columns. The role column can be user or assistant or system. This data is, however, not formatted for training. You can use the --chat-template parameter to format the data during training.\n",
    "\n",
    "--chat-template supports the following kinds of templates:\n",
    "\n",
    "none (default)\n",
    "zephyr\n",
    "chatml\n",
    "tokenizer: use chat template mentioned in tokenizer config\n",
    "A multi-line sample is also shown below:\n",
    "\n",
    "Copied\n",
    "[{\"content\": \"hello\", \"role\": \"user\"}, {\"content\": \"hi nice to meet you\", \"role\": \"assistant\"}]\n",
    "[{\"content\": \"how are you\", \"role\": \"user\"}, {\"content\": \"I am fine\", \"role\": \"assistant\"}]\n",
    "[{\"content\": \"What is your name?\", \"role\": \"user\"}, {\"content\": \"My name is Mary\", \"role\": \"assistant\"}]\n",
    "[{\"content\": \"Which is the best programming language?\", \"role\": \"user\"}, {\"content\": \"Python\", \"role\": \"assistant\"}]\n",
    ".\n",
    ".\n",
    ".\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b7d0bc0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "\n",
    "df = result_df.copy()\n",
    "# Convert DataFrame to training format\n",
    "training_data = []\n",
    "\n",
    "for _, row in df.iterrows():\n",
    "    # Create user message from prompt\n",
    "    user_msg = {\n",
    "        \"content\": row[\"prompt\"],\n",
    "        \"role\": \"user\"\n",
    "    }\n",
    "    \n",
    "    # Create assistant message from solution\n",
    "    assistant_msg = {\n",
    "        \"content\": row[\"solution\"],\n",
    "        \"role\": \"assistant\" \n",
    "    }\n",
    "    \n",
    "    # Add think process as system message if present\n",
    "    if pd.notna(row[\"think_process\"]):\n",
    "        system_msg = {\n",
    "            \"content\": row[\"think_process\"],\n",
    "            \"role\": \"assistant\"\n",
    "        }\n",
    "        training_data.append([user_msg, system_msg, assistant_msg])\n",
    "    else:\n",
    "        training_data.append([user_msg, assistant_msg])\n",
    "\n",
    "# Save to JSONL file\n",
    "with open('training_data.jsonl', 'w', encoding='utf-8') as f:\n",
    "    for messages in training_data:\n",
    "        f.write(json.dumps(messages, ensure_ascii=False) + '\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cc4e93b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "705b1d94",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}