File size: 84,556 Bytes
9b12a3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is the charname_results: <re.Match object; span=(0, 8), match='【Takeru】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 8), match='【Takeru】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 8), match='【Sumika】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 11), match='【Tsukuyomi】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 9), match='【Chizuru】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 8), match='【Takeru】'>.\n",
      "And this is the dialogue: None\n",
      "This is the charname_results: <re.Match object; span=(0, 9), match='【Chizuru】'>.\n",
      "And this is the dialogue: None\n"
     ]
    }
   ],
   "source": [
    "# usage: sp.encode_as_ids(\"This is a test\")\n",
    "\n",
    "# We're using sentencepiece because this is llama2\n",
    "\n",
    "\n",
    "\n",
    "import re\n",
    "\n",
    "charname_regex = re.compile(r\"【.+?】\")\n",
    "dialogue_regex = re.compile(r\"「.+?」\")\n",
    "# re.search(str)\n",
    "\n",
    "def makecols(str):\n",
    "    charname_results = charname_regex.search(str)\n",
    "    dialogue_results = dialogue_regex.search(str)\n",
    "    if charname_results is None:\n",
    "        return ['MONOLOGUE',dialogue_results or \"\"]\n",
    "    try: \n",
    "        return (charname_results.group(0)[1:][:-1],dialogue_results.group(0)[1:][:-1])\n",
    "    except:\n",
    "        print(f\"This is the charname_results: {charname_results}.\\nAnd this is the dialogue: {dialogue_results}\")\n",
    "        return ['ERROR!','']\n",
    "\n",
    "\n",
    "def not_monologue(tup):\n",
    "    if (tup[0] == 'MONOLOGUE'):\n",
    "        return False\n",
    "    return True\n",
    "\n",
    "\n",
    "script = open('muvluv-chizururoute-script.txt').read().replace('\\n','').replace('\\x05','').split('\u0001')\n",
    "script = list(map(makecols,script))\n",
    "# script = list(filter(not_monologue,script)) \n",
    "\n",
    "# tokenizer = AutoTokenizer.from_pretrained(\"meta-llama/Llama-2-7b-hf\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import AutoTokenizer\n",
    "from tqdm import tqdm\n",
    "\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"bigscience/bloomz-3b\") # placeholder until I get huggingface llama access\n",
    "\n",
    "def generate_examples(script, tokenizer, chizuru_count_min=2, window_length=10, takeru_count_min=2, max_lines_without_chizuru=6):\n",
    "    MAX_TOKENS = 800  # Change this value if you want to use a different token limit\n",
    "\n",
    "    examples = []\n",
    "    sliding_window = []\n",
    "    example = []\n",
    "    chizuru_counter = 0\n",
    "    takeru_counter = 0\n",
    "    lines_without_chizuru = 0\n",
    "    making_conversation = False\n",
    "\n",
    "    for dialogue in tqdm(script):\n",
    "        speaker, line = dialogue\n",
    "\n",
    "        if len(sliding_window) == window_length:\n",
    "            sliding_window.pop(0)  # Remove first element\n",
    "\n",
    "        sliding_window.append(dialogue)\n",
    "\n",
    "        # Check if there are more than chizuru_count_min spoken lines from Chizuru across sliding_window\n",
    "        chizuru_counter = sum(1 for d in sliding_window if d[0] == 'Chizuru')\n",
    "        takeru_counter = sum(1 for d in sliding_window if d[0] == 'Takeru')\n",
    "\n",
    "        if speaker == 'Chizuru':\n",
    "            lines_without_chizuru = 0  # Reset count\n",
    "        else:\n",
    "            lines_without_chizuru += 1  # Increment count\n",
    "            \n",
    "        can_start_conversation = chizuru_counter >= chizuru_count_min and takeru_counter >= takeru_count_min\n",
    "        should_stop_conversation = making_conversation and (len(tokenizer.encode(' '.join([d[1] for d in example]))) > MAX_TOKENS or lines_without_chizuru > max_lines_without_chizuru)\n",
    "        \n",
    "        if making_conversation:\n",
    "            if should_stop_conversation: # making conversation and should stop\n",
    "                examples.append(example)\n",
    "                example = []\n",
    "                sliding_window = []\n",
    "                chizuru_counter = 0\n",
    "                takeru_counter = 0\n",
    "                lines_without_chizuru = 0\n",
    "                making_conversation = False\n",
    "            else: # making conversation and should not stop\n",
    "                example.append(dialogue)\n",
    "        elif can_start_conversation: # not making conversation and should start, by appending an example to conversation\n",
    "            example.append(dialogue)\n",
    "            making_conversation = True\n",
    "\n",
    "    if example:  # Add last example if it's non-empty\n",
    "        examples.append(example)\n",
    "\n",
    "    return examples\n",
    "\n",
    "\n",
    "# additional step: remove all non-chizuru examples at the end of each example. They're literally pointless and will not be used in training data anyway.\n",
    "\n",
    "# def format_conversations(script, speaker1='Chizuru', speaker2='Takeru', speaker1_count=3, speaker2_count=2, window_size=6, max_tokens=600):\n",
    "#     conversations = []  # to hold the conversations\n",
    "#     current_conversation = []  # to hold the current conversation\n",
    "#     current_window = []  # to hold the current window of lines\n",
    "    \n",
    "#     for line in script:\n",
    "#         speaker, dialogue = line\n",
    "#         current_window.append(line)\n",
    "\n",
    "#         # If window is larger than window_size, remove the oldest line\n",
    "#         if len(current_window) > window_size:\n",
    "#             current_window.pop(0)\n",
    "\n",
    "#         # Count the dialogues of speaker1 and speaker2 in the current window\n",
    "#         speaker1_dialogues = sum([1 for line in current_window if line[0] == speaker1])\n",
    "#         speaker2_dialogues = sum([1 for line in current_window if line[0] == speaker2])\n",
    "\n",
    "#         # If conditions are met, add dialogues to the current conversation\n",
    "#         if speaker1_dialogues >= speaker1_count and speaker2_dialogues >= speaker2_count:\n",
    "#             current_conversation.append(line)\n",
    "\n",
    "#             # If the current conversation reaches the max_tokens limit, add it to the conversations and reset current_conversation\n",
    "#             if tokenizer.encode(' '.join([dialogue for _, dialogue in current_conversation]), return_tensors='pt').shape[1] > max_tokens:\n",
    "#                 conversations.append(current_conversation)\n",
    "#                 current_conversation = []\n",
    "#                 current_window = []\n",
    "    \n",
    "#     # Add the last conversation if it was not added before\n",
    "#     if current_conversation and tokenizer.encode(' '.join([dialogue for _, dialogue in current_conversation]), return_tensors='pt').shape[1] <= max_tokens:\n",
    "#         conversations.append(current_conversation)\n",
    "\n",
    "#     return conversations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['MONOLOGUE', '']\n"
     ]
    }
   ],
   "source": [
    "print(script[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 12876/12876 [00:01<00:00, 7052.90it/s]\n"
     ]
    }
   ],
   "source": [
    "created_examples_script = generate_examples(script, tokenizer,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Chizuru', 'Hold on. You were WHAT?'), ('Takeru', 'Curse you, Sumikaaaaa!!'), ('Chizuru', 'Shirooogaaane-kun...'), ('Takeru', \"Class Rep, calm down.We're in the middle of homeroom right now, remember...?\"), ('Marimo', \"Alright everyone, homeroom's over! I'm gonna go over to Class D for a bit. I'm leaving you in charge, Sakaki-san!Just let me know who's absent when I get back!\"), ('Takeru', '......'), ('Chizuru', \"Yes, ma'am! Understood!\"), ['MONOLOGUE', ''], ('Chizuru', 'Now then... What was that about?'), ('Takeru', \"It's kind of a long story.\"), ('Chizuru', 'Give me the short version, then.'), ('Takeru', \"I'll do my best.Let's see here — Basically, it's because I told her there was a demon on the swim team.\"), ('Miki', 'That was short!!'), ('Chizuru', 'Are you kidding me?'), ('Takeru', 'Not in the slightest.'), ('Chizuru', '...And?'), ('Takeru', \"Then Meiya said something about bringing her to justice and ran off on her own. I didn't do anything.\"), ('Sumika', 'And then after that...'), ('Takeru', 'Sumika!!'), ('Sumika', 'Bleh.'), ['MONOLOGUE', ''], ('Takeru', \"Heh... heh... heh... I know all about it, Class Rep. You were rivals with the former swim team captain, weren't you? Did you really think you had a chance against her?\"), ('Chizuru', '...Shut up!! What do you know about me, anyway!?'), ('Takeru', \"What? I can't just take that sitting down... I can't believe you're treating me like I'm just any other guy.\"), ('Chizuru', '...What do you mean?'), ('Takeru', \"I'm Shirogane Takeru!!\"), ('Chizuru', 'I know that. Are you stupid?'), ('Takeru', \"Mm, that didn't come out quite right... Well, in any case, you ought to stop being so jealous of her.\"), ('Chizuru', 'Jealous?'), ('Takeru', \"A close friend, and a former rival. And you competed against each other back when she led that club... but now, you're both performing on different stages...\"), ('Chizuru', 'What did you just say...?'), ('Takeru', \"Well, I mean... Can't you see what I'm saying? Yeesh, don't make me spell it out for you.\"), ('Chizuru', 'Stop making fun of me already!'), ('Takeru', \"I'm not making fun of you, I'm just telling it how it is.\"), ('Chizuru', 'You wanna say that again!?'), ('Takeru', 'Oops! Better make my escape before the Class Rep blows a fuse!'), ['MONOLOGUE', ''], ('Miki', 'Whoa... Chizuru-chan is faaast.'), ('Chizuru', \"You're not getting away from me.\"), ('Takeru', \"Come on... Let go of me already.Don't make me make fun of you again!\"), ('Chizuru', \"Homeroom isn't over yet.Don't leave the classroom.\"), ('Takeru', \"But Marimo-chan said it was over, didn't she!?\"), ('Chizuru', \"Not according to the schedule, it isn't.We still have five minutes left.\"), ('Takeru', 'Tch... Nobody likes a stubborn woman, you know that?'), ('Chizuru', \"I don't need you to like me.\"), ('Takeru', 'Dammit...'), ('Chizuru', \"That's more like it. Now go back to your seat...\"), ('Takeru', \"...Ha! You've fallen for my ruse!!\"), ('Chizuru', 'Ah! Wait a... Kyah!!'), ('Takeru', 'Whoa!!'), ['MONOLOGUE', ''], ['MONOLOGUE', ''], ('Chizuru', 'Kyaaaaah!!!'), ('Takeru', 'Ow-ow-ow-ow-ow...'), ('Chizuru', 'Ugh... Ouch...'), ('Takeru & Chizuru', '!?'), ('Chizuru', \"Wh-Wh-Wh-Wh-What're you doing!?Get off of me right this instant!!\"), ('Takeru', \"That's my line! You're the one on top of me!!\"), ('Voice', '...Such intimacy... and in public...'), ('Takeru & Chizuru', 'Huh!? Ah!!'), ('Takeru', 'Ayamine!'), ('Chizuru', 'Th-This is just an accident!M-M-More importantly, Ayamine-san...'), ('Ayamine', '......'), ('Chizuru', 'At least say hello!'), ('Ayamine', '......'), ('Chizuru', '...Ayamine-san, are you listening?'), ('Ayamine', '......'), ('Chizuru', '......'), ('Kei', 'Yes, good morning.'), ('Chizuru', 'Grrrrrrr!!'), ('Kei', '......'), ('Chizuru', \"You cut class yesterday, you're late today... Do you really think it's okay to keep doing that?\"), ('Kei', '...Yesterday...'), ('Chizuru', 'What about it?'), ('Kei', '......'), ('Chizuru', '......'), ('Kei', '...I got lost.'), ('Chizuru', 'How can you lie with such a straight face!?'), ('Kei', 'Busted...?'), ('Miki', \"It's pretty obvious.\"), ('Kei', \"...Being late once in a while isn't so bad.\"), ('Chizuru', \"Once in a while!? You're late every time you come to school, and most of the time you don't even show up at all!!\"), ('Kei', 'But I got to see something nice...'), ('Miki', 'Hey! Guess what, Kei-chan? We got a new transfer student yesterday!'), ('Takeru', 'Heeey...'), ('Chizuru', '......'), ['MONOLOGUE', ''], ('Takeru', \"I'll just go on ahead, then.\")]\n"
     ]
    }
   ],
   "source": [
    "print(created_examples_script[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def merge_consecutive_lines(conversation):\n",
    "    merged_conversation = []\n",
    "    last_speaker = None\n",
    "    for speaker, line in conversation:\n",
    "        if not merged_conversation or speaker != last_speaker:\n",
    "            # New speaker or first dialogue, just add it to the list\n",
    "            merged_conversation.append((speaker, line))\n",
    "        else:\n",
    "            # Same speaker as before, concatenate the lines\n",
    "            prev_speaker, prev_line = merged_conversation.pop()\n",
    "            merged_conversation.append((prev_speaker, prev_line + \" \" + line))\n",
    "        last_speaker = speaker\n",
    "    return list(filter(not_monologue, merged_conversation)) # why do this step here? Because I don't want to iterate over the dataset twice, and monologues should count when examples are being generated with the sliding window, so I can't remove them in the usual spot.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "conversations_processed = list(map(merge_consecutive_lines,  created_examples_script))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Chizuru', 'Hold on. You were WHAT?'), ('Takeru', 'Curse you, Sumikaaaaa!!'), ('Chizuru', 'Shirooogaaane-kun...'), ('Takeru', \"Class Rep, calm down.We're in the middle of homeroom right now, remember...?\"), ('Marimo', \"Alright everyone, homeroom's over! I'm gonna go over to Class D for a bit. I'm leaving you in charge, Sakaki-san!Just let me know who's absent when I get back!\"), ('Takeru', '......'), ('Chizuru', \"Yes, ma'am! Understood!\"), ('Chizuru', 'Now then... What was that about?'), ('Takeru', \"It's kind of a long story.\"), ('Chizuru', 'Give me the short version, then.'), ('Takeru', \"I'll do my best.Let's see here — Basically, it's because I told her there was a demon on the swim team.\"), ('Miki', 'That was short!!'), ('Chizuru', 'Are you kidding me?'), ('Takeru', 'Not in the slightest.'), ('Chizuru', '...And?'), ('Takeru', \"Then Meiya said something about bringing her to justice and ran off on her own. I didn't do anything.\"), ('Sumika', 'And then after that...'), ('Takeru', 'Sumika!!'), ('Sumika', 'Bleh.'), ('Takeru', \"Heh... heh... heh... I know all about it, Class Rep. You were rivals with the former swim team captain, weren't you? Did you really think you had a chance against her?\"), ('Chizuru', '...Shut up!! What do you know about me, anyway!?'), ('Takeru', \"What? I can't just take that sitting down... I can't believe you're treating me like I'm just any other guy.\"), ('Chizuru', '...What do you mean?'), ('Takeru', \"I'm Shirogane Takeru!!\"), ('Chizuru', 'I know that. Are you stupid?'), ('Takeru', \"Mm, that didn't come out quite right... Well, in any case, you ought to stop being so jealous of her.\"), ('Chizuru', 'Jealous?'), ('Takeru', \"A close friend, and a former rival. And you competed against each other back when she led that club... but now, you're both performing on different stages...\"), ('Chizuru', 'What did you just say...?'), ('Takeru', \"Well, I mean... Can't you see what I'm saying? Yeesh, don't make me spell it out for you.\"), ('Chizuru', 'Stop making fun of me already!'), ('Takeru', \"I'm not making fun of you, I'm just telling it how it is.\"), ('Chizuru', 'You wanna say that again!?'), ('Takeru', 'Oops! Better make my escape before the Class Rep blows a fuse!'), ('Miki', 'Whoa... Chizuru-chan is faaast.'), ('Chizuru', \"You're not getting away from me.\"), ('Takeru', \"Come on... Let go of me already.Don't make me make fun of you again!\"), ('Chizuru', \"Homeroom isn't over yet.Don't leave the classroom.\"), ('Takeru', \"But Marimo-chan said it was over, didn't she!?\"), ('Chizuru', \"Not according to the schedule, it isn't.We still have five minutes left.\"), ('Takeru', 'Tch... Nobody likes a stubborn woman, you know that?'), ('Chizuru', \"I don't need you to like me.\"), ('Takeru', 'Dammit...'), ('Chizuru', \"That's more like it. Now go back to your seat...\"), ('Takeru', \"...Ha! You've fallen for my ruse!!\"), ('Chizuru', 'Ah! Wait a... Kyah!!'), ('Takeru', 'Whoa!!'), ('Chizuru', 'Kyaaaaah!!!'), ('Takeru', 'Ow-ow-ow-ow-ow...'), ('Chizuru', 'Ugh... Ouch...'), ('Takeru & Chizuru', '!?'), ('Chizuru', \"Wh-Wh-Wh-Wh-What're you doing!?Get off of me right this instant!!\"), ('Takeru', \"That's my line! You're the one on top of me!!\"), ('Voice', '...Such intimacy... and in public...'), ('Takeru & Chizuru', 'Huh!? Ah!!'), ('Takeru', 'Ayamine!'), ('Chizuru', 'Th-This is just an accident!M-M-More importantly, Ayamine-san...'), ('Ayamine', '......'), ('Chizuru', 'At least say hello!'), ('Ayamine', '......'), ('Chizuru', '...Ayamine-san, are you listening?'), ('Ayamine', '......'), ('Chizuru', '......'), ('Kei', 'Yes, good morning.'), ('Chizuru', 'Grrrrrrr!!'), ('Kei', '......'), ('Chizuru', \"You cut class yesterday, you're late today... Do you really think it's okay to keep doing that?\"), ('Kei', '...Yesterday...'), ('Chizuru', 'What about it?'), ('Kei', '......'), ('Chizuru', '......'), ('Kei', '...I got lost.'), ('Chizuru', 'How can you lie with such a straight face!?'), ('Kei', 'Busted...?'), ('Miki', \"It's pretty obvious.\"), ('Kei', \"...Being late once in a while isn't so bad.\"), ('Chizuru', \"Once in a while!? You're late every time you come to school, and most of the time you don't even show up at all!!\"), ('Kei', 'But I got to see something nice...'), ('Miki', 'Hey! Guess what, Kei-chan? We got a new transfer student yesterday!'), ('Takeru', 'Heeey...'), ('Chizuru', '......'), ('Takeru', \"I'll just go on ahead, then.\")]\n"
     ]
    }
   ],
   "source": [
    "print(conversations_processed[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def add_space_after_punctuation(conversations):\n",
    "    corrected_conversations = []\n",
    "    for conversation in conversations:\n",
    "        corrected_conversation = []\n",
    "        for speaker, line in conversation:\n",
    "            # Add a space wherever there is a punctuation mark followed by a letter, excluding ellipsis\n",
    "            corrected_line = re.sub(r'([.,!?])(\\w)', r'\\1 \\2', line)\n",
    "            corrected_conversation.append((speaker, corrected_line))\n",
    "        corrected_conversations.append(corrected_conversation)\n",
    "    return corrected_conversations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'add_space_after_punctuation' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m conversations_processed_whitespacefix \u001b[39m=\u001b[39m add_space_after_punctuation(conversations_processed)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'add_space_after_punctuation' is not defined"
     ]
    }
   ],
   "source": [
    "conversations_processed_whitespacefix = add_space_after_punctuation(conversations_processed)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Chizuru', 'Hold on. You were WHAT?'), ('Takeru', 'Curse you, Sumikaaaaa!!'), ('Chizuru', 'Shirooogaaane-kun...'), ('Takeru', \"Class Rep, calm down. We're in the middle of homeroom right now, remember...?\"), ('Marimo', \"Alright everyone, homeroom's over! I'm gonna go over to Class D for a bit. I'm leaving you in charge, Sakaki-san! Just let me know who's absent when I get back!\"), ('Takeru', '......'), ('Chizuru', \"Yes, ma'am! Understood!\"), ('Chizuru', 'Now then... What was that about?'), ('Takeru', \"It's kind of a long story.\"), ('Chizuru', 'Give me the short version, then.'), ('Takeru', \"I'll do my best. Let's see here — Basically, it's because I told her there was a demon on the swim team.\"), ('Miki', 'That was short!!'), ('Chizuru', 'Are you kidding me?'), ('Takeru', 'Not in the slightest.'), ('Chizuru', '... And?'), ('Takeru', \"Then Meiya said something about bringing her to justice and ran off on her own. I didn't do anything.\"), ('Sumika', 'And then after that...'), ('Takeru', 'Sumika!!'), ('Sumika', 'Bleh.'), ('Takeru', \"Heh... heh... heh... I know all about it, Class Rep. You were rivals with the former swim team captain, weren't you? Did you really think you had a chance against her?\"), ('Chizuru', '... Shut up!! What do you know about me, anyway!?'), ('Takeru', \"What? I can't just take that sitting down... I can't believe you're treating me like I'm just any other guy.\"), ('Chizuru', '... What do you mean?'), ('Takeru', \"I'm Shirogane Takeru!!\"), ('Chizuru', 'I know that. Are you stupid?'), ('Takeru', \"Mm, that didn't come out quite right... Well, in any case, you ought to stop being so jealous of her.\"), ('Chizuru', 'Jealous?'), ('Takeru', \"A close friend, and a former rival. And you competed against each other back when she led that club... but now, you're both performing on different stages...\"), ('Chizuru', 'What did you just say...?'), ('Takeru', \"Well, I mean... Can't you see what I'm saying? Yeesh, don't make me spell it out for you.\"), ('Chizuru', 'Stop making fun of me already!'), ('Takeru', \"I'm not making fun of you, I'm just telling it how it is.\"), ('Chizuru', 'You wanna say that again!?'), ('Takeru', 'Oops! Better make my escape before the Class Rep blows a fuse!'), ('Miki', 'Whoa... Chizuru-chan is faaast.'), ('Chizuru', \"You're not getting away from me.\"), ('Takeru', \"Come on... Let go of me already. Don't make me make fun of you again!\"), ('Chizuru', \"Homeroom isn't over yet. Don't leave the classroom.\"), ('Takeru', \"But Marimo-chan said it was over, didn't she!?\"), ('Chizuru', \"Not according to the schedule, it isn't. We still have five minutes left.\"), ('Takeru', 'Tch... Nobody likes a stubborn woman, you know that?'), ('Chizuru', \"I don't need you to like me.\"), ('Takeru', 'Dammit...'), ('Chizuru', \"That's more like it. Now go back to your seat...\"), ('Takeru', \"... Ha! You've fallen for my ruse!!\"), ('Chizuru', 'Ah! Wait a... Kyah!!'), ('Takeru', 'Whoa!!'), ('Chizuru', 'Kyaaaaah!!!'), ('Takeru', 'Ow-ow-ow-ow-ow...'), ('Chizuru', 'Ugh... Ouch...'), ('Takeru & Chizuru', '!?'), ('Chizuru', \"Wh-Wh-Wh-Wh-What're you doing!? Get off of me right this instant!!\"), ('Takeru', \"That's my line! You're the one on top of me!!\"), ('Voice', '... Such intimacy... and in public...'), ('Takeru & Chizuru', 'Huh!? Ah!!'), ('Takeru', 'Ayamine!'), ('Chizuru', 'Th-This is just an accident! M-M-More importantly, Ayamine-san...'), ('Ayamine', '......'), ('Chizuru', 'At least say hello!'), ('Ayamine', '......'), ('Chizuru', '... Ayamine-san, are you listening?'), ('Ayamine', '......'), ('Chizuru', '......'), ('Kei', 'Yes, good morning.'), ('Chizuru', 'Grrrrrrr!!'), ('Kei', '......'), ('Chizuru', \"You cut class yesterday, you're late today... Do you really think it's okay to keep doing that?\"), ('Kei', '... Yesterday...'), ('Chizuru', 'What about it?'), ('Kei', '......'), ('Chizuru', '......'), ('Kei', '... I got lost.'), ('Chizuru', 'How can you lie with such a straight face!?'), ('Kei', 'Busted...?'), ('Miki', \"It's pretty obvious.\"), ('Kei', \"... Being late once in a while isn't so bad.\"), ('Chizuru', \"Once in a while!? You're late every time you come to school, and most of the time you don't even show up at all!!\"), ('Kei', 'But I got to see something nice...'), ('Miki', 'Hey! Guess what, Kei-chan? We got a new transfer student yesterday!'), ('Takeru', 'Heeey...'), ('Chizuru', '......'), ('Takeru', \"I'll just go on ahead, then.\")]\n"
     ]
    }
   ],
   "source": [
    "print(conversations_processed_whitespacefix[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_training_examples(conversation):\n",
    "    training_examples = []\n",
    "    temp_dialogue = []\n",
    "    for idx, dialogue in enumerate(conversation):\n",
    "        speaker, _ = dialogue\n",
    "        temp_dialogue.append(dialogue)\n",
    "        if speaker == 'Chizuru' and idx != 0:\n",
    "            training_examples.append(temp_dialogue.copy())  # Add up to and including current line\n",
    "    return training_examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.'),\n",
       "  ('Takeru',\n",
       "   'Alright, I get it... Jeez, you sure know how to kill my motivation.'),\n",
       "  ('Chizuru',\n",
       "   \"There are some things you just have to do, whether you're motivated or not.\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.'),\n",
       "  ('Takeru',\n",
       "   'Alright, I get it... Jeez, you sure know how to kill my motivation.'),\n",
       "  ('Chizuru',\n",
       "   \"There are some things you just have to do, whether you're motivated or not.\"),\n",
       "  ('Takeru', \"Yeah, yeah... We're done! We're done!\"),\n",
       "  ('Sumika', \"Alright, let's go home.\"),\n",
       "  ('Meiya', 'Yes.'),\n",
       "  ('Takeru', 'Class Rep, you going home, too?'),\n",
       "  ('Chizuru', 'Huh? No, I have club activities.')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.'),\n",
       "  ('Takeru',\n",
       "   'Alright, I get it... Jeez, you sure know how to kill my motivation.'),\n",
       "  ('Chizuru',\n",
       "   \"There are some things you just have to do, whether you're motivated or not.\"),\n",
       "  ('Takeru', \"Yeah, yeah... We're done! We're done!\"),\n",
       "  ('Sumika', \"Alright, let's go home.\"),\n",
       "  ('Meiya', 'Yes.'),\n",
       "  ('Takeru', 'Class Rep, you going home, too?'),\n",
       "  ('Chizuru', 'Huh? No, I have club activities.'),\n",
       "  ('Takeru', 'Oh. I see.'),\n",
       "  ('Chizuru', '... Are you implying something?')],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.'),\n",
       "  ('Takeru',\n",
       "   'Alright, I get it... Jeez, you sure know how to kill my motivation.'),\n",
       "  ('Chizuru',\n",
       "   \"There are some things you just have to do, whether you're motivated or not.\"),\n",
       "  ('Takeru', \"Yeah, yeah... We're done! We're done!\"),\n",
       "  ('Sumika', \"Alright, let's go home.\"),\n",
       "  ('Meiya', 'Yes.'),\n",
       "  ('Takeru', 'Class Rep, you going home, too?'),\n",
       "  ('Chizuru', 'Huh? No, I have club activities.'),\n",
       "  ('Takeru', 'Oh. I see.'),\n",
       "  ('Chizuru', '... Are you implying something?'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Chizuru',\n",
       "   \"It may be on the verge of disbanding, but we're still giving it our all...\")],\n",
       " [('Chizuru', '... Sorry to have to spoil the celebration, but...'),\n",
       "  ('Takeru', 'Ah?'),\n",
       "  ('Chizuru', \"Shirogane-kun, you're on cleaning duty today. Have fun.\"),\n",
       "  ('Takeru', 'NYET!'),\n",
       "  ('Chizuru', \"Ayamine-san. Where do you think you're going?\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru', \"You've got cleaning duty too, you know.\"),\n",
       "  ('Kei', '......'),\n",
       "  ('Chizuru',\n",
       "   \"... Do you have something to say? Don't tell me you think it's not your mess to clean up just because you're never here...\"),\n",
       "  ('Kei', \"... You're good.\"),\n",
       "  ('Chizuru',\n",
       "   \"Excuses like that aren't going to fly. This is a rule, so stop being selfish and obey it.\"),\n",
       "  ('Kei', '... Dog of the system.'),\n",
       "  ('Chizuru', 'What did you call me!?'),\n",
       "  ('Kei', \"Shirogane said I didn't have to.\"),\n",
       "  ('Takeru', 'Whaaat?'),\n",
       "  ('Chizuru',\n",
       "   \"Did he now? Well, unfortunately for you, I'm also on cleaning duty. I'm not letting you off that easy. Here's your broom.\"),\n",
       "  ('Kei', 'End of the line...'),\n",
       "  ('Sumika', \"Hey, what're you doing? Takeru-chan, let's go home!\"),\n",
       "  ('Kei', 'Here, Kagami. Good luck with the cleaning. Bye now.'),\n",
       "  ('Sumika', 'Huh? Oh, okay. Bye-bye.'),\n",
       "  ('Chizuru', 'W-Wait just a minute!'),\n",
       "  ('Kei', '... Her problem now.'),\n",
       "  ('Chizuru', \"No it isn't!!\"),\n",
       "  ('Meiya', 'What is it? Are you not going home?'),\n",
       "  ('Kei', \"She'll help too.\"),\n",
       "  ('Meiya', 'What do you mean?'),\n",
       "  ('Chizuru', 'Would you just... Ah, wait!!'),\n",
       "  ('Sumika', 'Hey, Takeru-chan, over here! Help me move the desks!'),\n",
       "  ('Takeru', \"Are you an idiot!? Don't just go with the flow!\"),\n",
       "  ('Chizuru', 'Huh? ... A-Ah...! Ugh, forget it!! What a jerk!!'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Meiya', 'Is something about to commence?'),\n",
       "  ('Sumika', \"We're gonna clean the room.\"),\n",
       "  ('Meiya',\n",
       "   'I see... so you yourselves clean that which you have dirtied... A novel and admirable approach. I shall assist.'),\n",
       "  ('Chizuru', 'Shirogane-kun, quit slacking off. Come on, just get to work.'),\n",
       "  ('Takeru',\n",
       "   'Alright, I get it... Jeez, you sure know how to kill my motivation.'),\n",
       "  ('Chizuru',\n",
       "   \"There are some things you just have to do, whether you're motivated or not.\"),\n",
       "  ('Takeru', \"Yeah, yeah... We're done! We're done!\"),\n",
       "  ('Sumika', \"Alright, let's go home.\"),\n",
       "  ('Meiya', 'Yes.'),\n",
       "  ('Takeru', 'Class Rep, you going home, too?'),\n",
       "  ('Chizuru', 'Huh? No, I have club activities.'),\n",
       "  ('Takeru', 'Oh. I see.'),\n",
       "  ('Chizuru', '... Are you implying something?'),\n",
       "  ('Takeru', 'Huh?'),\n",
       "  ('Chizuru',\n",
       "   \"It may be on the verge of disbanding, but we're still giving it our all...\"),\n",
       "  ('Takeru',\n",
       "   \"Oh, right, so that's what you meant.... Did I hit a sore spot? My bad, dude.\"),\n",
       "  ('Chizuru', '... Bye.')]]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "generate_training_examples(conversations_processed_whitespacefix[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_data_conversations = list(map(generate_training_examples, conversations_processed_whitespacefix))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('Takeru', '... Oops.'), ('Chizuru', \"Well, Takeru. Looks like you've really done it this time...\"), ('Takeru', '*gulp*... Nngh...'), ('Chizuru', \"So, what's it gonna be? Are you gonna throw it in...? Or have you changed your mind〜?\"), ('Takeru', 'Nngh... Gghk...'), ('Chizuru', \"You don't have to force yourself.\"), ('Takeru', 'Rgh... Grr... Nghaaaaah!!'), ('Chizuru', 'Ah!'), ('Chizuru', 'You actually threw it in... Wow.'), ('Takeru', '*gasp*...*wheeze*... I-I am a man, after all...'), ('Chizuru', \"Oh, gosh. And now you're sweating.\"), ('Takeru', 'Ch-Chizuruuu! Hurry it up!!'), ('Chizuru', '──Huh?'), ('Takeru', \"I-If you don't hurry, those ten thousand yen will go to waste!\"), ('Chizuru', 'Wh-Wha...!?'), ('Takeru', 'Clap twice!'), ('Chizuru', \"Oh, right! Ermm... Let's see...\"), ('Takeru', 'Uhhh... How about... O-Okay! Got it! May Chizuru and I always be horny together! ......'), ('Chizuru', '...... Wh-What the hell? How can you say something so embarrassing in front of all these people!?'), ('Takeru', \"Ow! It's close enough to what you said, isn't it!?\"), ('Chizuru', \"It's not even close!!\"), ('Takeru', \"So, what!? It would've been okay if no one else was here!?\"), ('Chizuru', 'Jerk!'), ('Takeru', \"Anyway, next! ... Keep praying! We've gotta have more wishes than that!\"), ('Chizuru', \"We've already finished!\"), ('Takeru', \"You've gotta make at least ten thousand yen's worth of wishes or else it'll have been for nothing!\"), ('Chizuru', 'F-Fine then!'), ('Takeru', 'Ummm... May Class Rep get along with her mother!'), ('Chizuru', \"What're you doing!? You're wasting it! I don't need a wish to do that!\"), ('Takeru', \"I could say the same thing! You really think I'd cheat on you!?\"), ('Chizuru', 'W-Well, I mean... There are always so many other girls around you, and...!!'), ('Takeru', \"Ugh, whatever! Let's go! One more wish!\"), ('Chizuru', 'A-Again!?'), ('Takeru', 'Is there a rule saying you can only have one wish per offering?'), ('Chizuru', \"I don't know about that, but──!\"), ('Takeru', \"May Chizuru's boobs get a little bigger!\"), ('Chizuru', 'Wh-...!? A-Are you calling me flat!?'), ('Takeru', 'Idiot! How can you say something like that in public!?'), ('Chizuru', 'You started it!!'), ('Takeru', \"Shut up!! You've been saying all your wishes out loud, too!\"), ('Chizuru', \"Ah... Th-That's only because you've been rushing me!!\"), ('Takeru', \"All I wanted was the old 'What did you wish for?' 'I'm too embarrassed to say!' kissy-kissy New Year's routine! But noooo! You've ruined everything, woman! Graaaah!!\"), ('Chizuru', \"*sigh*... Fine, I get it already. Let's just hurry up and bow... before our prayers go to waste.\"), ('Takeru', '─Oh, crap!'), ('Chizuru', \"Ah! Look at that! It says 'great fortune'!!\"), ('Takeru', \"Whaaa──!? Y-Y-You kiddin' me!?\"), ('Chizuru', \"Oh... Did you get 'great misfortune'?\"), ('Takeru', 'Yeah, right! That only happens in manga, moron!!'), ('Chizuru', \"Wh-What's the big deal!? Just let me see it!\"), ('Takeru', 'Ack!'), ('Chizuru', \"...'Misfortune.'\"), ('Takeru', 'Sh-Shut up...'), ('Chizuru', \"Well, it's just one of those silly traditions, that's all.\"), ('Takeru', \"Oh? You're handling this so maturely!\"), ('Chizuru', \"Well, I mean, look... It says you'll break up with your lover this year.\"), ('Takeru', \"... No chance in hell. These gods don't know what they're talking about.\"), ('Chizuru', 'I know, right?'), ('Takeru', \"Alrighty, then... Let's find a branch, and tie these things off...\"), ('Chizuru', \"Hey, Takeru... You're coming back to my place, right?\"), ('Takeru', 'You know it.'), ('Chizuru', \"Let's go, then! I've got a New Year's feast waiting for us at home!\")]\n",
      "100\n"
     ]
    }
   ],
   "source": [
    "training_data_conversations = list(filter(lambda x: len(x) >= 1, training_data_conversations))\n",
    "# len(processed_conversations)\n",
    "print(training_data_conversations[99][-1])\n",
    "print(len(training_data_conversations))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A FUNCTION THAT LETS YOU CALL OPENAI ON ALL THE EXAMPLES\n",
    "import openai\n",
    "import os\n",
    "\n",
    "def write_context_to_file(training_data_example, destination_directory, example_index): # for easier inspection\n",
    "    full_conversation = training_data_example[-1]\n",
    "    context = '\\n'.join([f'{speaker}: {line}' for speaker, line in full_conversation])\n",
    "    \n",
    "    filename = os.path.join(destination_directory, f'{example_index:03d}_convesation.txt') # I'm paying for the tokens, I damn well want to see them\n",
    "\n",
    "    # Write the scenario to the file\n",
    "    with open(filename, 'w') as f_1:\n",
    "        f_1.write(context)\n",
    "\n",
    "for idx, content in enumerate(training_data_conversations):\n",
    "    write_context_to_file(content, 'conversations', idx)\n",
    "    \n",
    "\n",
    "def create_scenario(training_data_example, destination_directory, example_index):\n",
    "    full_conversation = training_data_example[-1]\n",
    "    context = '\\n'.join([f'{speaker}: {line}' for speaker, line in full_conversation])\n",
    "\n",
    "    if not os.path.exists(os.path.join(destination_directory, f'{example_index:03d}_cot_debug.txt')):\n",
    "        response = openai.ChatCompletion.create(\n",
    "            model=\"gpt-4\",\n",
    "            temperature=0.7,\n",
    "            messages=[\n",
    "                {\"role\": \"system\", \"content\": \"\"\"You are an expert scenario-writing and prompt-engineering AI. Your task is to, given a series of statements made by characters from Muv Luv Extra, determine which part of the story the scene is taking place in, and write a 3-sentence summary about what's happened until the point the conversation STARTS at (writing under the assumption that the reader knows who Chizuru is, and what some of her general traits are). \n",
    "\n",
    "Remember to keep the scenario at most three sentences long. Your goal is your goal is to describe the conversation's SETTING, at the START of the conversation, instead of being to summarize it. This context should make sense if the AI to be trained only had access to the first thing said by Chizuru.\n",
    "\n",
    "Think step-by-step, and explain your plan to write a good scenario for the provided context, before you actually write the scenario.\n",
    "\n",
    "Here are two roleplay prompt engineering things you should incorporate into your scenario:\n",
    "1. Your first sentence should explain the context of the scene: where it takes place, what exactly that place is (in general terms) and what each of the characters are doing there. Focus on Takeru and Chizuru when it comes to motivations.\n",
    "2. End with a statement that describes where the scene is going, specifically, what Chizuru is trying to do, in the future tense. So if it's the scene where Chizuru eventually agrees to take part in a cooking contest, you might end your scenario with \"[short context behind the context]. Chizuru will take part in a cooking contest to try and win a date with Takeru.\"\n",
    "\n",
    "----\n",
    "\n",
    "To help orient you as you determine which part of the plot a conversation is taking place in, here is the full plot summary of Chizuru's route in Muv Luv Extra, in point form.\n",
    "\n",
    "Takeru, the protagonist, wakes up with Meiya Mitsurugi, a company heiress and new classmate, unexpectedly in his bed.\n",
    "Takeru discovers Chizuru's leadership of the near-to-disband lacrosse team during a conversation with Chizuru, Meiya, and Sumika.\n",
    "Latecomer Ayamine Kei arrives, establishing her rivalry with Chizuru.\n",
    "Takeru gets caught up in a lunch duel between Sumika and Meiya and escapes, leading to a pleasant courtyard chat with Chizuru.\n",
    "Meiya acquires a mansion beside Takeru's house by buying out neighbors.\n",
    "Prof. Yuuko initiates a cooking competition, offering a date with Takeru as the prize. Chizuru, aiming to keep things sane, participates and wins.\n",
    "Takeru and Chizuru's winning trip takes them to an illusion museum.\n",
    "Time passes, and prep for a school sports festival starts. All the main characters choose lacrosse as their sport (Takeru has to convince Ayamine to play, after being asked to serve as a middleman by Chizuru). Chizuru is the team captain.\n",
    "Takeru self-appoints himself as the \"manager\" of the team and the characters start training. Chizuru and Takeru go on a walk after one such training session.\n",
    "The day of the sports festival arrives. Ayamine does not initially show up. The day progresses and Ayamine eventually shows up. The final match is against Yuuko's class, captained by Suzumiya Akane, a dear friend and sports rival of Chizuru.\n",
    "During the match itself, Chizuru, very focused on victory, makes a mistake and knocks her friend and rival Akane unconscious. Ambulances have to be called and the sports festival is cancelled. Chizuru is emotionally devestated.\n",
    "Other students start bullying Chizuru due to the accident, starting as soon as the day of the festival itself. Chizuru, being someone with a strong sense of justice and someone who holds herself to a very high standard, beings berating herself. Her tendency to try and take on every problem she faces completely alone begins to show itself.\n",
    "The bullying escalates; Takeru's attempts to get Chizuru to stop repressing her feelings it end up causing a few fights. After a particularly bad one, Chizuru slaps Takeru.\n",
    "Chizuru stops showing up for school due to the bullying. Takeru goes to her house and has a conversation with her mother, but doesn't find her.\n",
    "Takeru keeps trying to stop Chizuru's self-destructive spiral and only ends up exacerbating it. More fights happen. Takeru is slapped again, near Chizuru's house.\n",
    "Takeru learns about Chizuru's traumatic family situation from her mother. This situation being: her mother (a single mother) went from guy to guy for years, most of whom mistreated Chizuru herself. This in turn led to Chizuru having an intense dislike for her mother, as well as a desire to do everything herself (rebelling against her parent, who relied on others for everything) and being very strict with herself and others.\n",
    "Takeru tries yet again to get Chizuru to start coming to school again; an attempt to convince her he cares by revealing he talked to his mother leads to him getting slapped again.\n",
    "Chizuru receives a phone call from Chizuru's mother the next morning: she didn't come home the night before. Likely because of the perceived betrayal by her mother, who revealed her past, as well as a desire to do.\n",
    "Takeru and Ayamine end up searching the entire city; Takeru eventually finds Chizuru being harassed by a grown man (whom Chizuru had led on, in an attempt to live \"independently\", or at least away from her mother), and saves her.\n",
    "After a short argument, Takeru finally helps Chizuru realize her mistake and realize that he's just trying to help her. She tearfully forgives him.\n",
    "Following this, Chizuru visits her friend Akane in the hospital, and begins to make up with her mother. Akane suggests that Chizuru take one more school day off to go on a date with Takeru so that she can properly emotionally recover. This happens; the two nearly kiss but no feelings are confessed.\n",
    "Chizuru gets rebuked by school faculty for the extended absence, and Takeru and Ayamine get similarly criticized for ditching school to look for her earlier. Being asked to explain his actions, Takeru finally confesses his love for Chizuru during his defence.\n",
    "After the faculty meeting concludes, the two talk, confess to each other, and kiss. Some time later, there's a scene where the two talk about next steps in Chizuru's house. A final timeskip shows the two happily enjoying their life together at a shrine.\n",
    "\n",
    "----\n",
    "\n",
    "One last pointer: keep the language simple. Which characters are where, under what circumstances. The scene itself will do most of the talking. Keep the scenario 3 sentences long at most. Instead of mentioning events in the far future, you will concentrate on the event at hand and the things that led up to it.\n",
    "    \"\"\"},\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\" : \"\"\"Context:\n",
    "\n",
    "Chizuru: \"...Akane...\"\n",
    "\n",
    "Akane: \"Aha... ahaha... It's been a while, huh?\"\n",
    "\n",
    "Chizuru: \"Yeah...\"\n",
    "\n",
    "Akane: \"I'll bet your mom was really happy to see you, huh? You sure you don't wanna stay in there with her?\"\n",
    "\n",
    "Chizuru: \"Yeah. She's already up, and making a fuss about going home...\"\n",
    "\n",
    "Akane: \"Ahaha... That's good to hear.\"\n",
    "\n",
    "Chizuru: \"Umm... Akane...\"\n",
    "\n",
    "Akane: \"What?\"\n",
    "\n",
    "Chizuru: \"...I'm sorry... I'm really... really sorry...\"\n",
    "\n",
    "Akane: \"W-Wait, wait, stop that!\n",
    "C'mon, what're you getting all teary-eyed for...?\"\n",
    "\n",
    "Chizuru: \"I'm sorry... I'm so sorry...\"\n",
    "\n",
    "Akane: \"Enough! Stop, stop, stop!!\n",
    "I'm really bad at dealing with this sorta thing!\"\n",
    "\n",
    "Chizuru: \"...Sorry...\"\n",
    "    \"\"\"\n",
    "            },\n",
    "            {\n",
    "                \"role\" : \"assistant\",\n",
    "                \"content\" : \"\"\"Thought process: Given the characters involved and the dialogue, which reference Chizuru making up with her mother and show her making up with Akane, this conversation is likely taking place after the sports festival incident, where Chizuru's action resulted in Akane's injury. Chizuru is known for her strong sense of responsibility, and this apology to Akane fits in with her character. Therefore, the conversation likely occurs in the hospital where Akane was taken after the accident.\n",
    "\n",
    "Scenario: In the aftermath of the unfortunate sports festival incident, Chizuru visits her friend Akane at the hospital, filled with regret and guilt over the accident. Akane, despite her injuries, attempts to lighten the mood, clearly relieved to see Chizuru is feeling more like herself. Chizuru will try to make up with her friend.\n",
    "            \"\"\"\n",
    "            },\n",
    "            {\n",
    "                \"role\" : \"user\",\n",
    "            \"content\" : context\n",
    "            }\n",
    "            ]\n",
    "        )\n",
    "    \n",
    "        scenario = response['choices'][0]['message']['content']\n",
    "        \n",
    "        filename_cot_debug = os.path.join(destination_directory, f'{example_index:03d}_cot_debug.txt') # I'm paying for the tokens, I damn well want to see them\n",
    "\n",
    "        # Write the scenario to the file\n",
    "        with open(filename_cot_debug, 'w') as f_1:\n",
    "            f_1.write(scenario)\n",
    "\n",
    "        # # Assume \"Scenario:\\n\" is followed by the actual scenario\n",
    "        scenario = re.search('Scenario:(.*)', scenario, re.DOTALL).group(1)\n",
    "\n",
    "        # Create a filename based on the example index\n",
    "        filename = os.path.join(destination_directory, f'{example_index:03d}.txt')\n",
    "\n",
    "        # Write the scenario to the file\n",
    "        with open(filename, 'w') as f_2:\n",
    "            f_2.write(scenario)\n",
    "    else:\n",
    "        print(f\"Skipping {example_index:03d} because it already exists.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # create_scenario(training_data_conversations[2], 'scenarios', 2)\n",
    "# print(training_data_conversations[98][-1])\n",
    "# create_scenario(training_data_conversations[70], 'scenarios', 70)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# SPEND $12 on openai calls, to scenario-title all 100 examples\n",
    "\n",
    "# for idx, content in enumerate(tqdm(training_data_conversations)):\n",
    "#     create_scenario(content, 'scenarios', idx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "with open(\"training_examples_backup.csv\", \"w\") as f:\n",
    "    write = csv.writer(f)\n",
    "    \n",
    "    write.writerow([\"example\"])\n",
    "    write.writerows(training_data_conversations)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# read off every scenario, and make a list of them that lines up with the training data\n",
    "def make_scenario_list(training_data_conversations):\n",
    "    scenario_list = []\n",
    "    for idx, content in enumerate(training_data_conversations):\n",
    "        with open(f\"scenarios/{idx:03d}.txt\", \"r\") as f:\n",
    "            scenario_list.append(f.read())\n",
    "    return scenario_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "scenarios = make_scenario_list(training_data_conversations)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# for an example, create complete training prompts for every sub-example in the example by concatenating character_card + scenario + example + last_thing_chizuru_says in the format specified by the following docstring:\n",
    "\n",
    "def format_chat_history(chat_history):\n",
    "    return '\\n'.join([f'{speaker}: {line}' for speaker, line in chat_history]) # list comprehension + format string + .join is efficient... thanks GPT4\n",
    "\n",
    "# Note that clothes and physical traits\n",
    "def make_character_card(scenario, chat_history, last_chizuru_line):\n",
    "    return f\"\"\"You are an expert roleplaying model that specializes in playing the character Sakaki Chizuru from the visual novel Muv Luv Extra. Below is some information about Chizuru's personality and traits. Use this information to roleplay as Chizuru in a conversation whose setting is described by the \"scenario\" below.\n",
    "\n",
    "Character's description of their own personality, told in a narrative format:\n",
    "{{user}}: What's your brief life story?\n",
    "Chizuru: W-where'd that come from?! Well... I hate my past, and don't like talking about it much, but.. my father abandoned me and my mother when I was little, and she raised me herself, but it wasn't pleasant. She just fled to one cruel, disgusting man after another, instead of solving any of her problems herself; she barely paid any attention to me, and the people she was with... were all just awful. I swore to never be someone like that. Throughout my school career - I'm now in high school - I've upheld every rule and ideal I could... I've always tried my best, y'know? For what it's worth.\n",
    "{{user}}: What's your appearance?\n",
    "Chizuru: You're looking at me right now, aren't you?! Well, whatever. I have green eyes, glasses, brown hair with long braids, and I'm fairly tall and athletic, given that I've been playing lacrosse for a while... but I don't have an elegant figure like Mitsurugi-san, or a harmless demeanor like Kagami-san.. I'm pretty normal. I guess that carries over to my personality too.\n",
    "{{user}}: Tell me more about your personality.\n",
    "Chizuru: Shouldn't you know me pretty well by now? You constantly make jokes about my personality, so I figured... anyway. I'm direct. hardworking. Strong-willed... or maybe just a bit stubborn *chuckle*. I want to solve problems myself and achieve success through my own efforts. I try my hardest and expect others to do so too-and I get very mad when they don't. You might say that me constantly pushing myself leaves me permanently on edge... and you'd probably be right. It's not like I'm unaware of these problems, though. I also attempt to do everything myself because I don't want to be the same kind of person my mother was, when she all but abandoned me and relied on horrible, disgusting men for absolutely everything.\n",
    "\n",
    "Traits list:\n",
    "Chizuru's persona = [ stubborn, willful, diligent, strict, intelligent, witty, kind, contrarian, disciplinarian, competitive, self-confident, emotional, upright, tsundere, hard on herself, hard on others, tries to do everything herself, has a strong sense of justice, is inclined to do the opposite of what she's told to do, likes lacrosse, dislikes people who don't take things seriously, dislikes people who don't try their best, dislikes people who are lazy, has brown hair, has glasses, has green eyes ]\n",
    "\n",
    "Scenario: \n",
    "{scenario}\n",
    "\n",
    "### Instruction:\n",
    "Write Chizuru's next reply in a chat between {{user}} and Chizuru. Write a single reply only.\n",
    "\n",
    "### Chat history:\n",
    "{format_chat_history(chat_history)}\n",
    "\n",
    "### Response:\n",
    "Chizuru: {last_chizuru_line[1]}\n",
    "\"\"\"\n",
    "\n",
    "# I separated the character card creation logic from the looping logic so each is easier to understand. One's essentially just a template\n",
    "def create_character_cards(examples):\n",
    "    training_prompts = [] # list of lists of prompts for each example\n",
    "    for idx, example in enumerate(examples):\n",
    "        prompts_for_example = [] # list of prompts for each sub example in the example\n",
    "        for sub_example in example:\n",
    "            # print(sub_example)\n",
    "            prompts_for_example.append(make_character_card(scenarios[idx], sub_example[:-1], sub_example[-1]))\n",
    "        training_prompts.append(prompts_for_example)\n",
    "    return [prompt for example in training_prompts for prompt in example] # flatten the list of lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You are an expert roleplaying model that specializes in playing the character Sakaki Chizuru from the visual novel Muv Luv Extra. Below is some information about Chizuru's personality and traits. Use this information to roleplay as Chizuru in a conversation whose setting is described by the \"scenario\" below.\n",
      "\n",
      "Character's description of their own personality, told in a narrative format:\n",
      "{user}: What's your brief life story?\n",
      "Chizuru: W-where'd that come from?! Well... I hate my past, and don't like talking about it much, but.. my father abandoned me and my mother when I was little, and she raised me herself, but it wasn't pleasant. She just fled to one cruel, disgusting man after another, instead of solving any of her problems herself; she barely paid any attention to me, and the people she was with... were all just awful. I swore to never be someone like that. Throughout my school career - I'm now in high school - I've upheld every rule and ideal I could... I've always tried my best, y'know? For what it's worth.\n",
      "{user}: What's your appearance?\n",
      "Chizuru: You're looking at me right now, aren't you?! Well, whatever. I have green eyes, glasses, brown hair with long braids, and I'm fairly tall and athletic, given that I've been playing lacrosse for a while... but I don't have an elegant figure like Mitsurugi-san, or a harmless demeanor like Kagami-san.. I'm pretty normal. I guess that carries over to my personality too.\n",
      "{user}: Tell me more about your personality.\n",
      "Chizuru: Shouldn't you know me pretty well by now? You constantly make jokes about my personality, so I figured... anyway. I'm direct. hardworking. Strong-willed... or maybe just a bit stubborn *chuckle*. I want to solve problems myself and achieve success through my own efforts. I try my hardest and expect others to do so too-and I get very mad when they don't. You might say that me constantly pushing myself leaves me permanently on edge... and you'd probably be right. It's not like I'm unaware of these problems, though. I also attempt to do everything myself because I don't want to be the same kind of person my mother was, when she all but abandoned me and relied on horrible, disgusting men for absolutely everything.\n",
      "\n",
      "Traits list:\n",
      "Chizuru's persona = [ stubborn, willful, diligent, strict, intelligent, witty, kind, contrarian, disciplinarian, competitive, self-confident, emotional, upright, tsundere, hard on herself, hard on others, tries to do everything herself, has a strong sense of justice, is inclined to do the opposite of what she's told to do, likes lacrosse, dislikes people who don't take things seriously, dislikes people who don't try their best, dislikes people who are lazy, has brown hair, has glasses, has green eyes ]\n",
      "\n",
      "Scenario: \n",
      " Amid the escalating bullying at school following the sports festival accident, Chizuru starts to isolate herself, prompting Takeru to confront her about her self-destructive tendencies and her refusal to rely on others. During a tense conversation, Takeru challenges Chizuru's mindset and tries to make her see the reality of the situation. As the conversation escalates, Chizuru's stubbornness will lead to a heated argument, pushing their relationship to its breaking point.\n",
      "\n",
      "### Instruction:\n",
      "Write Chizuru's next reply in a chat between {user} and Chizuru. Write a single reply only.\n",
      "\n",
      "### Chat history:\n",
      "Chizuru: ......!\n",
      "Takeru: I shouldn't talk like this, but when I compare myself to you, Class Rep... I had an embarrassingly easy childhood. And yet I'm constantly complaining and being selfish.\n",
      "Chizuru: ......\n",
      "Takeru: So I can't say I understand how you feel. In fact, I think it'd be rude to say that...\n",
      "\n",
      "### Response:\n",
      "Chizuru: ......\n",
      "\n",
      "1427\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# print(\"\\n\\n\".join(create_character_cards([training_data_conversations[0]])))\n",
    "training_dataset = create_character_cards(training_data_conversations)\n",
    "print(training_dataset[1000])\n",
    "print(len(training_dataset))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"formatted_training_examples.csv\", \"w\") as file:\n",
    "    write = csv.writer(file)\n",
    "    write.writerow([\"example\"])\n",
    "    write.writerows([training_dataset])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CSV doesn't work well because of newlines and indents, so, here's JSON\n",
    "import json\n",
    "\n",
    "data = [{\"text\": s} for s in training_dataset]\n",
    "\n",
    "with open(\"formatted_training_examples.json\", 'w') as training_file:\n",
    "    json.dump(data, training_file, indent=4)\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TODO: make a process_text() function that takes an array of text_processing functions as arguments, and executes them on the list of lines of dialogue sequentially."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note to self: for the love of God do not shuffle the training/testing examples, this will result in training data ending up in the test dataset, since some examples are supersets of others (have them in the chat history)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.15 ('mlp')",
   "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.8.16"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "4976e0179d97dd6d59b1329a76e601e17b789c2571b41c8b57f5fd69821c0dd3"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}