File size: 50,556 Bytes
391de07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d9fec777",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ba0578d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "books = pd.read_csv(\"books_with_categories.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "547ef724",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0184c98f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Device set to use cuda\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[[{'label': 'joy', 'score': 0.9771687984466553},\n",
       "  {'label': 'surprise', 'score': 0.008528684265911579},\n",
       "  {'label': 'neutral', 'score': 0.005764602683484554},\n",
       "  {'label': 'anger', 'score': 0.004419787786900997},\n",
       "  {'label': 'sadness', 'score': 0.0020923942793160677},\n",
       "  {'label': 'disgust', 'score': 0.0016119946958497167},\n",
       "  {'label': 'fear', 'score': 0.0004138521908316761}]]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import pipeline\n",
    "classifier = pipeline(\"text-classification\", \n",
    "                      model=\"j-hartmann/emotion-english-distilroberta-base\",\n",
    "                      top_k = None,\n",
    "                      device = \"cuda\")\n",
    "classifier(\"I love this!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ab7b7c6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'A NOVEL THAT READERS and critics have been eagerly anticipating for over a decade, Gilead is an astonishingly imagined story of remarkable lives. John Ames is a preacher, the son of a preacher and the grandson (both maternal and paternal) of preachers. It’s 1956 in Gilead, Iowa, towards the end of the Reverend Ames’s life, and he is absorbed in recording his family’s story, a legacy for the young son he will never see grow up. Haunted by his grandfather’s presence, John tells of the rift between his grandfather and his father: the elder, an angry visionary who fought for the abolitionist cause, and his son, an ardent pacifist. He is troubled, too, by his prodigal namesake, Jack (John Ames) Boughton, his best friend’s lost son who returns to Gilead searching for forgiveness and redemption. Told in John Ames’s joyous, rambling voice that finds beauty, humour and truth in the smallest of life’s details, Gilead is a song of celebration and acceptance of the best and the worst the world has to offer. At its heart is a tale of the sacred bonds between fathers and sons, pitch-perfect in style and story, set to dazzle critics and readers alike.'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "books[\"description\"][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "80d70c9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[{'label': 'fear', 'score': 0.6548407673835754},\n",
       "  {'label': 'neutral', 'score': 0.16985219717025757},\n",
       "  {'label': 'sadness', 'score': 0.11640916764736176},\n",
       "  {'label': 'surprise', 'score': 0.020700708031654358},\n",
       "  {'label': 'disgust', 'score': 0.019100721925497055},\n",
       "  {'label': 'joy', 'score': 0.01516129169613123},\n",
       "  {'label': 'anger', 'score': 0.0039351508021354675}]]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classifier(books[\"description\"][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d8c6e560",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[{'label': 'surprise', 'score': 0.7296026349067688},\n",
       "  {'label': 'neutral', 'score': 0.14038565754890442},\n",
       "  {'label': 'fear', 'score': 0.0681622102856636},\n",
       "  {'label': 'joy', 'score': 0.047942474484443665},\n",
       "  {'label': 'anger', 'score': 0.009156355634331703},\n",
       "  {'label': 'disgust', 'score': 0.002628473797813058},\n",
       "  {'label': 'sadness', 'score': 0.002122160280123353}],\n",
       " [{'label': 'neutral', 'score': 0.4493710994720459},\n",
       "  {'label': 'disgust', 'score': 0.27359139919281006},\n",
       "  {'label': 'joy', 'score': 0.10908272117376328},\n",
       "  {'label': 'sadness', 'score': 0.09362725168466568},\n",
       "  {'label': 'anger', 'score': 0.04047825187444687},\n",
       "  {'label': 'surprise', 'score': 0.026970187202095985},\n",
       "  {'label': 'fear', 'score': 0.006879056338220835}],\n",
       " [{'label': 'neutral', 'score': 0.6462168097496033},\n",
       "  {'label': 'sadness', 'score': 0.24273255467414856},\n",
       "  {'label': 'disgust', 'score': 0.04342259094119072},\n",
       "  {'label': 'surprise', 'score': 0.028300529345870018},\n",
       "  {'label': 'joy', 'score': 0.014211456291377544},\n",
       "  {'label': 'fear', 'score': 0.01408409047871828},\n",
       "  {'label': 'anger', 'score': 0.011031880043447018}],\n",
       " [{'label': 'fear', 'score': 0.9281679391860962},\n",
       "  {'label': 'anger', 'score': 0.03219100087881088},\n",
       "  {'label': 'neutral', 'score': 0.012808752246201038},\n",
       "  {'label': 'sadness', 'score': 0.00875688437372446},\n",
       "  {'label': 'surprise', 'score': 0.008597937412559986},\n",
       "  {'label': 'disgust', 'score': 0.008431863971054554},\n",
       "  {'label': 'joy', 'score': 0.0010455828160047531}],\n",
       " [{'label': 'sadness', 'score': 0.9671575427055359},\n",
       "  {'label': 'neutral', 'score': 0.015104170888662338},\n",
       "  {'label': 'disgust', 'score': 0.006480599287897348},\n",
       "  {'label': 'fear', 'score': 0.0053939977660775185},\n",
       "  {'label': 'surprise', 'score': 0.0022869440726935863},\n",
       "  {'label': 'anger', 'score': 0.0018428928451612592},\n",
       "  {'label': 'joy', 'score': 0.0017338799079880118}],\n",
       " [{'label': 'joy', 'score': 0.9327967166900635},\n",
       "  {'label': 'disgust', 'score': 0.037718113511800766},\n",
       "  {'label': 'neutral', 'score': 0.015892023220658302},\n",
       "  {'label': 'sadness', 'score': 0.006444575730711222},\n",
       "  {'label': 'anger', 'score': 0.005025049671530724},\n",
       "  {'label': 'surprise', 'score': 0.0015812116907909513},\n",
       "  {'label': 'fear', 'score': 0.0005423118127509952}],\n",
       " [{'label': 'joy', 'score': 0.6528710126876831},\n",
       "  {'label': 'neutral', 'score': 0.2542743384838104},\n",
       "  {'label': 'surprise', 'score': 0.06808304786682129},\n",
       "  {'label': 'sadness', 'score': 0.00990898534655571},\n",
       "  {'label': 'disgust', 'score': 0.006512206979095936},\n",
       "  {'label': 'anger', 'score': 0.004821315407752991},\n",
       "  {'label': 'fear', 'score': 0.003529016859829426}],\n",
       " [{'label': 'neutral', 'score': 0.5494765043258667},\n",
       "  {'label': 'sadness', 'score': 0.1116902157664299},\n",
       "  {'label': 'disgust', 'score': 0.10400670766830444},\n",
       "  {'label': 'surprise', 'score': 0.07876554876565933},\n",
       "  {'label': 'anger', 'score': 0.0641336739063263},\n",
       "  {'label': 'fear', 'score': 0.05136284604668617},\n",
       "  {'label': 'joy', 'score': 0.04056443274021149}]]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classifier(books[\"description\"][0].split(\".\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ecd96f5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sentences = books[\"description\"][0].split(\".\")\n",
    "predictions = classifier(sentences)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "395f13c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'A NOVEL THAT READERS and critics have been eagerly anticipating for over a decade, Gilead is an astonishingly imagined story of remarkable lives'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentences[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0f136f0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'label': 'surprise', 'score': 0.7296026349067688},\n",
       " {'label': 'neutral', 'score': 0.14038565754890442},\n",
       " {'label': 'fear', 'score': 0.0681622102856636},\n",
       " {'label': 'joy', 'score': 0.047942474484443665},\n",
       " {'label': 'anger', 'score': 0.009156355634331703},\n",
       " {'label': 'disgust', 'score': 0.002628473797813058},\n",
       " {'label': 'sadness', 'score': 0.002122160280123353}]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5468ffde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' Haunted by his grandfather’s presence, John tells of the rift between his grandfather and his father: the elder, an angry visionary who fought for the abolitionist cause, and his son, an ardent pacifist'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentences[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4cec13a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'label': 'fear', 'score': 0.9281679391860962},\n",
       " {'label': 'anger', 'score': 0.03219100087881088},\n",
       " {'label': 'neutral', 'score': 0.012808752246201038},\n",
       " {'label': 'sadness', 'score': 0.00875688437372446},\n",
       " {'label': 'surprise', 'score': 0.008597937412559986},\n",
       " {'label': 'disgust', 'score': 0.008431863971054554},\n",
       " {'label': 'joy', 'score': 0.0010455828160047531}]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "08252ce7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[{'label': 'surprise', 'score': 0.7296026349067688},\n",
       "  {'label': 'neutral', 'score': 0.14038565754890442},\n",
       "  {'label': 'fear', 'score': 0.0681622102856636},\n",
       "  {'label': 'joy', 'score': 0.047942474484443665},\n",
       "  {'label': 'anger', 'score': 0.009156355634331703},\n",
       "  {'label': 'disgust', 'score': 0.002628473797813058},\n",
       "  {'label': 'sadness', 'score': 0.002122160280123353}],\n",
       " [{'label': 'neutral', 'score': 0.4493710994720459},\n",
       "  {'label': 'disgust', 'score': 0.27359139919281006},\n",
       "  {'label': 'joy', 'score': 0.10908272117376328},\n",
       "  {'label': 'sadness', 'score': 0.09362725168466568},\n",
       "  {'label': 'anger', 'score': 0.04047825187444687},\n",
       "  {'label': 'surprise', 'score': 0.026970187202095985},\n",
       "  {'label': 'fear', 'score': 0.006879056338220835}],\n",
       " [{'label': 'neutral', 'score': 0.6462168097496033},\n",
       "  {'label': 'sadness', 'score': 0.24273255467414856},\n",
       "  {'label': 'disgust', 'score': 0.04342259094119072},\n",
       "  {'label': 'surprise', 'score': 0.028300529345870018},\n",
       "  {'label': 'joy', 'score': 0.014211456291377544},\n",
       "  {'label': 'fear', 'score': 0.01408409047871828},\n",
       "  {'label': 'anger', 'score': 0.011031880043447018}],\n",
       " [{'label': 'fear', 'score': 0.9281679391860962},\n",
       "  {'label': 'anger', 'score': 0.03219100087881088},\n",
       "  {'label': 'neutral', 'score': 0.012808752246201038},\n",
       "  {'label': 'sadness', 'score': 0.00875688437372446},\n",
       "  {'label': 'surprise', 'score': 0.008597937412559986},\n",
       "  {'label': 'disgust', 'score': 0.008431863971054554},\n",
       "  {'label': 'joy', 'score': 0.0010455828160047531}],\n",
       " [{'label': 'sadness', 'score': 0.9671575427055359},\n",
       "  {'label': 'neutral', 'score': 0.015104170888662338},\n",
       "  {'label': 'disgust', 'score': 0.006480599287897348},\n",
       "  {'label': 'fear', 'score': 0.0053939977660775185},\n",
       "  {'label': 'surprise', 'score': 0.0022869440726935863},\n",
       "  {'label': 'anger', 'score': 0.0018428928451612592},\n",
       "  {'label': 'joy', 'score': 0.0017338799079880118}],\n",
       " [{'label': 'joy', 'score': 0.9327967166900635},\n",
       "  {'label': 'disgust', 'score': 0.037718113511800766},\n",
       "  {'label': 'neutral', 'score': 0.015892023220658302},\n",
       "  {'label': 'sadness', 'score': 0.006444575730711222},\n",
       "  {'label': 'anger', 'score': 0.005025049671530724},\n",
       "  {'label': 'surprise', 'score': 0.0015812116907909513},\n",
       "  {'label': 'fear', 'score': 0.0005423118127509952}],\n",
       " [{'label': 'joy', 'score': 0.6528710126876831},\n",
       "  {'label': 'neutral', 'score': 0.2542743384838104},\n",
       "  {'label': 'surprise', 'score': 0.06808304786682129},\n",
       "  {'label': 'sadness', 'score': 0.00990898534655571},\n",
       "  {'label': 'disgust', 'score': 0.006512206979095936},\n",
       "  {'label': 'anger', 'score': 0.004821315407752991},\n",
       "  {'label': 'fear', 'score': 0.003529016859829426}],\n",
       " [{'label': 'neutral', 'score': 0.5494765043258667},\n",
       "  {'label': 'sadness', 'score': 0.1116902157664299},\n",
       "  {'label': 'disgust', 'score': 0.10400670766830444},\n",
       "  {'label': 'surprise', 'score': 0.07876554876565933},\n",
       "  {'label': 'anger', 'score': 0.0641336739063263},\n",
       "  {'label': 'fear', 'score': 0.05136284604668617},\n",
       "  {'label': 'joy', 'score': 0.04056443274021149}]]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e76fc604",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'label': 'anger', 'score': 0.009156355634331703},\n",
       " {'label': 'disgust', 'score': 0.002628473797813058},\n",
       " {'label': 'fear', 'score': 0.0681622102856636},\n",
       " {'label': 'joy', 'score': 0.047942474484443665},\n",
       " {'label': 'neutral', 'score': 0.14038565754890442},\n",
       " {'label': 'sadness', 'score': 0.002122160280123353},\n",
       " {'label': 'surprise', 'score': 0.7296026349067688}]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(predictions[0], key = lambda x:x[\"label\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "bb49276c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "emotion_labels = [\"anger\", \"disgust\", \"fear\", \"joy\", \"sadness\", \"surprise\", \"neutral\"]\n",
    "isbn = []\n",
    "emotion_scores = {label: [] for label in emotion_labels}\n",
    "\n",
    "def calculate_max_emotion_score(predictions):\n",
    "    per_emotion_scores = {label:[] for label in emotion_labels}\n",
    "    for prediction in predictions:\n",
    "        sorted_predictions = sorted(prediction, key = lambda x: x[\"label\"])\n",
    "        for index, label in enumerate(emotion_labels):\n",
    "            per_emotion_scores[label].append(sorted_predictions[index][\"score\"])\n",
    "    return {label: np.max(scores) for label, scores in per_emotion_scores.items()}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e3fc36a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "You seem to be using the pipelines sequentially on GPU. In order to maximize efficiency please use a dataset\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    isbn.append(books[\"isbn13\"][i])\n",
    "    sentences = books[\"description\"][0].split(\".\")\n",
    "    predictions = classifier(sentences)\n",
    "    max_scores = calculate_max_emotion_score(predictions)\n",
    "    for label in emotion_labels:\n",
    "        emotion_scores[label].append(max_scores[label])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a5ea90b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'anger': [np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263),\n",
       "  np.float64(0.0641336739063263)],\n",
       " 'disgust': [np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006),\n",
       "  np.float64(0.27359139919281006)],\n",
       " 'fear': [np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962),\n",
       "  np.float64(0.9281679391860962)],\n",
       " 'joy': [np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635),\n",
       "  np.float64(0.9327967166900635)],\n",
       " 'sadness': [np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033),\n",
       "  np.float64(0.6462168097496033)],\n",
       " 'surprise': [np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359),\n",
       "  np.float64(0.9671575427055359)],\n",
       " 'neutral': [np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688),\n",
       "  np.float64(0.7296026349067688)]}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "emotion_scores"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5b2ca76f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 5197/5197 [01:58<00:00, 43.92it/s]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from tqdm import tqdm\n",
    "\n",
    "emotion_labels = [\"anger\", \"disgust\", \"fear\", \"joy\", \"sadness\", \"surprise\", \"neutral\"]\n",
    "isbn = []\n",
    "emotion_scores = {label: [] for label in emotion_labels}\n",
    "\n",
    "for i in tqdm(range(len(books))):\n",
    "    isbn.append(books[\"isbn13\"][i])\n",
    "    sentences = books[\"description\"][i].split(\".\")\n",
    "    predictions = classifier(sentences)\n",
    "    max_scores = calculate_max_emotion_score(predictions)\n",
    "    for label in emotion_labels:\n",
    "        emotion_scores[label].append(max_scores[label])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "f69ecf48",
   "metadata": {},
   "outputs": [],
   "source": [
    "emotions_df = pd.DataFrame(emotion_scores)\n",
    "emotions_df[\"isbn13\"] = isbn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "f74c27e0",
   "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>anger</th>\n",
       "      <th>disgust</th>\n",
       "      <th>fear</th>\n",
       "      <th>joy</th>\n",
       "      <th>sadness</th>\n",
       "      <th>surprise</th>\n",
       "      <th>neutral</th>\n",
       "      <th>isbn13</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.273591</td>\n",
       "      <td>0.928168</td>\n",
       "      <td>0.932797</td>\n",
       "      <td>0.646217</td>\n",
       "      <td>0.967158</td>\n",
       "      <td>0.729603</td>\n",
       "      <td>9780002005883</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.612619</td>\n",
       "      <td>0.348285</td>\n",
       "      <td>0.942528</td>\n",
       "      <td>0.704421</td>\n",
       "      <td>0.887939</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.252545</td>\n",
       "      <td>9780002261982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.972321</td>\n",
       "      <td>0.767236</td>\n",
       "      <td>0.549477</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "      <td>9780006178736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.351483</td>\n",
       "      <td>0.150722</td>\n",
       "      <td>0.360707</td>\n",
       "      <td>0.251881</td>\n",
       "      <td>0.732685</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "      <td>9780006280897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.081412</td>\n",
       "      <td>0.184495</td>\n",
       "      <td>0.095043</td>\n",
       "      <td>0.040564</td>\n",
       "      <td>0.884389</td>\n",
       "      <td>0.475881</td>\n",
       "      <td>0.078766</td>\n",
       "      <td>9780006280934</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",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5192</th>\n",
       "      <td>0.148209</td>\n",
       "      <td>0.030643</td>\n",
       "      <td>0.919165</td>\n",
       "      <td>0.255169</td>\n",
       "      <td>0.853721</td>\n",
       "      <td>0.980877</td>\n",
       "      <td>0.030656</td>\n",
       "      <td>9788172235222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5193</th>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.114383</td>\n",
       "      <td>0.051363</td>\n",
       "      <td>0.400263</td>\n",
       "      <td>0.883199</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.227765</td>\n",
       "      <td>9788173031014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5194</th>\n",
       "      <td>0.009997</td>\n",
       "      <td>0.009929</td>\n",
       "      <td>0.339218</td>\n",
       "      <td>0.947779</td>\n",
       "      <td>0.375755</td>\n",
       "      <td>0.066685</td>\n",
       "      <td>0.057625</td>\n",
       "      <td>9788179921623</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5195</th>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.459269</td>\n",
       "      <td>0.759456</td>\n",
       "      <td>0.951104</td>\n",
       "      <td>0.368111</td>\n",
       "      <td>0.078766</td>\n",
       "      <td>9788185300535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5196</th>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.051363</td>\n",
       "      <td>0.958549</td>\n",
       "      <td>0.915193</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "      <td>9789027712059</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5197 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         anger   disgust      fear       joy   sadness  surprise   neutral  \\\n",
       "0     0.064134  0.273591  0.928168  0.932797  0.646217  0.967158  0.729603   \n",
       "1     0.612619  0.348285  0.942528  0.704421  0.887939  0.111690  0.252545   \n",
       "2     0.064134  0.104007  0.972321  0.767236  0.549477  0.111690  0.078766   \n",
       "3     0.351483  0.150722  0.360707  0.251881  0.732685  0.111690  0.078766   \n",
       "4     0.081412  0.184495  0.095043  0.040564  0.884389  0.475881  0.078766   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "5192  0.148209  0.030643  0.919165  0.255169  0.853721  0.980877  0.030656   \n",
       "5193  0.064134  0.114383  0.051363  0.400263  0.883199  0.111690  0.227765   \n",
       "5194  0.009997  0.009929  0.339218  0.947779  0.375755  0.066685  0.057625   \n",
       "5195  0.064134  0.104007  0.459269  0.759456  0.951104  0.368111  0.078766   \n",
       "5196  0.064134  0.104007  0.051363  0.958549  0.915193  0.111690  0.078766   \n",
       "\n",
       "             isbn13  \n",
       "0     9780002005883  \n",
       "1     9780002261982  \n",
       "2     9780006178736  \n",
       "3     9780006280897  \n",
       "4     9780006280934  \n",
       "...             ...  \n",
       "5192  9788172235222  \n",
       "5193  9788173031014  \n",
       "5194  9788179921623  \n",
       "5195  9788185300535  \n",
       "5196  9789027712059  \n",
       "\n",
       "[5197 rows x 8 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "emotions_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "93f5ef26",
   "metadata": {},
   "outputs": [],
   "source": [
    "books = pd.merge(books, emotions_df, on = \"isbn13\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "88e9a111",
   "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>isbn13</th>\n",
       "      <th>isbn10</th>\n",
       "      <th>title</th>\n",
       "      <th>authors</th>\n",
       "      <th>categories</th>\n",
       "      <th>thumbnail</th>\n",
       "      <th>description</th>\n",
       "      <th>published_year</th>\n",
       "      <th>average_rating</th>\n",
       "      <th>num_pages</th>\n",
       "      <th>...</th>\n",
       "      <th>title_and_subtitle</th>\n",
       "      <th>tagged_description</th>\n",
       "      <th>simple_categories</th>\n",
       "      <th>anger</th>\n",
       "      <th>disgust</th>\n",
       "      <th>fear</th>\n",
       "      <th>joy</th>\n",
       "      <th>sadness</th>\n",
       "      <th>surprise</th>\n",
       "      <th>neutral</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9780002005883</td>\n",
       "      <td>0002005883</td>\n",
       "      <td>Gilead</td>\n",
       "      <td>Marilynne Robinson</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>http://books.google.com/books/content?id=KQZCP...</td>\n",
       "      <td>A NOVEL THAT READERS and critics have been eag...</td>\n",
       "      <td>2004.0</td>\n",
       "      <td>3.85</td>\n",
       "      <td>247.0</td>\n",
       "      <td>...</td>\n",
       "      <td>Gilead</td>\n",
       "      <td>9780002005883 A NOVEL THAT READERS and critics...</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.273591</td>\n",
       "      <td>0.928168</td>\n",
       "      <td>0.932797</td>\n",
       "      <td>0.646217</td>\n",
       "      <td>0.967158</td>\n",
       "      <td>0.729603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9780002261982</td>\n",
       "      <td>0002261987</td>\n",
       "      <td>Spider's Web</td>\n",
       "      <td>Charles Osborne;Agatha Christie</td>\n",
       "      <td>Detective and mystery stories</td>\n",
       "      <td>http://books.google.com/books/content?id=gA5GP...</td>\n",
       "      <td>A new 'Christie for Christmas' -- a full-lengt...</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>3.83</td>\n",
       "      <td>241.0</td>\n",
       "      <td>...</td>\n",
       "      <td>Spider's Web: A Novel</td>\n",
       "      <td>9780002261982 A new 'Christie for Christmas' -...</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>0.612619</td>\n",
       "      <td>0.348285</td>\n",
       "      <td>0.942528</td>\n",
       "      <td>0.704421</td>\n",
       "      <td>0.887939</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.252545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9780006178736</td>\n",
       "      <td>0006178731</td>\n",
       "      <td>Rage of angels</td>\n",
       "      <td>Sidney Sheldon</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>http://books.google.com/books/content?id=FKo2T...</td>\n",
       "      <td>A memorable, mesmerizing heroine Jennifer -- b...</td>\n",
       "      <td>1993.0</td>\n",
       "      <td>3.93</td>\n",
       "      <td>512.0</td>\n",
       "      <td>...</td>\n",
       "      <td>Rage of angels</td>\n",
       "      <td>9780006178736 A memorable, mesmerizing heroine...</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.972321</td>\n",
       "      <td>0.767236</td>\n",
       "      <td>0.549477</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9780006280897</td>\n",
       "      <td>0006280897</td>\n",
       "      <td>The Four Loves</td>\n",
       "      <td>Clive Staples Lewis</td>\n",
       "      <td>Christian life</td>\n",
       "      <td>http://books.google.com/books/content?id=XhQ5X...</td>\n",
       "      <td>Lewis' work on the nature of love divides love...</td>\n",
       "      <td>2002.0</td>\n",
       "      <td>4.15</td>\n",
       "      <td>170.0</td>\n",
       "      <td>...</td>\n",
       "      <td>The Four Loves</td>\n",
       "      <td>9780006280897 Lewis' work on the nature of lov...</td>\n",
       "      <td>Nonfiction</td>\n",
       "      <td>0.351483</td>\n",
       "      <td>0.150722</td>\n",
       "      <td>0.360707</td>\n",
       "      <td>0.251881</td>\n",
       "      <td>0.732685</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9780006280934</td>\n",
       "      <td>0006280935</td>\n",
       "      <td>The Problem of Pain</td>\n",
       "      <td>Clive Staples Lewis</td>\n",
       "      <td>Christian life</td>\n",
       "      <td>http://books.google.com/books/content?id=Kk-uV...</td>\n",
       "      <td>\"In The Problem of Pain, C.S. Lewis, one of th...</td>\n",
       "      <td>2002.0</td>\n",
       "      <td>4.09</td>\n",
       "      <td>176.0</td>\n",
       "      <td>...</td>\n",
       "      <td>The Problem of Pain</td>\n",
       "      <td>9780006280934 \"In The Problem of Pain, C.S. Le...</td>\n",
       "      <td>Nonfiction</td>\n",
       "      <td>0.081412</td>\n",
       "      <td>0.184495</td>\n",
       "      <td>0.095043</td>\n",
       "      <td>0.040564</td>\n",
       "      <td>0.884389</td>\n",
       "      <td>0.475881</td>\n",
       "      <td>0.078766</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",
       "      <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",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5192</th>\n",
       "      <td>9788172235222</td>\n",
       "      <td>8172235224</td>\n",
       "      <td>Mistaken Identity</td>\n",
       "      <td>Nayantara Sahgal</td>\n",
       "      <td>Indic fiction (English)</td>\n",
       "      <td>http://books.google.com/books/content?id=q-tKP...</td>\n",
       "      <td>On A Train Journey Home To North India After L...</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>2.93</td>\n",
       "      <td>324.0</td>\n",
       "      <td>...</td>\n",
       "      <td>Mistaken Identity</td>\n",
       "      <td>9788172235222 On A Train Journey Home To North...</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>0.148209</td>\n",
       "      <td>0.030643</td>\n",
       "      <td>0.919165</td>\n",
       "      <td>0.255169</td>\n",
       "      <td>0.853721</td>\n",
       "      <td>0.980877</td>\n",
       "      <td>0.030656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5193</th>\n",
       "      <td>9788173031014</td>\n",
       "      <td>8173031010</td>\n",
       "      <td>Journey to the East</td>\n",
       "      <td>Hermann Hesse</td>\n",
       "      <td>Adventure stories</td>\n",
       "      <td>http://books.google.com/books/content?id=rq6JP...</td>\n",
       "      <td>This book tells the tale of a man who goes on ...</td>\n",
       "      <td>2002.0</td>\n",
       "      <td>3.70</td>\n",
       "      <td>175.0</td>\n",
       "      <td>...</td>\n",
       "      <td>Journey to the East</td>\n",
       "      <td>9788173031014 This book tells the tale of a ma...</td>\n",
       "      <td>Nonfiction</td>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.114383</td>\n",
       "      <td>0.051363</td>\n",
       "      <td>0.400263</td>\n",
       "      <td>0.883199</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.227765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5194</th>\n",
       "      <td>9788179921623</td>\n",
       "      <td>817992162X</td>\n",
       "      <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
       "      <td>Robin Sharma</td>\n",
       "      <td>Health &amp; Fitness</td>\n",
       "      <td>http://books.google.com/books/content?id=c_7mf...</td>\n",
       "      <td>Wisdom to Create a Life of Passion, Purpose, a...</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>3.82</td>\n",
       "      <td>198.0</td>\n",
       "      <td>...</td>\n",
       "      <td>The Monk Who Sold His Ferrari: A Fable About F...</td>\n",
       "      <td>9788179921623 Wisdom to Create a Life of Passi...</td>\n",
       "      <td>Fiction</td>\n",
       "      <td>0.009997</td>\n",
       "      <td>0.009929</td>\n",
       "      <td>0.339218</td>\n",
       "      <td>0.947779</td>\n",
       "      <td>0.375755</td>\n",
       "      <td>0.066685</td>\n",
       "      <td>0.057625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5195</th>\n",
       "      <td>9788185300535</td>\n",
       "      <td>8185300534</td>\n",
       "      <td>I Am that</td>\n",
       "      <td>Sri Nisargadatta Maharaj;Sudhakar S. Dikshit</td>\n",
       "      <td>Philosophy</td>\n",
       "      <td>http://books.google.com/books/content?id=Fv_JP...</td>\n",
       "      <td>This collection of the timeless teachings of o...</td>\n",
       "      <td>1999.0</td>\n",
       "      <td>4.51</td>\n",
       "      <td>531.0</td>\n",
       "      <td>...</td>\n",
       "      <td>I Am that: Talks with Sri Nisargadatta Maharaj</td>\n",
       "      <td>9788185300535 This collection of the timeless ...</td>\n",
       "      <td>Nonfiction</td>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.459269</td>\n",
       "      <td>0.759456</td>\n",
       "      <td>0.951104</td>\n",
       "      <td>0.368111</td>\n",
       "      <td>0.078766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5196</th>\n",
       "      <td>9789027712059</td>\n",
       "      <td>9027712050</td>\n",
       "      <td>The Berlin Phenomenology</td>\n",
       "      <td>Georg Wilhelm Friedrich Hegel</td>\n",
       "      <td>History</td>\n",
       "      <td>http://books.google.com/books/content?id=Vy7Sk...</td>\n",
       "      <td>Since the three volume edition ofHegel's Philo...</td>\n",
       "      <td>1981.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>210.0</td>\n",
       "      <td>...</td>\n",
       "      <td>The Berlin Phenomenology</td>\n",
       "      <td>9789027712059 Since the three volume edition o...</td>\n",
       "      <td>Nonfiction</td>\n",
       "      <td>0.064134</td>\n",
       "      <td>0.104007</td>\n",
       "      <td>0.051363</td>\n",
       "      <td>0.958549</td>\n",
       "      <td>0.915193</td>\n",
       "      <td>0.111690</td>\n",
       "      <td>0.078766</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5197 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             isbn13      isbn10  \\\n",
       "0     9780002005883  0002005883   \n",
       "1     9780002261982  0002261987   \n",
       "2     9780006178736  0006178731   \n",
       "3     9780006280897  0006280897   \n",
       "4     9780006280934  0006280935   \n",
       "...             ...         ...   \n",
       "5192  9788172235222  8172235224   \n",
       "5193  9788173031014  8173031010   \n",
       "5194  9788179921623  817992162X   \n",
       "5195  9788185300535  8185300534   \n",
       "5196  9789027712059  9027712050   \n",
       "\n",
       "                                                  title  \\\n",
       "0                                                Gilead   \n",
       "1                                          Spider's Web   \n",
       "2                                        Rage of angels   \n",
       "3                                        The Four Loves   \n",
       "4                                   The Problem of Pain   \n",
       "...                                                 ...   \n",
       "5192                                  Mistaken Identity   \n",
       "5193                                Journey to the East   \n",
       "5194  The Monk Who Sold His Ferrari: A Fable About F...   \n",
       "5195                                          I Am that   \n",
       "5196                           The Berlin Phenomenology   \n",
       "\n",
       "                                           authors  \\\n",
       "0                               Marilynne Robinson   \n",
       "1                  Charles Osborne;Agatha Christie   \n",
       "2                                   Sidney Sheldon   \n",
       "3                              Clive Staples Lewis   \n",
       "4                              Clive Staples Lewis   \n",
       "...                                            ...   \n",
       "5192                              Nayantara Sahgal   \n",
       "5193                                 Hermann Hesse   \n",
       "5194                                  Robin Sharma   \n",
       "5195  Sri Nisargadatta Maharaj;Sudhakar S. Dikshit   \n",
       "5196                 Georg Wilhelm Friedrich Hegel   \n",
       "\n",
       "                         categories  \\\n",
       "0                           Fiction   \n",
       "1     Detective and mystery stories   \n",
       "2                           Fiction   \n",
       "3                    Christian life   \n",
       "4                    Christian life   \n",
       "...                             ...   \n",
       "5192        Indic fiction (English)   \n",
       "5193              Adventure stories   \n",
       "5194               Health & Fitness   \n",
       "5195                     Philosophy   \n",
       "5196                        History   \n",
       "\n",
       "                                              thumbnail  \\\n",
       "0     http://books.google.com/books/content?id=KQZCP...   \n",
       "1     http://books.google.com/books/content?id=gA5GP...   \n",
       "2     http://books.google.com/books/content?id=FKo2T...   \n",
       "3     http://books.google.com/books/content?id=XhQ5X...   \n",
       "4     http://books.google.com/books/content?id=Kk-uV...   \n",
       "...                                                 ...   \n",
       "5192  http://books.google.com/books/content?id=q-tKP...   \n",
       "5193  http://books.google.com/books/content?id=rq6JP...   \n",
       "5194  http://books.google.com/books/content?id=c_7mf...   \n",
       "5195  http://books.google.com/books/content?id=Fv_JP...   \n",
       "5196  http://books.google.com/books/content?id=Vy7Sk...   \n",
       "\n",
       "                                            description  published_year  \\\n",
       "0     A NOVEL THAT READERS and critics have been eag...          2004.0   \n",
       "1     A new 'Christie for Christmas' -- a full-lengt...          2000.0   \n",
       "2     A memorable, mesmerizing heroine Jennifer -- b...          1993.0   \n",
       "3     Lewis' work on the nature of love divides love...          2002.0   \n",
       "4     \"In The Problem of Pain, C.S. Lewis, one of th...          2002.0   \n",
       "...                                                 ...             ...   \n",
       "5192  On A Train Journey Home To North India After L...          2003.0   \n",
       "5193  This book tells the tale of a man who goes on ...          2002.0   \n",
       "5194  Wisdom to Create a Life of Passion, Purpose, a...          2003.0   \n",
       "5195  This collection of the timeless teachings of o...          1999.0   \n",
       "5196  Since the three volume edition ofHegel's Philo...          1981.0   \n",
       "\n",
       "      average_rating  num_pages  ...  \\\n",
       "0               3.85      247.0  ...   \n",
       "1               3.83      241.0  ...   \n",
       "2               3.93      512.0  ...   \n",
       "3               4.15      170.0  ...   \n",
       "4               4.09      176.0  ...   \n",
       "...              ...        ...  ...   \n",
       "5192            2.93      324.0  ...   \n",
       "5193            3.70      175.0  ...   \n",
       "5194            3.82      198.0  ...   \n",
       "5195            4.51      531.0  ...   \n",
       "5196            0.00      210.0  ...   \n",
       "\n",
       "                                     title_and_subtitle  \\\n",
       "0                                                Gilead   \n",
       "1                                 Spider's Web: A Novel   \n",
       "2                                        Rage of angels   \n",
       "3                                        The Four Loves   \n",
       "4                                   The Problem of Pain   \n",
       "...                                                 ...   \n",
       "5192                                  Mistaken Identity   \n",
       "5193                                Journey to the East   \n",
       "5194  The Monk Who Sold His Ferrari: A Fable About F...   \n",
       "5195     I Am that: Talks with Sri Nisargadatta Maharaj   \n",
       "5196                           The Berlin Phenomenology   \n",
       "\n",
       "                                     tagged_description simple_categories  \\\n",
       "0     9780002005883 A NOVEL THAT READERS and critics...           Fiction   \n",
       "1     9780002261982 A new 'Christie for Christmas' -...           Fiction   \n",
       "2     9780006178736 A memorable, mesmerizing heroine...           Fiction   \n",
       "3     9780006280897 Lewis' work on the nature of lov...        Nonfiction   \n",
       "4     9780006280934 \"In The Problem of Pain, C.S. Le...        Nonfiction   \n",
       "...                                                 ...               ...   \n",
       "5192  9788172235222 On A Train Journey Home To North...           Fiction   \n",
       "5193  9788173031014 This book tells the tale of a ma...        Nonfiction   \n",
       "5194  9788179921623 Wisdom to Create a Life of Passi...           Fiction   \n",
       "5195  9788185300535 This collection of the timeless ...        Nonfiction   \n",
       "5196  9789027712059 Since the three volume edition o...        Nonfiction   \n",
       "\n",
       "         anger   disgust      fear       joy   sadness  surprise   neutral  \n",
       "0     0.064134  0.273591  0.928168  0.932797  0.646217  0.967158  0.729603  \n",
       "1     0.612619  0.348285  0.942528  0.704421  0.887939  0.111690  0.252545  \n",
       "2     0.064134  0.104007  0.972321  0.767236  0.549477  0.111690  0.078766  \n",
       "3     0.351483  0.150722  0.360707  0.251881  0.732685  0.111690  0.078766  \n",
       "4     0.081412  0.184495  0.095043  0.040564  0.884389  0.475881  0.078766  \n",
       "...        ...       ...       ...       ...       ...       ...       ...  \n",
       "5192  0.148209  0.030643  0.919165  0.255169  0.853721  0.980877  0.030656  \n",
       "5193  0.064134  0.114383  0.051363  0.400263  0.883199  0.111690  0.227765  \n",
       "5194  0.009997  0.009929  0.339218  0.947779  0.375755  0.066685  0.057625  \n",
       "5195  0.064134  0.104007  0.459269  0.759456  0.951104  0.368111  0.078766  \n",
       "5196  0.064134  0.104007  0.051363  0.958549  0.915193  0.111690  0.078766  \n",
       "\n",
       "[5197 rows x 22 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "books"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "6e7c5bd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "books.to_csv(\"books_with_emotions.csv\", index = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "books_env",
   "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}