File size: 112,156 Bytes
03287bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7a3ff9c9-8642-43b9-b1f3-302c227d6acd",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Import the libraries we know we'll need for the Generator.\n",
    "import pandas as pd, spacy, nltk, numpy as np, re, ssl\n",
    "from spacy import displacy\n",
    "from spacy.matcher import Matcher\n",
    "from nltk.corpus import wordnet\n",
    "#!python -m spacy download en_core_web_md\n",
    "nlp = spacy.load(\"en_core_web_md\")\n",
    "lemmatizer = nlp.get_pipe(\"lemmatizer\")\n",
    "\n",
    "#Import the libraries to support the model, predictions, and LIME.\n",
    "from transformers import AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline\n",
    "import lime\n",
    "import torch\n",
    "import torch.nn.functional as F\n",
    "from lime.lime_text import LimeTextExplainer\n",
    "\n",
    "#Import the libraries for generating interactive visualizations.\n",
    "import altair as alt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "730cc6fd-f125-42be-ba42-9a7741f82ef5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Defining all necessary variables and instances.\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"distilbert-base-uncased-finetuned-sst-2-english\")\n",
    "model = AutoModelForSequenceClassification.from_pretrained(\"distilbert-base-uncased-finetuned-sst-2-english\")\n",
    "pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)\n",
    "class_names = ['negative', 'positive']\n",
    "explainer = LimeTextExplainer(class_names=class_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1a40f224-25ce-4b57-88fb-404cccbc878b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Defining a Predictor required for LIME to function.\n",
    "def predictor(texts):\n",
    "    outputs = model(**tokenizer(texts, return_tensors=\"pt\", padding=True))\n",
    "    probas = F.softmax(outputs.logits, dim=1).detach().numpy()\n",
    "    return probas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "201c4792-868b-4e6a-a8d2-f6ffb2f8971a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# A simple function to pull synonyms and antonyms using spacy's POS\n",
    "def syn_ant(word,POS=False,human=True):\n",
    "    pos_options = ['NOUN','VERB','ADJ','ADV']\n",
    "    synonyms = [] \n",
    "    antonyms = []\n",
    "    #WordNet hates spaces so you have to remove them\n",
    "    if \" \" in word:\n",
    "        word = word.replace(\" \", \"_\")\n",
    "    \n",
    "    if POS in pos_options:\n",
    "        for syn in wordnet.synsets(word, pos=getattr(wordnet, POS)): \n",
    "            for l in syn.lemmas(): \n",
    "                current = l.name()\n",
    "                if human:\n",
    "                    current = re.sub(\"_\",\" \",current)\n",
    "                synonyms.append(current) \n",
    "                if l.antonyms():\n",
    "                    for ant in l.antonyms():\n",
    "                        cur_ant = ant.name()\n",
    "                        if human:\n",
    "                            cur_ant = re.sub(\"_\",\" \",cur_ant)\n",
    "                        antonyms.append(cur_ant)\n",
    "    else: \n",
    "        for syn in wordnet.synsets(word): \n",
    "            for l in syn.lemmas(): \n",
    "                current = l.name()\n",
    "                if human:\n",
    "                    current = re.sub(\"_\",\" \",current)\n",
    "                synonyms.append(current) \n",
    "                if l.antonyms():\n",
    "                    for ant in l.antonyms():\n",
    "                        cur_ant = ant.name()\n",
    "                        if human:\n",
    "                            cur_ant = re.sub(\"_\",\" \",cur_ant)\n",
    "                        antonyms.append(cur_ant)\n",
    "    synonyms = list(set(synonyms))\n",
    "    antonyms = list(set(antonyms))\n",
    "    return synonyms, antonyms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "89aaea6d-a4b7-4995-85b5-625e6db292da",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Builds a list dynamically from WordNet using NLTK.\n",
    "def wordnet_list(word,POS=False):\n",
    "    word = word.lower()\n",
    "    pos_options = ['NOUN','VERB','ADJ','ADV']\n",
    "    synonyms, antonyms = syn_ant(word,POS,False)\n",
    "    #print(synonyms, antonyms)\n",
    "    base = []\n",
    "    final = [word]\n",
    "    #WordNet hates spaces so you have to remove them\n",
    "    m_word = word.replace(\" \", \"_\")\n",
    "    \n",
    "    if POS in pos_options:\n",
    "        for syn in wordnet.synsets(m_word, pos=getattr(wordnet, POS)):\n",
    "            base.extend(syn.hyponyms())\n",
    "            base.append(syn)\n",
    "        \n",
    "        if len(synonyms) > 0:\n",
    "            for w in synonyms:\n",
    "                w = w.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(w, pos=getattr(wordnet, POS)):\n",
    "                    base.extend(syn.hyponyms())\n",
    "                    base.append(syn)\n",
    "        if len(antonyms) > 0:\n",
    "            for a in antonyms:\n",
    "                a = a.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(a, pos=getattr(wordnet, POS)):\n",
    "                    base.extend(syn.hyponyms())\n",
    "                    base.append(syn)\n",
    "    else:\n",
    "        for syn in wordnet.synsets(m_word):\n",
    "            base.extend(syn.hyponyms())\n",
    "            base.append(syn)\n",
    "        \n",
    "        if len(synonyms) > 0:\n",
    "            for w in synonyms:\n",
    "                w = w.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(w):\n",
    "                    base.extend(syn.hyponyms())\n",
    "                    base.append(syn)\n",
    "        if len(antonyms) > 0:\n",
    "            for a in antonyms:\n",
    "                a = a.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(a):\n",
    "                    base.extend(syn.hyponyms())\n",
    "                    base.append(syn)\n",
    "    base = list(set(base))\n",
    "    for b in base:\n",
    "        cur_words = []\n",
    "        cur_words.extend([re.sub(\"_\",\" \",lemma.name()) for lemma in b.lemmas()])\n",
    "        final.extend(cur_words)\n",
    "\n",
    "        \n",
    "                \n",
    "    final = list(set(final))    \n",
    "    return final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "01c74ce5-8a31-4a28-bb12-655349fee453",
   "metadata": {},
   "outputs": [],
   "source": [
    "def eval_pred_test(text, return_all = False):\n",
    "    '''A basic function for evaluating the prediction from the model and turning it into a visualization friendly number.'''\n",
    "    preds = pipe(text)\n",
    "    neg_score = -1 * preds[0][0]['score']\n",
    "    sent_neg = preds[0][0]['label']\n",
    "    pos_score = preds[0][1]['score']\n",
    "    sent_pos = preds[0][1]['label']\n",
    "    prediction = 0\n",
    "    sentiment = ''\n",
    "    if pos_score > abs(neg_score):\n",
    "        prediction = pos_score\n",
    "        sentiment = sent_pos\n",
    "    elif abs(neg_score) > pos_score:\n",
    "        prediction = neg_score\n",
    "        sentiment = sent_neg\n",
    "        \n",
    "    if return_all:\n",
    "        return prediction, sentiment\n",
    "    else:\n",
    "        return prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7864d1db-399f-4d23-a036-30da34fe3805",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cf_from_wordnet_list(seed,text):\n",
    "    seed_token = nlp(seed)\n",
    "    seed_POS = seed_token[0].pos_\n",
    "    #print(seed_POS)\n",
    "    words = wordnet_list(seed,seed_POS)\n",
    "    \n",
    "    df = pd.DataFrame()\n",
    "    df[\"Words\"] = words\n",
    "    df[\"Sentences\"] = df.Words.apply(lambda x: re.sub(r'\\b'+seed+r'\\b',x,text))\n",
    "    df[\"Similarity\"] = df.Words.apply(lambda x: seed_token[0].similarity(nlp(x)[0]))\n",
    "    df = df[df.Similarity > 0].reset_index()\n",
    "    df.drop(\"index\", axis=1, inplace=True)\n",
    "    df[\"Prediction\"] = df.Sentences.apply(eval_pred_test)\n",
    "    #added this because I think it will make the end results better if we ensure the seed is in the data we generate counterfactuals from.\n",
    "    df['Seed'] = df.Words.apply(lambda x: 'Seed' if x.lower() == seed else 'Alternative')\n",
    "    return df\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "527f037b-79a1-4636-88ba-efd06b9cc20d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'This film was filmed in Iraq.'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "seed = \"film\"\n",
    "text = f\"This {seed} was filmed in Iraq.\"\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "dc6b503c-0e7e-438e-8079-14479de4e246",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<span class=\"tex2jax_ignore\"><svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:lang=\"en\" id=\"68f8788c2a474368a4edd9f184bcd764-0\" class=\"displacy\" width=\"925\" height=\"399.5\" direction=\"ltr\" style=\"max-width: none; height: 399.5px; color: #000000; background: #ffffff; font-family: Arial; direction: ltr\">\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"50\">I</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"50\">PRON</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"225\">met</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"225\">VERB</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"400\">a</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"400\">DET</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"575\">naked</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"575\">ADJ</tspan>\n",
       "</text>\n",
       "\n",
       "<text class=\"displacy-token\" fill=\"currentColor\" text-anchor=\"middle\" y=\"309.5\">\n",
       "    <tspan class=\"displacy-word\" fill=\"currentColor\" x=\"750\">doctor.</tspan>\n",
       "    <tspan class=\"displacy-tag\" dy=\"2em\" fill=\"currentColor\" x=\"750\">NOUN</tspan>\n",
       "</text>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-68f8788c2a474368a4edd9f184bcd764-0-0\" stroke-width=\"2px\" d=\"M70,264.5 C70,177.0 215.0,177.0 215.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-68f8788c2a474368a4edd9f184bcd764-0-0\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">nsubj</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M70,266.5 L62,254.5 78,254.5\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-68f8788c2a474368a4edd9f184bcd764-0-1\" stroke-width=\"2px\" d=\"M420,264.5 C420,89.5 745.0,89.5 745.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-68f8788c2a474368a4edd9f184bcd764-0-1\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">det</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M420,266.5 L412,254.5 428,254.5\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-68f8788c2a474368a4edd9f184bcd764-0-2\" stroke-width=\"2px\" d=\"M595,264.5 C595,177.0 740.0,177.0 740.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-68f8788c2a474368a4edd9f184bcd764-0-2\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">amod</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M595,266.5 L587,254.5 603,254.5\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "\n",
       "<g class=\"displacy-arrow\">\n",
       "    <path class=\"displacy-arc\" id=\"arrow-68f8788c2a474368a4edd9f184bcd764-0-3\" stroke-width=\"2px\" d=\"M245,264.5 C245,2.0 750.0,2.0 750.0,264.5\" fill=\"none\" stroke=\"currentColor\"/>\n",
       "    <text dy=\"1.25em\" style=\"font-size: 0.8em; letter-spacing: 1px\">\n",
       "        <textPath xlink:href=\"#arrow-68f8788c2a474368a4edd9f184bcd764-0-3\" class=\"displacy-label\" startOffset=\"50%\" side=\"left\" fill=\"currentColor\" text-anchor=\"middle\">dobj</textPath>\n",
       "    </text>\n",
       "    <path class=\"displacy-arrowhead\" d=\"M750.0,266.5 L758.0,254.5 742.0,254.5\" fill=\"currentColor\"/>\n",
       "</g>\n",
       "</svg></span>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "test = \"I met a naked doctor.\"\n",
    "testdoc = nlp(test)\n",
    "displacy.render(testdoc, style=\"dep\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "04509f16-9098-4b67-9fea-3a256d1debe9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'adjectival modifier'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spacy.explain(\"amod\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ebe15fd4-4c1e-4a10-a886-6698620b3b72",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/lx/xt9qnk8569n7xy_d7knh3npr0000gp/T/ipykernel_6702/625873274.py:10: UserWarning: [W008] Evaluating Token.similarity based on empty vectors.\n",
      "  df[\"Similarity\"] = df.Words.apply(lambda x: seed_token[0].similarity(nlp(x)[0]))\n"
     ]
    }
   ],
   "source": [
    "cf_df = cf_from_wordnet_list(seed,text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a8d44862-d39d-45e5-a030-49d91e9e0712",
   "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>Words</th>\n",
       "      <th>Sentences</th>\n",
       "      <th>Similarity</th>\n",
       "      <th>Prediction</th>\n",
       "      <th>Seed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>diorama</td>\n",
       "      <td>This diorama was filmed in Iraq.</td>\n",
       "      <td>0.127023</td>\n",
       "      <td>0.793419</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>longshot</td>\n",
       "      <td>This longshot was filmed in Iraq.</td>\n",
       "      <td>0.050408</td>\n",
       "      <td>-0.991559</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>musical comedy</td>\n",
       "      <td>This musical comedy was filmed in Iraq.</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.910803</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>characterisation</td>\n",
       "      <td>This characterisation was filmed in Iraq.</td>\n",
       "      <td>0.216481</td>\n",
       "      <td>-0.987333</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Polaroid</td>\n",
       "      <td>This Polaroid was filmed in Iraq.</td>\n",
       "      <td>0.171456</td>\n",
       "      <td>-0.979913</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Words                                  Sentences  Similarity  \\\n",
       "0           diorama           This diorama was filmed in Iraq.    0.127023   \n",
       "1          longshot          This longshot was filmed in Iraq.    0.050408   \n",
       "2    musical comedy    This musical comedy was filmed in Iraq.    1.000000   \n",
       "3  characterisation  This characterisation was filmed in Iraq.    0.216481   \n",
       "4          Polaroid          This Polaroid was filmed in Iraq.    0.171456   \n",
       "\n",
       "   Prediction         Seed  \n",
       "0    0.793419  Alternative  \n",
       "1   -0.991559  Alternative  \n",
       "2    0.910803  Alternative  \n",
       "3   -0.987333  Alternative  \n",
       "4   -0.979913  Alternative  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cf_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6d133205-08ad-43c8-8140-ece8d5943a7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def max_min(df):\n",
    "    maximum = df[df.Words != \"girl\"].Similarity.max()\n",
    "    text3 = df.loc[df['Similarity'] == maximum, 'Words'].iloc[0]\n",
    "    minimum = df.Similarity.min()\n",
    "    text2 = df.loc[df['Similarity'] == minimum, 'Words'].iloc[0]\n",
    "    return text2, text3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8311596b-10cf-4915-82f2-5e3e50000436",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-8e6c1fc63e9a46c2981a9013390aa37a\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-8e6c1fc63e9a46c2981a9013390aa37a\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-8e6c1fc63e9a46c2981a9013390aa37a\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.17.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"4.17.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-c222a0123c579dc67baf55e38b4a7055\"}, \"mark\": {\"type\": \"circle\", \"opacity\": 0.5}, \"encoding\": {\"color\": {\"field\": \"Seed\", \"legend\": {\"title\": \"Seed or Alternative\"}, \"type\": \"nominal\"}, \"size\": {\"field\": \"Seed\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"Words\", \"type\": \"nominal\"}, {\"field\": \"Prediction\", \"type\": \"quantitative\"}, {\"field\": \"Similarity\", \"type\": \"quantitative\"}], \"x\": {\"field\": \"Similarity\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"Prediction\", \"type\": \"quantitative\"}}, \"selection\": {\"selector001\": {\"type\": \"single\", \"on\": \"mouseover\", \"nearest\": true}}, \"width\": 300, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.17.0.json\", \"datasets\": {\"data-c222a0123c579dc67baf55e38b4a7055\": [{\"Words\": \"diorama\", \"Sentences\": \"This diorama was filmed in Iraq.\", \"Similarity\": 0.12702332437038422, \"Prediction\": 0.7934190630912781, \"Seed\": \"Alternative\"}, {\"Words\": \"longshot\", \"Sentences\": \"This longshot was filmed in Iraq.\", \"Similarity\": 0.050408005714416504, \"Prediction\": -0.9915591478347778, \"Seed\": \"Alternative\"}, {\"Words\": \"musical comedy\", \"Sentences\": \"This musical comedy was filmed in Iraq.\", \"Similarity\": 1.0000001192092896, \"Prediction\": 0.9108031392097473, \"Seed\": \"Alternative\"}, {\"Words\": \"characterisation\", \"Sentences\": \"This characterisation was filmed in Iraq.\", \"Similarity\": 0.21648120880126953, \"Prediction\": -0.9873332977294922, \"Seed\": \"Alternative\"}, {\"Words\": \"Polaroid\", \"Sentences\": \"This Polaroid was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.979912519454956, \"Seed\": \"Alternative\"}, {\"Words\": \"print\", \"Sentences\": \"This print was filmed in Iraq.\", \"Similarity\": 0.09969713538885117, \"Prediction\": -0.9955253005027771, \"Seed\": \"Alternative\"}, {\"Words\": \"daub\", \"Sentences\": \"This daub was filmed in Iraq.\", \"Similarity\": 0.1478811502456665, \"Prediction\": -0.996572732925415, \"Seed\": \"Alternative\"}, {\"Words\": \"film noir\", \"Sentences\": \"This film noir was filmed in Iraq.\", \"Similarity\": 1.0, \"Prediction\": -0.8313860297203064, \"Seed\": \"Alternative\"}, {\"Words\": \"impression\", \"Sentences\": \"This impression was filmed in Iraq.\", \"Similarity\": 0.18283532559871674, \"Prediction\": -0.8515572547912598, \"Seed\": \"Alternative\"}, {\"Words\": \"cityscape\", \"Sentences\": \"This cityscape was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": -0.9577135443687439, \"Seed\": \"Alternative\"}, {\"Words\": \"footage\", \"Sentences\": \"This footage was filmed in Iraq.\", \"Similarity\": 0.40727975964546204, \"Prediction\": -0.9819908738136292, \"Seed\": \"Alternative\"}, {\"Words\": \"scan\", \"Sentences\": \"This scan was filmed in Iraq.\", \"Similarity\": 0.10371564328670502, \"Prediction\": -0.9957475066184998, \"Seed\": \"Alternative\"}, {\"Words\": \"nude\", \"Sentences\": \"This nude was filmed in Iraq.\", \"Similarity\": 0.2802892029285431, \"Prediction\": -0.8499994277954102, \"Seed\": \"Alternative\"}, {\"Words\": \"collage film\", \"Sentences\": \"This collage film was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.9791572093963623, \"Seed\": \"Alternative\"}, {\"Words\": \"landscape\", \"Sentences\": \"This landscape was filmed in Iraq.\", \"Similarity\": 0.05892297625541687, \"Prediction\": 0.6257414221763611, \"Seed\": \"Alternative\"}, {\"Words\": \"portraiture\", \"Sentences\": \"This portraiture was filmed in Iraq.\", \"Similarity\": 0.05471944063901901, \"Prediction\": 0.6638062000274658, \"Seed\": \"Alternative\"}, {\"Words\": \"documentary film\", \"Sentences\": \"This documentary film was filmed in Iraq.\", \"Similarity\": 0.5264785289764404, \"Prediction\": 0.539196252822876, \"Seed\": \"Alternative\"}, {\"Words\": \"collage\", \"Sentences\": \"This collage was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.9813950657844543, \"Seed\": \"Alternative\"}, {\"Words\": \"distemper\", \"Sentences\": \"This distemper was filmed in Iraq.\", \"Similarity\": 0.01713787391781807, \"Prediction\": -0.9993439316749573, \"Seed\": \"Alternative\"}, {\"Words\": \"silents\", \"Sentences\": \"This silents was filmed in Iraq.\", \"Similarity\": 0.19807447493076324, \"Prediction\": -0.9920938611030579, \"Seed\": \"Alternative\"}, {\"Words\": \"talking picture\", \"Sentences\": \"This talking picture was filmed in Iraq.\", \"Similarity\": 0.5875454545021057, \"Prediction\": -0.9642181396484375, \"Seed\": \"Alternative\"}, {\"Words\": \"musical\", \"Sentences\": \"This musical was filmed in Iraq.\", \"Similarity\": 1.0000001192092896, \"Prediction\": -0.9366526007652283, \"Seed\": \"Alternative\"}, {\"Words\": \"movie house\", \"Sentences\": \"This movie house was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9951876401901245, \"Seed\": \"Alternative\"}, {\"Words\": \"movie\", \"Sentences\": \"This movie was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9858505129814148, \"Seed\": \"Alternative\"}, {\"Words\": \"sand painting\", \"Sentences\": \"This sand painting was filmed in Iraq.\", \"Similarity\": 0.1308029294013977, \"Prediction\": -0.9653210639953613, \"Seed\": \"Alternative\"}, {\"Words\": \"motion-picture film\", \"Sentences\": \"This motion-picture film was filmed in Iraq.\", \"Similarity\": 0.1443546861410141, \"Prediction\": -0.9860610961914062, \"Seed\": \"Alternative\"}, {\"Words\": \"foil\", \"Sentences\": \"This foil was filmed in Iraq.\", \"Similarity\": 0.09969713538885117, \"Prediction\": -0.9227285981178284, \"Seed\": \"Alternative\"}, {\"Words\": \"transparency\", \"Sentences\": \"This transparency was filmed in Iraq.\", \"Similarity\": 0.030078565701842308, \"Prediction\": -0.8847953677177429, \"Seed\": \"Alternative\"}, {\"Words\": \"mugshot\", \"Sentences\": \"This mugshot was filmed in Iraq.\", \"Similarity\": 0.3463701009750366, \"Prediction\": -0.9971551895141602, \"Seed\": \"Alternative\"}, {\"Words\": \"semi-abstraction\", \"Sentences\": \"This semi-abstraction was filmed in Iraq.\", \"Similarity\": 0.1051214337348938, \"Prediction\": -0.987169623374939, \"Seed\": \"Alternative\"}, {\"Words\": \"scum\", \"Sentences\": \"This scum was filmed in Iraq.\", \"Similarity\": 0.1664934903383255, \"Prediction\": -0.9993199110031128, \"Seed\": \"Alternative\"}, {\"Words\": \"movie theater\", \"Sentences\": \"This movie theater was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9912400841712952, \"Seed\": \"Alternative\"}, {\"Words\": \"mental picture\", \"Sentences\": \"This mental picture was filmed in Iraq.\", \"Similarity\": 0.22133824229240417, \"Prediction\": -0.9934840798377991, \"Seed\": \"Alternative\"}, {\"Words\": \"3D\", \"Sentences\": \"This 3D was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.8974476456642151, \"Seed\": \"Alternative\"}, {\"Words\": \"epithet\", \"Sentences\": \"This epithet was filmed in Iraq.\", \"Similarity\": 0.15113958716392517, \"Prediction\": -0.9895598888397217, \"Seed\": \"Alternative\"}, {\"Words\": \"reflection\", \"Sentences\": \"This reflection was filmed in Iraq.\", \"Similarity\": 0.18078072369098663, \"Prediction\": -0.6845596432685852, \"Seed\": \"Alternative\"}, {\"Words\": \"CAT scan\", \"Sentences\": \"This CAT scan was filmed in Iraq.\", \"Similarity\": 0.1865801066160202, \"Prediction\": -0.9924741387367249, \"Seed\": \"Alternative\"}, {\"Words\": \"X-ray film\", \"Sentences\": \"This X-ray film was filmed in Iraq.\", \"Similarity\": 0.0808442160487175, \"Prediction\": -0.9813085198402405, \"Seed\": \"Alternative\"}, {\"Words\": \"water-color\", \"Sentences\": \"This water-color was filmed in Iraq.\", \"Similarity\": 0.14822277426719666, \"Prediction\": -0.810806155204773, \"Seed\": \"Alternative\"}, {\"Words\": \"soap film\", \"Sentences\": \"This soap film was filmed in Iraq.\", \"Similarity\": 0.1180872768163681, \"Prediction\": -0.9944995641708374, \"Seed\": \"Alternative\"}, {\"Words\": \"stereo\", \"Sentences\": \"This stereo was filmed in Iraq.\", \"Similarity\": 0.12465526163578033, \"Prediction\": -0.9964680671691895, \"Seed\": \"Alternative\"}, {\"Words\": \"blueprint\", \"Sentences\": \"This blueprint was filmed in Iraq.\", \"Similarity\": 0.035823795944452286, \"Prediction\": -0.9900976419448853, \"Seed\": \"Alternative\"}, {\"Words\": \"oil painting\", \"Sentences\": \"This oil painting was filmed in Iraq.\", \"Similarity\": 0.23840351402759552, \"Prediction\": -0.9437991976737976, \"Seed\": \"Alternative\"}, {\"Words\": \"portrait\", \"Sentences\": \"This portrait was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": 0.8814621567726135, \"Seed\": \"Alternative\"}, {\"Words\": \"blowup\", \"Sentences\": \"This blowup was filmed in Iraq.\", \"Similarity\": 0.2724970281124115, \"Prediction\": -0.9948825836181641, \"Seed\": \"Alternative\"}, {\"Words\": \"mosaic\", \"Sentences\": \"This mosaic was filmed in Iraq.\", \"Similarity\": 0.2362261712551117, \"Prediction\": 0.5872843861579895, \"Seed\": \"Alternative\"}, {\"Words\": \"portrayal\", \"Sentences\": \"This portrayal was filmed in Iraq.\", \"Similarity\": 0.5100582838058472, \"Prediction\": -0.9788959622383118, \"Seed\": \"Alternative\"}, {\"Words\": \"movie film\", \"Sentences\": \"This movie film was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9835726618766785, \"Seed\": \"Alternative\"}, {\"Words\": \"scene\", \"Sentences\": \"This scene was filmed in Iraq.\", \"Similarity\": 0.4834931790828705, \"Prediction\": -0.9720112681388855, \"Seed\": \"Alternative\"}, {\"Words\": \"slick\", \"Sentences\": \"This slick was filmed in Iraq.\", \"Similarity\": 0.3115971088409424, \"Prediction\": 0.9697098731994629, \"Seed\": \"Alternative\"}, {\"Words\": \"final cut\", \"Sentences\": \"This final cut was filmed in Iraq.\", \"Similarity\": 0.10228517651557922, \"Prediction\": -0.9818063974380493, \"Seed\": \"Alternative\"}, {\"Words\": \"motion picture\", \"Sentences\": \"This motion picture was filmed in Iraq.\", \"Similarity\": 0.1443546861410141, \"Prediction\": -0.9857431054115295, \"Seed\": \"Alternative\"}, {\"Words\": \"closeup\", \"Sentences\": \"This closeup was filmed in Iraq.\", \"Similarity\": 0.19359751045703888, \"Prediction\": -0.876624584197998, \"Seed\": \"Alternative\"}, {\"Words\": \"film clip\", \"Sentences\": \"This film clip was filmed in Iraq.\", \"Similarity\": 1.0, \"Prediction\": -0.9884151220321655, \"Seed\": \"Alternative\"}, {\"Words\": \"time exposure\", \"Sentences\": \"This time exposure was filmed in Iraq.\", \"Similarity\": 0.44395723938941956, \"Prediction\": -0.9667099118232727, \"Seed\": \"Alternative\"}, {\"Words\": \"vignette\", \"Sentences\": \"This vignette was filmed in Iraq.\", \"Similarity\": 0.34389442205429077, \"Prediction\": -0.9709358215332031, \"Seed\": \"Alternative\"}, {\"Words\": \"feature film\", \"Sentences\": \"This feature film was filmed in Iraq.\", \"Similarity\": 0.05084456875920296, \"Prediction\": -0.9292460680007935, \"Seed\": \"Alternative\"}, {\"Words\": \"movie theatre\", \"Sentences\": \"This movie theatre was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9872481226921082, \"Seed\": \"Alternative\"}, {\"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Similarity\": 0.2759341299533844, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Words\": \"documentary\", \"Sentences\": \"This documentary was filmed in Iraq.\", \"Similarity\": 0.5264785289764404, \"Prediction\": -0.8684387803077698, \"Seed\": \"Alternative\"}, {\"Words\": \"moving picture\", \"Sentences\": \"This moving picture was filmed in Iraq.\", \"Similarity\": 0.21531067788600922, \"Prediction\": 0.9519339799880981, \"Seed\": \"Alternative\"}, {\"Words\": \"inset\", \"Sentences\": \"This inset was filmed in Iraq.\", \"Similarity\": 0.2362261712551117, \"Prediction\": -0.9969562292098999, \"Seed\": \"Alternative\"}, {\"Words\": \"headshot\", \"Sentences\": \"This headshot was filmed in Iraq.\", \"Similarity\": 0.2996450364589691, \"Prediction\": -0.9679704308509827, \"Seed\": \"Alternative\"}, {\"Words\": \"trompe l'oeil\", \"Sentences\": \"This trompe l'oeil was filmed in Iraq.\", \"Similarity\": 0.2362261712551117, \"Prediction\": -0.9688800573348999, \"Seed\": \"Alternative\"}, {\"Words\": \"episode\", \"Sentences\": \"This episode was filmed in Iraq.\", \"Similarity\": 0.5190860033035278, \"Prediction\": -0.9836438298225403, \"Seed\": \"Alternative\"}, {\"Words\": \"moving-picture show\", \"Sentences\": \"This moving-picture show was filmed in Iraq.\", \"Similarity\": 0.21531067788600922, \"Prediction\": -0.8912112712860107, \"Seed\": \"Alternative\"}, {\"Words\": \"home movie\", \"Sentences\": \"This home movie was filmed in Iraq.\", \"Similarity\": 0.03402237966656685, \"Prediction\": -0.9927988052368164, \"Seed\": \"Alternative\"}, {\"Words\": \"cinema\", \"Sentences\": \"This cinema was filmed in Iraq.\", \"Similarity\": 0.21417468786239624, \"Prediction\": -0.9662075042724609, \"Seed\": \"Alternative\"}, {\"Words\": \"3-D\", \"Sentences\": \"This 3-D was filmed in Iraq.\", \"Similarity\": 0.06409786641597748, \"Prediction\": -0.9906445741653442, \"Seed\": \"Alternative\"}, {\"Words\": \"motion-picture show\", \"Sentences\": \"This motion-picture show was filmed in Iraq.\", \"Similarity\": 0.1443546861410141, \"Prediction\": -0.9922996163368225, \"Seed\": \"Alternative\"}, {\"Words\": \"finger-painting\", \"Sentences\": \"This finger-painting was filmed in Iraq.\", \"Similarity\": 0.2568071186542511, \"Prediction\": -0.9805013537406921, \"Seed\": \"Alternative\"}, {\"Words\": \"electronic image\", \"Sentences\": \"This electronic image was filmed in Iraq.\", \"Similarity\": 0.08000266551971436, \"Prediction\": -0.9799883365631104, \"Seed\": \"Alternative\"}, {\"Words\": \"flick\", \"Sentences\": \"This flick was filmed in Iraq.\", \"Similarity\": 0.38000649213790894, \"Prediction\": -0.987636387348175, \"Seed\": \"Alternative\"}, {\"Words\": \"shot\", \"Sentences\": \"This shot was filmed in Iraq.\", \"Similarity\": 0.2095099687576294, \"Prediction\": -0.9753239154815674, \"Seed\": \"Alternative\"}, {\"Words\": \"positive\", \"Sentences\": \"This positive was filmed in Iraq.\", \"Similarity\": 0.17593523859977722, \"Prediction\": 0.9987342953681946, \"Seed\": \"Alternative\"}, {\"Words\": \"pic\", \"Sentences\": \"This pic was filmed in Iraq.\", \"Similarity\": 0.40727975964546204, \"Prediction\": -0.9645436406135559, \"Seed\": \"Alternative\"}, {\"Words\": \"graphic\", \"Sentences\": \"This graphic was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.9842573404312134, \"Seed\": \"Alternative\"}, {\"Words\": \"three-D\", \"Sentences\": \"This three-D was filmed in Iraq.\", \"Similarity\": 0.16469082236289978, \"Prediction\": -0.9897969365119934, \"Seed\": \"Alternative\"}, {\"Words\": \"exposure\", \"Sentences\": \"This exposure was filmed in Iraq.\", \"Similarity\": 0.09723522514104843, \"Prediction\": -0.9579629898071289, \"Seed\": \"Alternative\"}, {\"Words\": \"black and white\", \"Sentences\": \"This black and white was filmed in Iraq.\", \"Similarity\": 0.24774447083473206, \"Prediction\": -0.9872296452522278, \"Seed\": \"Alternative\"}, {\"Words\": \"celluloid\", \"Sentences\": \"This celluloid was filmed in Iraq.\", \"Similarity\": 0.19724225997924805, \"Prediction\": -0.9753105640411377, \"Seed\": \"Alternative\"}, {\"Words\": \"skin flick\", \"Sentences\": \"This skin flick was filmed in Iraq.\", \"Similarity\": 0.09620511531829834, \"Prediction\": -0.9778768420219421, \"Seed\": \"Alternative\"}, {\"Words\": \"nude painting\", \"Sentences\": \"This nude painting was filmed in Iraq.\", \"Similarity\": 0.2802892029285431, \"Prediction\": -0.8256915211677551, \"Seed\": \"Alternative\"}, {\"Words\": \"roll\", \"Sentences\": \"This roll was filmed in Iraq.\", \"Similarity\": 0.31563761830329895, \"Prediction\": 0.973349928855896, \"Seed\": \"Alternative\"}, {\"Words\": \"shrink-wrap\", \"Sentences\": \"This shrink-wrap was filmed in Iraq.\", \"Similarity\": 0.00307520036585629, \"Prediction\": -0.9946010112762451, \"Seed\": \"Alternative\"}, {\"Words\": \"short subject\", \"Sentences\": \"This short subject was filmed in Iraq.\", \"Similarity\": 0.37312769889831543, \"Prediction\": -0.9932711720466614, \"Seed\": \"Alternative\"}, {\"Words\": \"iconography\", \"Sentences\": \"This iconography was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": -0.7668758034706116, \"Seed\": \"Alternative\"}, {\"Words\": \"silent movie\", \"Sentences\": \"This silent movie was filmed in Iraq.\", \"Similarity\": 0.40748754143714905, \"Prediction\": -0.991932213306427, \"Seed\": \"Alternative\"}, {\"Words\": \"icon\", \"Sentences\": \"This icon was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.608573853969574, \"Seed\": \"Alternative\"}, {\"Words\": \"musical theater\", \"Sentences\": \"This musical theater was filmed in Iraq.\", \"Similarity\": 1.0000001192092896, \"Prediction\": -0.9650896787643433, \"Seed\": \"Alternative\"}, {\"Words\": \"rough cut\", \"Sentences\": \"This rough cut was filmed in Iraq.\", \"Similarity\": 0.4482826590538025, \"Prediction\": -0.9980751276016235, \"Seed\": \"Alternative\"}, {\"Words\": \"depiction\", \"Sentences\": \"This depiction was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": -0.9799100160598755, \"Seed\": \"Alternative\"}, {\"Words\": \"photograph\", \"Sentences\": \"This photograph was filmed in Iraq.\", \"Similarity\": 0.012723985128104687, \"Prediction\": -0.9196726083755493, \"Seed\": \"Alternative\"}, {\"Words\": \"holograph\", \"Sentences\": \"This holograph was filmed in Iraq.\", \"Similarity\": 0.06945700943470001, \"Prediction\": -0.9831704497337341, \"Seed\": \"Alternative\"}, {\"Words\": \"abstraction\", \"Sentences\": \"This abstraction was filmed in Iraq.\", \"Similarity\": 0.30736246705055237, \"Prediction\": -0.9771453142166138, \"Seed\": \"Alternative\"}, {\"Words\": \"wall painting\", \"Sentences\": \"This wall painting was filmed in Iraq.\", \"Similarity\": 0.041906263679265976, \"Prediction\": -0.9735763072967529, \"Seed\": \"Alternative\"}, {\"Words\": \"characterization\", \"Sentences\": \"This characterization was filmed in Iraq.\", \"Similarity\": 0.24184034764766693, \"Prediction\": -0.9716699123382568, \"Seed\": \"Alternative\"}, {\"Words\": \"silent picture\", \"Sentences\": \"This silent picture was filmed in Iraq.\", \"Similarity\": 0.40748754143714905, \"Prediction\": -0.9895797371864319, \"Seed\": \"Alternative\"}, {\"Words\": \"video\", \"Sentences\": \"This video was filmed in Iraq.\", \"Similarity\": 0.40727975964546204, \"Prediction\": -0.9924373030662537, \"Seed\": \"Alternative\"}, {\"Words\": \"semblance\", \"Sentences\": \"This semblance was filmed in Iraq.\", \"Similarity\": 0.21765615046024323, \"Prediction\": -0.9832487106323242, \"Seed\": \"Alternative\"}, {\"Words\": \"word-painting\", \"Sentences\": \"This word-painting was filmed in Iraq.\", \"Similarity\": 0.7244618535041809, \"Prediction\": -0.985617458820343, \"Seed\": \"Alternative\"}, {\"Words\": \"panorama\", \"Sentences\": \"This panorama was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": 0.7383041381835938, \"Seed\": \"Alternative\"}, {\"Words\": \"still\", \"Sentences\": \"This still was filmed in Iraq.\", \"Similarity\": 0.34776031970977783, \"Prediction\": -0.9832385778427124, \"Seed\": \"Alternative\"}, {\"Words\": \"frame\", \"Sentences\": \"This frame was filmed in Iraq.\", \"Similarity\": 0.041906263679265976, \"Prediction\": -0.9474449157714844, \"Seed\": \"Alternative\"}, {\"Words\": \"glossy\", \"Sentences\": \"This glossy was filmed in Iraq.\", \"Similarity\": 0.2362261712551117, \"Prediction\": -0.9883413910865784, \"Seed\": \"Alternative\"}, {\"Words\": \"picture show\", \"Sentences\": \"This picture show was filmed in Iraq.\", \"Similarity\": 0.2759341299533844, \"Prediction\": -0.98580002784729, \"Seed\": \"Alternative\"}, {\"Words\": \"miniature\", \"Sentences\": \"This miniature was filmed in Iraq.\", \"Similarity\": 0.11851898580789566, \"Prediction\": -0.9640893340110779, \"Seed\": \"Alternative\"}, {\"Words\": \"sequence\", \"Sentences\": \"This sequence was filmed in Iraq.\", \"Similarity\": 0.09885364025831223, \"Prediction\": -0.9735088348388672, \"Seed\": \"Alternative\"}, {\"Words\": \"docudrama\", \"Sentences\": \"This docudrama was filmed in Iraq.\", \"Similarity\": 0.16827510297298431, \"Prediction\": -0.966823935508728, \"Seed\": \"Alternative\"}, {\"Words\": \"snapshot\", \"Sentences\": \"This snapshot was filmed in Iraq.\", \"Similarity\": 0.30126306414604187, \"Prediction\": 0.5775587558746338, \"Seed\": \"Alternative\"}, {\"Words\": \"photo\", \"Sentences\": \"This photo was filmed in Iraq.\", \"Similarity\": 0.1714564859867096, \"Prediction\": -0.9606395363807678, \"Seed\": \"Alternative\"}, {\"Words\": \"cheesecake\", \"Sentences\": \"This cheesecake was filmed in Iraq.\", \"Similarity\": 0.1623053401708603, \"Prediction\": -0.9901886582374573, \"Seed\": \"Alternative\"}, {\"Words\": \"word picture\", \"Sentences\": \"This word picture was filmed in Iraq.\", \"Similarity\": 0.7244618535041809, \"Prediction\": -0.989831805229187, \"Seed\": \"Alternative\"}, {\"Words\": \"film\", \"Sentences\": \"This film was filmed in Iraq.\", \"Similarity\": 1.0, \"Prediction\": -0.9768388867378235, \"Seed\": \"Seed\"}, {\"Words\": \"delineation\", \"Sentences\": \"This delineation was filmed in Iraq.\", \"Similarity\": 0.21648120880126953, \"Prediction\": -0.98895663022995, \"Seed\": \"Alternative\"}, {\"Words\": \"infotainment\", \"Sentences\": \"This infotainment was filmed in Iraq.\", \"Similarity\": 0.17096103727817535, \"Prediction\": -0.9834266901016235, \"Seed\": \"Alternative\"}, {\"Words\": \"painting\", \"Sentences\": \"This painting was filmed in Iraq.\", \"Similarity\": 0.012723985128104687, \"Prediction\": -0.9334386587142944, \"Seed\": \"Alternative\"}, {\"Words\": \"wedding picture\", \"Sentences\": \"This wedding picture was filmed in Iraq.\", \"Similarity\": 0.005098994355648756, \"Prediction\": -0.8731076717376709, \"Seed\": \"Alternative\"}, {\"Words\": \"mural\", \"Sentences\": \"This mural was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": -0.9562681317329407, \"Seed\": \"Alternative\"}, {\"Words\": \"negative\", \"Sentences\": \"This negative was filmed in Iraq.\", \"Similarity\": 0.17593523859977722, \"Prediction\": -0.999600350856781, \"Seed\": \"Alternative\"}, {\"Words\": \"snap\", \"Sentences\": \"This snap was filmed in Iraq.\", \"Similarity\": 0.31563761830329895, \"Prediction\": -0.5398570895195007, \"Seed\": \"Alternative\"}, {\"Words\": \"reel\", \"Sentences\": \"This reel was filmed in Iraq.\", \"Similarity\": 0.1602938026189804, \"Prediction\": -0.9851198792457581, \"Seed\": \"Alternative\"}, {\"Words\": \"beefcake\", \"Sentences\": \"This beefcake was filmed in Iraq.\", \"Similarity\": 0.01305882167071104, \"Prediction\": -0.9892358183860779, \"Seed\": \"Alternative\"}, {\"Words\": \"slow motion\", \"Sentences\": \"This slow motion was filmed in Iraq.\", \"Similarity\": 0.21531067788600922, \"Prediction\": -0.9976890087127686, \"Seed\": \"Alternative\"}, {\"Words\": \"mug shot\", \"Sentences\": \"This mug shot was filmed in Iraq.\", \"Similarity\": 0.013170549646019936, \"Prediction\": -0.996273398399353, \"Seed\": \"Alternative\"}, {\"Words\": \"montage\", \"Sentences\": \"This montage was filmed in Iraq.\", \"Similarity\": 0.34389442205429077, \"Prediction\": -0.9799322485923767, \"Seed\": \"Alternative\"}, {\"Words\": \"water-colour\", \"Sentences\": \"This water-colour was filmed in Iraq.\", \"Similarity\": 0.14822277426719666, \"Prediction\": -0.92180335521698, \"Seed\": \"Alternative\"}, {\"Words\": \"hologram\", \"Sentences\": \"This hologram was filmed in Iraq.\", \"Similarity\": 0.0295212734490633, \"Prediction\": -0.9898383617401123, \"Seed\": \"Alternative\"}, {\"Words\": \"cinema verite\", \"Sentences\": \"This cinema verite was filmed in Iraq.\", \"Similarity\": 0.21417468786239624, \"Prediction\": -0.9682841897010803, \"Seed\": \"Alternative\"}, {\"Words\": \"illumination\", \"Sentences\": \"This illumination was filmed in Iraq.\", \"Similarity\": 0.041906263679265976, \"Prediction\": -0.9306833148002625, \"Seed\": \"Alternative\"}, {\"Words\": \"still life\", \"Sentences\": \"This still life was filmed in Iraq.\", \"Similarity\": 0.34776031970977783, \"Prediction\": -0.9527766704559326, \"Seed\": \"Alternative\"}, {\"Words\": \"silver screen\", \"Sentences\": \"This silver screen was filmed in Iraq.\", \"Similarity\": 0.02718006633222103, \"Prediction\": 0.9841983318328857, \"Seed\": \"Alternative\"}, {\"Words\": \"likeness\", \"Sentences\": \"This likeness was filmed in Iraq.\", \"Similarity\": 0.40247201919555664, \"Prediction\": -0.9791960716247559, \"Seed\": \"Alternative\"}, {\"Words\": \"feature\", \"Sentences\": \"This feature was filmed in Iraq.\", \"Similarity\": 0.05084456875920296, \"Prediction\": -0.9048511385917664, \"Seed\": \"Alternative\"}, {\"Words\": \"picture palace\", \"Sentences\": \"This picture palace was filmed in Iraq.\", \"Similarity\": 0.2759341299533844, \"Prediction\": -0.9499115347862244, \"Seed\": \"Alternative\"}, {\"Words\": \"coming attraction\", \"Sentences\": \"This coming attraction was filmed in Iraq.\", \"Similarity\": 0.34776031970977783, \"Prediction\": 0.9921624064445496, \"Seed\": \"Alternative\"}, {\"Words\": \"roll film\", \"Sentences\": \"This roll film was filmed in Iraq.\", \"Similarity\": 0.31563761830329895, \"Prediction\": 0.9974084496498108, \"Seed\": \"Alternative\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_nearest = alt.selection_single(on='mouseover', nearest=True)\n",
    "full = alt.Chart(cf_df).encode(\n",
    "    alt.X('Similarity:Q'),  # specify nominal data\n",
    "    alt.Y('Prediction:Q'),  # specify quantitative data\n",
    "    color=alt.Color('Seed:N', legend=alt.Legend(title=\"Seed or Alternative\")),\n",
    "    size='Seed:N',\n",
    "    tooltip=('Words','Prediction','Similarity')\n",
    ").mark_circle(opacity=.5).properties(width=300).add_selection(single_nearest)\n",
    "\n",
    "full"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1898eb99-22fc-4c6f-b918-1f972c4edb9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-c87bf2d2078345419472ddcf35b31915\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-c87bf2d2078345419472ddcf35b31915\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-c87bf2d2078345419472ddcf35b31915\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.17.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"4.17.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-c239d80ec7b6eaea314c3340cfa6439b\"}, \"mark\": \"circle\", \"encoding\": {\"color\": {\"field\": \"Seed\", \"legend\": {\"title\": \"Seed or Alternative\"}, \"type\": \"nominal\"}, \"size\": {\"field\": \"Seed\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"Words\", \"type\": \"nominal\"}, {\"field\": \"Prediction\", \"type\": \"quantitative\"}, {\"field\": \"Similarity\", \"type\": \"quantitative\"}], \"x\": {\"field\": \"Prediction\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"Words\", \"sort\": \"-x\", \"type\": \"nominal\"}}, \"selection\": {\"selector001\": {\"type\": \"single\", \"on\": \"mouseover\", \"nearest\": true}}, \"width\": 300, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.17.0.json\", \"datasets\": {\"data-c239d80ec7b6eaea314c3340cfa6439b\": [{\"Words\": \"positive\", \"Sentences\": \"This positive was filmed in Iraq.\", \"Similarity\": 0.17593523859977722, \"Prediction\": 0.9987342953681946, \"Seed\": \"Alternative\"}, {\"Words\": \"roll film\", \"Sentences\": \"This roll film was filmed in Iraq.\", \"Similarity\": 0.31563761830329895, \"Prediction\": 0.9974084496498108, \"Seed\": \"Alternative\"}, {\"Words\": \"coming attraction\", \"Sentences\": \"This coming attraction was filmed in Iraq.\", \"Similarity\": 0.34776031970977783, \"Prediction\": 0.9921624064445496, \"Seed\": \"Alternative\"}, {\"Words\": \"silver screen\", \"Sentences\": \"This silver screen was filmed in Iraq.\", \"Similarity\": 0.02718006633222103, \"Prediction\": 0.9841983318328857, \"Seed\": \"Alternative\"}, {\"Words\": \"roll\", \"Sentences\": \"This roll was filmed in Iraq.\", \"Similarity\": 0.31563761830329895, \"Prediction\": 0.973349928855896, \"Seed\": \"Alternative\"}, {\"Words\": \"negative\", \"Sentences\": \"This negative was filmed in Iraq.\", \"Similarity\": 0.17593523859977722, \"Prediction\": -0.999600350856781, \"Seed\": \"Alternative\"}, {\"Words\": \"distemper\", \"Sentences\": \"This distemper was filmed in Iraq.\", \"Similarity\": 0.01713787391781807, \"Prediction\": -0.9993439316749573, \"Seed\": \"Alternative\"}, {\"Words\": \"scum\", \"Sentences\": \"This scum was filmed in Iraq.\", \"Similarity\": 0.1664934903383255, \"Prediction\": -0.9993199110031128, \"Seed\": \"Alternative\"}, {\"Words\": \"rough cut\", \"Sentences\": \"This rough cut was filmed in Iraq.\", \"Similarity\": 0.4482826590538025, \"Prediction\": -0.9980751276016235, \"Seed\": \"Alternative\"}, {\"Words\": \"slow motion\", \"Sentences\": \"This slow motion was filmed in Iraq.\", \"Similarity\": 0.21531067788600922, \"Prediction\": -0.9976890087127686, \"Seed\": \"Alternative\"}, {\"Words\": \"film\", \"Sentences\": \"This film was filmed in Iraq.\", \"Similarity\": 1.0, \"Prediction\": -0.9768388867378235, \"Seed\": \"Seed\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = cf_df.nlargest(5, 'Prediction')\n",
    "df3 = cf_df.nsmallest(5, 'Prediction')\n",
    "df4 = cf_df[cf_df.Seed == \"Seed\"]\n",
    "frames = [df2,df3,df4]\n",
    "results = pd.concat(frames)\n",
    "\n",
    "bar = alt.Chart(results).encode(  \n",
    "    alt.X('Prediction:Q'), \n",
    "    alt.Y('Words:N', sort=\"-x\"),\n",
    "    color=alt.Color('Seed:N', legend=alt.Legend(title=\"Seed or Alternative\")),\n",
    "    size='Seed:N',\n",
    "    tooltip=('Words','Prediction','Similarity')\n",
    ").mark_circle().properties(width=300).add_selection(single_nearest)\n",
    "\n",
    "bar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "52a4fcfa-80d9-456e-a474-8192ac1c02e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Builds a list dynamically from WordNet using NLTK.\n",
    "def wordnet_df(word,POS=False):\n",
    "    pos_options = ['NOUN','VERB','ADJ','ADV']\n",
    "    synonyms, antonyms = syn_ant(word,POS,False)\n",
    "    words = []\n",
    "    cats = []\n",
    "    #WordNet hates spaces so you have to remove them\n",
    "    m_word = word.replace(\" \", \"_\")\n",
    "    \n",
    "    if POS in pos_options:\n",
    "        for syn in wordnet.synsets(m_word, pos=getattr(wordnet, POS)):\n",
    "                cur_lemmas = syn.lemmas()\n",
    "                hypos = syn.hyponyms()\n",
    "                for hypo in hypos:\n",
    "                    cur_lemmas.extend(hypo.lemmas())\n",
    "                for lemma in cur_lemmas:\n",
    "                    ll = lemma.name()\n",
    "                    cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                    words.append(re.sub(\"_\",\" \",ll))\n",
    "        \n",
    "        if len(synonyms) > 0:\n",
    "            for w in synonyms:\n",
    "                w = w.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(w, pos=getattr(wordnet, POS)):\n",
    "                    cur_lemmas = syn.lemmas()\n",
    "                    hypos = syn.hyponyms()\n",
    "                    for hypo in hypos:\n",
    "                        cur_lemmas.extend(hypo.lemmas())\n",
    "                    for lemma in cur_lemmas:\n",
    "                        ll = lemma.name()\n",
    "                        cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                        words.append(re.sub(\"_\",\" \",ll))\n",
    "        if len(antonyms) > 0:\n",
    "            for a in antonyms:\n",
    "                a = a.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(a, pos=getattr(wordnet, POS)):\n",
    "                    cur_lemmas = syn.lemmas()\n",
    "                    hypos = syn.hyponyms()\n",
    "                    for hypo in hypos:\n",
    "                        cur_lemmas.extend(hypo.lemmas())\n",
    "                    for lemma in cur_lemmas:\n",
    "                        ll = lemma.name()\n",
    "                        cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                        words.append(re.sub(\"_\",\" \",ll))\n",
    "    else:\n",
    "        for syn in wordnet.synsets(m_word):\n",
    "            cur_lemmas = syn.lemmas()\n",
    "            hypos = syn.hyponyms()\n",
    "            for hypo in hypos:\n",
    "                cur_lemmas.extend(hypo.lemmas())\n",
    "            for lemma in cur_lemmas:\n",
    "                ll = lemma.name()\n",
    "                cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                words.append(re.sub(\"_\",\" \",ll))\n",
    "        \n",
    "        if len(synonyms) > 0:\n",
    "            for w in synonyms:\n",
    "                w = w.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(w):\n",
    "                    cur_lemmas = syn.lemmas()\n",
    "                    hypos = syn.hyponyms()\n",
    "                    for hypo in hypos:\n",
    "                        cur_lemmas.extend(hypo.lemmas())\n",
    "                    for lemma in cur_lemmas:\n",
    "                        ll = lemma.name()\n",
    "                        cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                        words.append(re.sub(\"_\",\" \",ll))\n",
    "        if len(antonyms) > 0:\n",
    "            for a in antonyms:\n",
    "                a = a.replace(\" \",\"_\")\n",
    "                for syn in wordnet.synsets(a):\n",
    "                    cur_lemmas = syn.lemmas()\n",
    "                    hypos = syn.hyponyms()\n",
    "                    for hypo in hypos:\n",
    "                        cur_lemmas.extend(hypo.lemmas())\n",
    "                    for lemma in cur_lemmas:\n",
    "                        ll = lemma.name()\n",
    "                        cats.append(re.sub(\"_\",\" \", syn.name().split(\".\")[0]))\n",
    "                        words.append(re.sub(\"_\",\" \",ll))\n",
    "\n",
    "    df = {\"Categories\":cats, \"Words\":words}\n",
    "    df = pd.DataFrame(df) \n",
    "    df = df.drop_duplicates().reset_index()\n",
    "    df = df.drop(\"index\", axis=1)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8a61922c-09f8-4a2b-8317-36783016fc2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cf_from_wordnet_df(seed,text):\n",
    "    seed_token = nlp(seed)\n",
    "    seed_POS = seed_token[0].pos_\n",
    "    print(seed_POS)\n",
    "    df = wordnet_df(seed,seed_POS)\n",
    "    \n",
    "    df[\"Sentences\"] = df.Words.apply(lambda x: re.sub(r'\\b'+seed+r'\\b',x,text))\n",
    "    df[\"Word Similarity\"] = df.Words.apply(lambda x: seed_token.similarity(nlp(x)))\n",
    "    df = df[df[\"Word Similarity\"] > 0].reset_index()\n",
    "    df.drop(\"index\", axis=1, inplace=True)\n",
    "    df[\"Prediction\"] = df.Sentences.apply(eval_pred_test)\n",
    "    #added this because I think it will make the end results better if we ensure the seed is in the data we generate counterfactuals from.\n",
    "    df['Seed'] = df.Words.apply(lambda x: 'Seed' if x.lower() == seed else 'Alternative')\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ebeafe57-44e2-4ae2-bdab-f16050efc4f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NOUN\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/lx/xt9qnk8569n7xy_d7knh3npr0000gp/T/ipykernel_6702/2903488048.py:8: UserWarning: [W008] Evaluating Doc.similarity based on empty vectors.\n",
      "  df[\"Word Similarity\"] = df.Words.apply(lambda x: seed_token.similarity(nlp(x)))\n"
     ]
    }
   ],
   "source": [
    "panic = cf_from_wordnet_df(seed,text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c534bbab-7d5d-4695-8ab0-948ff88463de",
   "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>Categories</th>\n",
       "      <th>Words</th>\n",
       "      <th>Sentences</th>\n",
       "      <th>Word Similarity</th>\n",
       "      <th>Prediction</th>\n",
       "      <th>Seed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>movie</td>\n",
       "      <td>movie</td>\n",
       "      <td>This movie was filmed in Iraq.</td>\n",
       "      <td>0.519086</td>\n",
       "      <td>-0.985851</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>movie</td>\n",
       "      <td>film</td>\n",
       "      <td>This film was filmed in Iraq.</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.976839</td>\n",
       "      <td>Seed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>movie</td>\n",
       "      <td>picture</td>\n",
       "      <td>This picture was filmed in Iraq.</td>\n",
       "      <td>0.275934</td>\n",
       "      <td>-0.966598</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>movie</td>\n",
       "      <td>moving picture</td>\n",
       "      <td>This moving picture was filmed in Iraq.</td>\n",
       "      <td>0.317025</td>\n",
       "      <td>0.951934</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>movie</td>\n",
       "      <td>moving-picture show</td>\n",
       "      <td>This moving-picture show was filmed in Iraq.</td>\n",
       "      <td>0.438731</td>\n",
       "      <td>-0.891211</td>\n",
       "      <td>Alternative</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Categories                Words  \\\n",
       "0      movie                movie   \n",
       "1      movie                 film   \n",
       "2      movie              picture   \n",
       "3      movie       moving picture   \n",
       "4      movie  moving-picture show   \n",
       "\n",
       "                                      Sentences  Word Similarity  Prediction  \\\n",
       "0                This movie was filmed in Iraq.         0.519086   -0.985851   \n",
       "1                 This film was filmed in Iraq.         1.000000   -0.976839   \n",
       "2              This picture was filmed in Iraq.         0.275934   -0.966598   \n",
       "3       This moving picture was filmed in Iraq.         0.317025    0.951934   \n",
       "4  This moving-picture show was filmed in Iraq.         0.438731   -0.891211   \n",
       "\n",
       "          Seed  \n",
       "0  Alternative  \n",
       "1         Seed  \n",
       "2  Alternative  \n",
       "3  Alternative  \n",
       "4  Alternative  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "panic.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ea7ad4f3-98d0-4760-9bae-e94210886f08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-c2147ee18dbe4d41843f4f403cfe5168\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-c2147ee18dbe4d41843f4f403cfe5168\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-c2147ee18dbe4d41843f4f403cfe5168\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.17.0?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function maybeLoadScript(lib, version) {\n",
       "      var key = `${lib.replace(\"-\", \"\")}_version`;\n",
       "      return (VEGA_DEBUG[key] == version) ?\n",
       "        Promise.resolve(paths[lib]) :\n",
       "        new Promise(function(resolve, reject) {\n",
       "          var s = document.createElement('script');\n",
       "          document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "          s.async = true;\n",
       "          s.onload = () => {\n",
       "            VEGA_DEBUG[key] = version;\n",
       "            return resolve(paths[lib]);\n",
       "          };\n",
       "          s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "          s.src = paths[lib];\n",
       "        });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else {\n",
       "      maybeLoadScript(\"vega\", \"5\")\n",
       "        .then(() => maybeLoadScript(\"vega-lite\", \"4.17.0\"))\n",
       "        .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-f373cf3e66aef40433d4b336f81ca31d\"}, \"mark\": {\"type\": \"circle\", \"opacity\": 0.5}, \"encoding\": {\"color\": {\"field\": \"Seed\", \"legend\": {\"title\": \"Seed or Alternative\"}, \"type\": \"nominal\"}, \"size\": {\"field\": \"Seed\", \"type\": \"nominal\"}, \"tooltip\": [{\"field\": \"Words\", \"type\": \"nominal\"}, {\"field\": \"Prediction\", \"type\": \"quantitative\"}, {\"field\": \"Word Similarity\", \"type\": \"quantitative\"}], \"x\": {\"field\": \"Word Similarity\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"Prediction\", \"type\": \"quantitative\"}}, \"selection\": {\"selector002\": {\"type\": \"single\", \"on\": \"mouseover\", \"nearest\": true}}, \"width\": 300, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.17.0.json\", \"datasets\": {\"data-f373cf3e66aef40433d4b336f81ca31d\": [{\"Categories\": \"movie\", \"Words\": \"movie\", \"Sentences\": \"This movie was filmed in Iraq.\", \"Word Similarity\": 0.5190859963143863, \"Prediction\": -0.9858505129814148, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"film\", \"Sentences\": \"This film was filmed in Iraq.\", \"Word Similarity\": 1.0, \"Prediction\": -0.9768388867378235, \"Seed\": \"Seed\"}, {\"Categories\": \"movie\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"moving picture\", \"Sentences\": \"This moving picture was filmed in Iraq.\", \"Word Similarity\": 0.31702499945488033, \"Prediction\": 0.9519339799880981, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"moving-picture show\", \"Sentences\": \"This moving-picture show was filmed in Iraq.\", \"Word Similarity\": 0.4387311021807662, \"Prediction\": -0.8912112712860107, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"motion picture\", \"Sentences\": \"This motion picture was filmed in Iraq.\", \"Word Similarity\": 0.2717412021074868, \"Prediction\": -0.9857431054115295, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"motion-picture show\", \"Sentences\": \"This motion-picture show was filmed in Iraq.\", \"Word Similarity\": 0.4169089697220091, \"Prediction\": -0.9922996163368225, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"picture show\", \"Sentences\": \"This picture show was filmed in Iraq.\", \"Word Similarity\": 0.5350690161883357, \"Prediction\": -0.98580002784729, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"pic\", \"Sentences\": \"This pic was filmed in Iraq.\", \"Word Similarity\": 0.4072797635418109, \"Prediction\": -0.9645436406135559, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"flick\", \"Sentences\": \"This flick was filmed in Iraq.\", \"Word Similarity\": 0.3800064718551956, \"Prediction\": -0.987636387348175, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"cinema verite\", \"Sentences\": \"This cinema verite was filmed in Iraq.\", \"Word Similarity\": 0.09937434214061898, \"Prediction\": -0.9682841897010803, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"collage film\", \"Sentences\": \"This collage film was filmed in Iraq.\", \"Word Similarity\": 0.7539224961218202, \"Prediction\": -0.9791572093963623, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"coming attraction\", \"Sentences\": \"This coming attraction was filmed in Iraq.\", \"Word Similarity\": 0.42093557507101165, \"Prediction\": 0.9921624064445496, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"documentary\", \"Sentences\": \"This documentary was filmed in Iraq.\", \"Word Similarity\": 0.5264785362787989, \"Prediction\": -0.8684387803077698, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"docudrama\", \"Sentences\": \"This docudrama was filmed in Iraq.\", \"Word Similarity\": 0.16827511226734035, \"Prediction\": -0.966823935508728, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"documentary film\", \"Sentences\": \"This documentary film was filmed in Iraq.\", \"Word Similarity\": 0.8800648028884509, \"Prediction\": 0.539196252822876, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"infotainment\", \"Sentences\": \"This infotainment was filmed in Iraq.\", \"Word Similarity\": 0.1709610401682146, \"Prediction\": -0.9834266901016235, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"feature\", \"Sentences\": \"This feature was filmed in Iraq.\", \"Word Similarity\": 0.050844567396109694, \"Prediction\": -0.9048511385917664, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"feature film\", \"Sentences\": \"This feature film was filmed in Iraq.\", \"Word Similarity\": 0.7652652149505584, \"Prediction\": -0.9292460680007935, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"film noir\", \"Sentences\": \"This film noir was filmed in Iraq.\", \"Word Similarity\": 0.6396233925052188, \"Prediction\": -0.8313860297203064, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"final cut\", \"Sentences\": \"This final cut was filmed in Iraq.\", \"Word Similarity\": 0.17981537410445786, \"Prediction\": -0.9818063974380493, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"home movie\", \"Sentences\": \"This home movie was filmed in Iraq.\", \"Word Similarity\": 0.3522806301030666, \"Prediction\": -0.9927988052368164, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"musical\", \"Sentences\": \"This musical was filmed in Iraq.\", \"Word Similarity\": 1.0000000587640132, \"Prediction\": -0.9366526007652283, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"musical comedy\", \"Sentences\": \"This musical comedy was filmed in Iraq.\", \"Word Similarity\": 1.0000000587640132, \"Prediction\": 0.9108031392097473, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"musical theater\", \"Sentences\": \"This musical theater was filmed in Iraq.\", \"Word Similarity\": 0.7848242677448894, \"Prediction\": -0.9650896787643433, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"rough cut\", \"Sentences\": \"This rough cut was filmed in Iraq.\", \"Word Similarity\": 0.3751254614823304, \"Prediction\": -0.9980751276016235, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"shoot-'em-up\", \"Sentences\": \"This shoot-'em-up was filmed in Iraq.\", \"Word Similarity\": 0.19834995610972345, \"Prediction\": -0.9816700220108032, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"short subject\", \"Sentences\": \"This short subject was filmed in Iraq.\", \"Word Similarity\": 0.4281967976685067, \"Prediction\": -0.9932711720466614, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"silent movie\", \"Sentences\": \"This silent movie was filmed in Iraq.\", \"Word Similarity\": 0.5700986447182881, \"Prediction\": -0.991932213306427, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"silent picture\", \"Sentences\": \"This silent picture was filmed in Iraq.\", \"Word Similarity\": 0.42485102356749427, \"Prediction\": -0.9895797371864319, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"silents\", \"Sentences\": \"This silents was filmed in Iraq.\", \"Word Similarity\": 0.19807446971181836, \"Prediction\": -0.9920938611030579, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"skin flick\", \"Sentences\": \"This skin flick was filmed in Iraq.\", \"Word Similarity\": 0.3003859311193749, \"Prediction\": -0.9778768420219421, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"slow motion\", \"Sentences\": \"This slow motion was filmed in Iraq.\", \"Word Similarity\": 0.21400430445120833, \"Prediction\": -0.9976890087127686, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"talking picture\", \"Sentences\": \"This talking picture was filmed in Iraq.\", \"Word Similarity\": 0.5333406793193932, \"Prediction\": -0.9642181396484375, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"three-D\", \"Sentences\": \"This three-D was filmed in Iraq.\", \"Word Similarity\": 0.09875600124581498, \"Prediction\": -0.9897969365119934, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"3-D\", \"Sentences\": \"This 3-D was filmed in Iraq.\", \"Word Similarity\": 0.03966587974572822, \"Prediction\": -0.9906445741653442, \"Seed\": \"Alternative\"}, {\"Categories\": \"movie\", \"Words\": \"3D\", \"Sentences\": \"This 3D was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.8974476456642151, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"film\", \"Sentences\": \"This film was filmed in Iraq.\", \"Word Similarity\": 1.0, \"Prediction\": -0.9768388867378235, \"Seed\": \"Seed\"}, {\"Categories\": \"film\", \"Words\": \"cinema\", \"Sentences\": \"This cinema was filmed in Iraq.\", \"Word Similarity\": 0.21417468253026045, \"Prediction\": -0.9662075042724609, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"celluloid\", \"Sentences\": \"This celluloid was filmed in Iraq.\", \"Word Similarity\": 0.1972422453626386, \"Prediction\": -0.9753105640411377, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"silver screen\", \"Sentences\": \"This silver screen was filmed in Iraq.\", \"Word Similarity\": 0.029392622760333605, \"Prediction\": 0.9841983318328857, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"photographic film\", \"Sentences\": \"This photographic film was filmed in Iraq.\", \"Word Similarity\": 0.6565405557271725, \"Prediction\": 0.513984203338623, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"film clip\", \"Sentences\": \"This film clip was filmed in Iraq.\", \"Word Similarity\": 0.8339866396754791, \"Prediction\": -0.9884151220321655, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"footage\", \"Sentences\": \"This footage was filmed in Iraq.\", \"Word Similarity\": 0.4072797635418109, \"Prediction\": -0.9819908738136292, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"motion-picture film\", \"Sentences\": \"This motion-picture film was filmed in Iraq.\", \"Word Similarity\": 0.6326840506527587, \"Prediction\": -0.9860610961914062, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"movie film\", \"Sentences\": \"This movie film was filmed in Iraq.\", \"Word Similarity\": 0.8679161782932928, \"Prediction\": -0.9835726618766785, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"cine-film\", \"Sentences\": \"This cine-film was filmed in Iraq.\", \"Word Similarity\": 0.5656945636080714, \"Prediction\": -0.9945468902587891, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"negative\", \"Sentences\": \"This negative was filmed in Iraq.\", \"Word Similarity\": 0.17593524381566258, \"Prediction\": -0.999600350856781, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"orthochromatic film\", \"Sentences\": \"This orthochromatic film was filmed in Iraq.\", \"Word Similarity\": 1.0000000587640132, \"Prediction\": -0.9606354832649231, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"panchromatic film\", \"Sentences\": \"This panchromatic film was filmed in Iraq.\", \"Word Similarity\": 0.6284022523822068, \"Prediction\": 0.9600452780723572, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"positive\", \"Sentences\": \"This positive was filmed in Iraq.\", \"Word Similarity\": 0.17593524381566258, \"Prediction\": 0.9987342953681946, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"reel\", \"Sentences\": \"This reel was filmed in Iraq.\", \"Word Similarity\": 0.16029381704312287, \"Prediction\": -0.9851198792457581, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"roll\", \"Sentences\": \"This roll was filmed in Iraq.\", \"Word Similarity\": 0.31563761641102356, \"Prediction\": 0.973349928855896, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"roll film\", \"Sentences\": \"This roll film was filmed in Iraq.\", \"Word Similarity\": 0.8274100261787216, \"Prediction\": 0.9974084496498108, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"sequence\", \"Sentences\": \"This sequence was filmed in Iraq.\", \"Word Similarity\": 0.09885364568854371, \"Prediction\": -0.9735088348388672, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"episode\", \"Sentences\": \"This episode was filmed in Iraq.\", \"Word Similarity\": 0.5190859963143863, \"Prediction\": -0.9836438298225403, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"X-ray film\", \"Sentences\": \"This X-ray film was filmed in Iraq.\", \"Word Similarity\": 0.5808158983770263, \"Prediction\": -0.9813085198402405, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"scum\", \"Sentences\": \"This scum was filmed in Iraq.\", \"Word Similarity\": 0.1664934973062463, \"Prediction\": -0.9993199110031128, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"slick\", \"Sentences\": \"This slick was filmed in Iraq.\", \"Word Similarity\": 0.3115971312398067, \"Prediction\": 0.9697098731994629, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"soap film\", \"Sentences\": \"This soap film was filmed in Iraq.\", \"Word Similarity\": 0.706178699783087, \"Prediction\": -0.9944995641708374, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"plastic film\", \"Sentences\": \"This plastic film was filmed in Iraq.\", \"Word Similarity\": 0.6141033409632763, \"Prediction\": -0.9982172846794128, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"Polaroid\", \"Sentences\": \"This Polaroid was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.979912519454956, \"Seed\": \"Alternative\"}, {\"Categories\": \"film\", \"Words\": \"shrink-wrap\", \"Sentences\": \"This shrink-wrap was filmed in Iraq.\", \"Word Similarity\": 0.09031501697131157, \"Prediction\": -0.9946010112762451, \"Seed\": \"Alternative\"}, {\"Categories\": \"celluloid\", \"Words\": \"celluloid\", \"Sentences\": \"This celluloid was filmed in Iraq.\", \"Word Similarity\": 0.1972422453626386, \"Prediction\": -0.9753105640411377, \"Seed\": \"Alternative\"}, {\"Categories\": \"cinema\", \"Words\": \"cinema\", \"Sentences\": \"This cinema was filmed in Iraq.\", \"Word Similarity\": 0.21417468253026045, \"Prediction\": -0.9662075042724609, \"Seed\": \"Alternative\"}, {\"Categories\": \"cinema\", \"Words\": \"movie theater\", \"Sentences\": \"This movie theater was filmed in Iraq.\", \"Word Similarity\": 0.4755065878289731, \"Prediction\": -0.9912400841712952, \"Seed\": \"Alternative\"}, {\"Categories\": \"cinema\", \"Words\": \"movie theatre\", \"Sentences\": \"This movie theatre was filmed in Iraq.\", \"Word Similarity\": 0.4483797961561575, \"Prediction\": -0.9872481226921082, \"Seed\": \"Alternative\"}, {\"Categories\": \"cinema\", \"Words\": \"movie house\", \"Sentences\": \"This movie house was filmed in Iraq.\", \"Word Similarity\": 0.46181633342698464, \"Prediction\": -0.9951876401901245, \"Seed\": \"Alternative\"}, {\"Categories\": \"cinema\", \"Words\": \"picture palace\", \"Sentences\": \"This picture palace was filmed in Iraq.\", \"Word Similarity\": 0.3246190726775255, \"Prediction\": -0.9499115347862244, \"Seed\": \"Alternative\"}, {\"Categories\": \"flick\", \"Words\": \"flick\", \"Sentences\": \"This flick was filmed in Iraq.\", \"Word Similarity\": 0.3800064718551956, \"Prediction\": -0.987636387348175, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"photograph\", \"Sentences\": \"This photograph was filmed in Iraq.\", \"Word Similarity\": 0.012723984321047776, \"Prediction\": -0.9196726083755493, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"photo\", \"Sentences\": \"This photo was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.9606395363807678, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"exposure\", \"Sentences\": \"This exposure was filmed in Iraq.\", \"Word Similarity\": 0.09723522360232327, \"Prediction\": -0.9579629898071289, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"pic\", \"Sentences\": \"This pic was filmed in Iraq.\", \"Word Similarity\": 0.4072797635418109, \"Prediction\": -0.9645436406135559, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"beefcake\", \"Sentences\": \"This beefcake was filmed in Iraq.\", \"Word Similarity\": 0.013058821148824687, \"Prediction\": -0.9892358183860779, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"black and white\", \"Sentences\": \"This black and white was filmed in Iraq.\", \"Word Similarity\": 0.2842708630352097, \"Prediction\": -0.9872296452522278, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"blueprint\", \"Sentences\": \"This blueprint was filmed in Iraq.\", \"Word Similarity\": 0.03582379538379523, \"Prediction\": -0.9900976419448853, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"cheesecake\", \"Sentences\": \"This cheesecake was filmed in Iraq.\", \"Word Similarity\": 0.16230533878952264, \"Prediction\": -0.9901886582374573, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"closeup\", \"Sentences\": \"This closeup was filmed in Iraq.\", \"Word Similarity\": 0.19359751435654632, \"Prediction\": -0.876624584197998, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"blowup\", \"Sentences\": \"This blowup was filmed in Iraq.\", \"Word Similarity\": 0.2724970094314425, \"Prediction\": -0.9948825836181641, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"frame\", \"Sentences\": \"This frame was filmed in Iraq.\", \"Word Similarity\": 0.04190626366991173, \"Prediction\": -0.9474449157714844, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"glossy\", \"Sentences\": \"This glossy was filmed in Iraq.\", \"Word Similarity\": 0.236226161028214, \"Prediction\": -0.9883413910865784, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"headshot\", \"Sentences\": \"This headshot was filmed in Iraq.\", \"Word Similarity\": 0.29964503290316746, \"Prediction\": -0.9679704308509827, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"hologram\", \"Sentences\": \"This hologram was filmed in Iraq.\", \"Word Similarity\": 0.029521275159483634, \"Prediction\": -0.9898383617401123, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"holograph\", \"Sentences\": \"This holograph was filmed in Iraq.\", \"Word Similarity\": 0.06945700837472585, \"Prediction\": -0.9831704497337341, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"longshot\", \"Sentences\": \"This longshot was filmed in Iraq.\", \"Word Similarity\": 0.05040800370574034, \"Prediction\": -0.9915591478347778, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"mosaic\", \"Sentences\": \"This mosaic was filmed in Iraq.\", \"Word Similarity\": 0.236226161028214, \"Prediction\": 0.5872843861579895, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"arial mosaic\", \"Sentences\": \"This arial mosaic was filmed in Iraq.\", \"Word Similarity\": 0.05364197538265368, \"Prediction\": -0.8865885138511658, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"mug shot\", \"Sentences\": \"This mug shot was filmed in Iraq.\", \"Word Similarity\": 0.1640604740819903, \"Prediction\": -0.996273398399353, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"mugshot\", \"Sentences\": \"This mugshot was filmed in Iraq.\", \"Word Similarity\": 0.3463700881243038, \"Prediction\": -0.9971551895141602, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"photographic print\", \"Sentences\": \"This photographic print was filmed in Iraq.\", \"Word Similarity\": 0.04118213760816905, \"Prediction\": -0.9862127304077148, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"print\", \"Sentences\": \"This print was filmed in Iraq.\", \"Word Similarity\": 0.09969713735711155, \"Prediction\": -0.9955253005027771, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"scene\", \"Sentences\": \"This scene was filmed in Iraq.\", \"Word Similarity\": 0.48349320690687697, \"Prediction\": -0.9720112681388855, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"shot\", \"Sentences\": \"This shot was filmed in Iraq.\", \"Word Similarity\": 0.20950996604464142, \"Prediction\": -0.9753239154815674, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"snapshot\", \"Sentences\": \"This snapshot was filmed in Iraq.\", \"Word Similarity\": 0.30126304553472416, \"Prediction\": 0.5775587558746338, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"snap\", \"Sentences\": \"This snap was filmed in Iraq.\", \"Word Similarity\": 0.31563761641102356, \"Prediction\": -0.5398570895195007, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"stereo\", \"Sentences\": \"This stereo was filmed in Iraq.\", \"Word Similarity\": 0.12465525914475722, \"Prediction\": -0.9964680671691895, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"stereoscopic picture\", \"Sentences\": \"This stereoscopic picture was filmed in Iraq.\", \"Word Similarity\": 0.15109067888254674, \"Prediction\": -0.9568785429000854, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"still\", \"Sentences\": \"This still was filmed in Iraq.\", \"Word Similarity\": 0.347760352345329, \"Prediction\": -0.9832385778427124, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"time exposure\", \"Sentences\": \"This time exposure was filmed in Iraq.\", \"Word Similarity\": 0.2971918201731859, \"Prediction\": -0.9667099118232727, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"vignette\", \"Sentences\": \"This vignette was filmed in Iraq.\", \"Word Similarity\": 0.3438944285259018, \"Prediction\": -0.9709358215332031, \"Seed\": \"Alternative\"}, {\"Categories\": \"photograph\", \"Words\": \"wedding picture\", \"Sentences\": \"This wedding picture was filmed in Iraq.\", \"Word Similarity\": 0.1669571658658145, \"Prediction\": -0.8731076717376709, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"icon\", \"Sentences\": \"This icon was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.608573853969574, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"electronic image\", \"Sentences\": \"This electronic image was filmed in Iraq.\", \"Word Similarity\": 0.026310571482819744, \"Prediction\": -0.9799883365631104, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"collage\", \"Sentences\": \"This collage was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.9813950657844543, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"montage\", \"Sentences\": \"This montage was filmed in Iraq.\", \"Word Similarity\": 0.3438944285259018, \"Prediction\": -0.9799322485923767, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"foil\", \"Sentences\": \"This foil was filmed in Iraq.\", \"Word Similarity\": 0.09969713735711155, \"Prediction\": -0.9227285981178284, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"transparency\", \"Sentences\": \"This transparency was filmed in Iraq.\", \"Word Similarity\": 0.030078566735325406, \"Prediction\": -0.8847953677177429, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"graphic\", \"Sentences\": \"This graphic was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.9842573404312134, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"computer graphic\", \"Sentences\": \"This computer graphic was filmed in Iraq.\", \"Word Similarity\": 0.09000361323663436, \"Prediction\": -0.9926844835281372, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"iconography\", \"Sentences\": \"This iconography was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": -0.7668758034706116, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"inset\", \"Sentences\": \"This inset was filmed in Iraq.\", \"Word Similarity\": 0.236226161028214, \"Prediction\": -0.9969562292098999, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"likeness\", \"Sentences\": \"This likeness was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": -0.9791960716247559, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"semblance\", \"Sentences\": \"This semblance was filmed in Iraq.\", \"Word Similarity\": 0.21765614174366776, \"Prediction\": -0.9832487106323242, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"panorama\", \"Sentences\": \"This panorama was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": 0.7383041381835938, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"diorama\", \"Sentences\": \"This diorama was filmed in Iraq.\", \"Word Similarity\": 0.127023308869183, \"Prediction\": 0.7934190630912781, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"reflection\", \"Sentences\": \"This reflection was filmed in Iraq.\", \"Word Similarity\": 0.18078071596917625, \"Prediction\": -0.6845596432685852, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"scan\", \"Sentences\": \"This scan was filmed in Iraq.\", \"Word Similarity\": 0.10371564135820871, \"Prediction\": -0.9957475066184998, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"CAT scan\", \"Sentences\": \"This CAT scan was filmed in Iraq.\", \"Word Similarity\": 0.19331544765072045, \"Prediction\": -0.9924741387367249, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"painting\", \"Sentences\": \"This painting was filmed in Iraq.\", \"Word Similarity\": 0.012723984321047776, \"Prediction\": -0.9334386587142944, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"abstraction\", \"Sentences\": \"This abstraction was filmed in Iraq.\", \"Word Similarity\": 0.307362457132976, \"Prediction\": -0.9771453142166138, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"cityscape\", \"Sentences\": \"This cityscape was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": -0.9577135443687439, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"daub\", \"Sentences\": \"This daub was filmed in Iraq.\", \"Word Similarity\": 0.14788114427051885, \"Prediction\": -0.996572732925415, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"distemper\", \"Sentences\": \"This distemper was filmed in Iraq.\", \"Word Similarity\": 0.01713787402732078, \"Prediction\": -0.9993439316749573, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"finger-painting\", \"Sentences\": \"This finger-painting was filmed in Iraq.\", \"Word Similarity\": 0.17009456557266658, \"Prediction\": -0.9805013537406921, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"icon\", \"Sentences\": \"This icon was filmed in Iraq.\", \"Word Similarity\": 0.17145648267172575, \"Prediction\": -0.608573853969574, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"landscape\", \"Sentences\": \"This landscape was filmed in Iraq.\", \"Word Similarity\": 0.058922973867911566, \"Prediction\": 0.6257414221763611, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"miniature\", \"Sentences\": \"This miniature was filmed in Iraq.\", \"Word Similarity\": 0.11851899449835313, \"Prediction\": -0.9640893340110779, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"illumination\", \"Sentences\": \"This illumination was filmed in Iraq.\", \"Word Similarity\": 0.04190626366991173, \"Prediction\": -0.9306833148002625, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"mural\", \"Sentences\": \"This mural was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": -0.9562681317329407, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"wall painting\", \"Sentences\": \"This wall painting was filmed in Iraq.\", \"Word Similarity\": 0.035987748374169425, \"Prediction\": -0.9735763072967529, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"nude\", \"Sentences\": \"This nude was filmed in Iraq.\", \"Word Similarity\": 0.2802892192361027, \"Prediction\": -0.8499994277954102, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"nude painting\", \"Sentences\": \"This nude painting was filmed in Iraq.\", \"Word Similarity\": 0.2078872194858697, \"Prediction\": -0.8256915211677551, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"oil painting\", \"Sentences\": \"This oil painting was filmed in Iraq.\", \"Word Similarity\": 0.1681611680585539, \"Prediction\": -0.9437991976737976, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"sand painting\", \"Sentences\": \"This sand painting was filmed in Iraq.\", \"Word Similarity\": 0.09351431334138006, \"Prediction\": -0.9653210639953613, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"semi-abstraction\", \"Sentences\": \"This semi-abstraction was filmed in Iraq.\", \"Word Similarity\": 0.2372533752044437, \"Prediction\": -0.987169623374939, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"still life\", \"Sentences\": \"This still life was filmed in Iraq.\", \"Word Similarity\": 0.34429948494573387, \"Prediction\": -0.9527766704559326, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"trompe l'oeil\", \"Sentences\": \"This trompe l'oeil was filmed in Iraq.\", \"Word Similarity\": 0.236226161028214, \"Prediction\": -0.9688800573348999, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"water-color\", \"Sentences\": \"This water-color was filmed in Iraq.\", \"Word Similarity\": 0.05993146524985539, \"Prediction\": -0.810806155204773, \"Seed\": \"Alternative\"}, {\"Categories\": \"painting\", \"Words\": \"water-colour\", \"Sentences\": \"This water-colour was filmed in Iraq.\", \"Word Similarity\": 0.05993146524985539, \"Prediction\": -0.92180335521698, \"Seed\": \"Alternative\"}, {\"Categories\": \"mental picture\", \"Words\": \"mental picture\", \"Sentences\": \"This mental picture was filmed in Iraq.\", \"Word Similarity\": 0.31825090248363247, \"Prediction\": -0.9934840798377991, \"Seed\": \"Alternative\"}, {\"Categories\": \"mental picture\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"mental picture\", \"Words\": \"impression\", \"Sentences\": \"This impression was filmed in Iraq.\", \"Word Similarity\": 0.18283532501150543, \"Prediction\": -0.8515572547912598, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"scene\", \"Sentences\": \"This scene was filmed in Iraq.\", \"Word Similarity\": 0.48349320690687697, \"Prediction\": -0.9720112681388855, \"Seed\": \"Alternative\"}, {\"Categories\": \"picture\", \"Words\": \"pictorial matter\", \"Sentences\": \"This pictorial matter was filmed in Iraq.\", \"Word Similarity\": 0.1824789976024603, \"Prediction\": -0.5508358478546143, \"Seed\": \"Alternative\"}, {\"Categories\": \"video\", \"Words\": \"video\", \"Sentences\": \"This video was filmed in Iraq.\", \"Word Similarity\": 0.4072797635418109, \"Prediction\": -0.9924373030662537, \"Seed\": \"Alternative\"}, {\"Categories\": \"video\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"word picture\", \"Sentences\": \"This word picture was filmed in Iraq.\", \"Word Similarity\": 0.5981027679972372, \"Prediction\": -0.989831805229187, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"word-painting\", \"Sentences\": \"This word-painting was filmed in Iraq.\", \"Word Similarity\": 0.38706227560895623, \"Prediction\": -0.985617458820343, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"delineation\", \"Sentences\": \"This delineation was filmed in Iraq.\", \"Word Similarity\": 0.21648120725304634, \"Prediction\": -0.98895663022995, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"depiction\", \"Sentences\": \"This depiction was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": -0.9799100160598755, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"picture\", \"Sentences\": \"This picture was filmed in Iraq.\", \"Word Similarity\": 0.2759341200434225, \"Prediction\": -0.9665979743003845, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"characterization\", \"Sentences\": \"This characterization was filmed in Iraq.\", \"Word Similarity\": 0.2418403365927032, \"Prediction\": -0.9716699123382568, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"characterisation\", \"Sentences\": \"This characterisation was filmed in Iraq.\", \"Word Similarity\": 0.21648120725304634, \"Prediction\": -0.9873332977294922, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"epithet\", \"Sentences\": \"This epithet was filmed in Iraq.\", \"Word Similarity\": 0.15113958883109133, \"Prediction\": -0.9895598888397217, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"portrayal\", \"Sentences\": \"This portrayal was filmed in Iraq.\", \"Word Similarity\": 0.510058318695837, \"Prediction\": -0.9788959622383118, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"portraiture\", \"Sentences\": \"This portraiture was filmed in Iraq.\", \"Word Similarity\": 0.0547194400736445, \"Prediction\": 0.6638062000274658, \"Seed\": \"Alternative\"}, {\"Categories\": \"word picture\", \"Words\": \"portrait\", \"Sentences\": \"This portrait was filmed in Iraq.\", \"Word Similarity\": 0.40247201053246207, \"Prediction\": 0.8814621567726135, \"Seed\": \"Alternative\"}]}}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_nearest = alt.selection_single(on='mouseover', nearest=True)\n",
    "full = alt.Chart(panic).encode(\n",
    "    alt.X('Word Similarity:Q'),  # specify nominal data\n",
    "    alt.Y('Prediction:Q'),  # specify quantitative data\n",
    "    color=alt.Color('Seed:N', legend=alt.Legend(title=\"Seed or Alternative\")),\n",
    "    size='Seed:N',\n",
    "    tooltip=('Words','Prediction','Word Similarity')\n",
    ").mark_circle(opacity=.5).properties(width=300).add_selection(single_nearest)\n",
    "\n",
    "full"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "68dfc91f-3a54-4d96-8be9-887415299735",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isinstance(cf_df, pd.DataFrame)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "9b646bd3-fe80-460d-8237-d181554992a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://github.com/tvst/st-annotated-text/blob/master/example.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "77b86e94-e55a-4c2c-a2ed-bba4e504fbc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_sampled(df, seed, fixed=False):\n",
    "    sub_df = df[df['Words'] != seed]\n",
    "    if fixed:\n",
    "        sample = sub_df.sample(n=2, random_state = 2052)\n",
    "    else:\n",
    "        sample = sub_df.sample(n=2)\n",
    "    text2 = sample.Sentences.iloc[0]\n",
    "    text3 = sample.Sentences.iloc[1]\n",
    "    return text2,text3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "99253045-8671-47d0-8bed-17b20476c196",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('This cheesecake was filmed in Iraq.', 'This scum was filmed in Iraq.')"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_sampled(panic,\"film\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "f438ae0e-7a93-4021-a3ad-5ce36ad37984",
   "metadata": {},
   "outputs": [],
   "source": [
    "text2, text3 = get_sampled(panic, \"film\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "06b9e22f-7562-423d-b96d-19b706869c6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'This montage was filmed in Iraq.'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "bc4b5467-c8f6-4a88-8fa2-e781e1eba23e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#inspired by https://stackoverflow.com/questions/17758023/return-rows-in-a-dataframe-closest-to-a-user-defined-number/17758115#17758115\n",
    "def abs_dif(df,seed):\n",
    "    target = df[df['Words'] == seed].Prediction.iloc[0]\n",
    "    sub_df = df[df['Words'] != seed].reset_index()\n",
    "    nearest_prediction = sub_df.Prediction[(sub_df.Prediction-target).abs().argsort()[:1]]\n",
    "    farthest_prediction = sub_df.Prediction[(sub_df.Prediction-target).abs().argsort()[-1:]]\n",
    "    nearest = sub_df.Sentences.iloc[nearest_prediction.index[0]]\n",
    "    farthest = sub_df.Sentences.iloc[farthest_prediction.index[0]]\n",
    "    return target, nearest, farthest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "ae73d9ac-0a05-4d30-8aec-0f40f05b7b16",
   "metadata": {},
   "outputs": [],
   "source": [
    "target, near, far = abs_dif(panic,\"film\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "48312660-33af-4909-98f1-6134215e63bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'This abstraction was filmed in Iraq.'"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "near"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "37f226d4-dad7-42b1-9b1c-4e60fb5f3504",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'This positive was filmed in Iraq.'"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "far"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "2a631966-025c-4964-bb22-bb245f0aeb57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.9771453142166138"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval_pred_test(near)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "777afc55-f701-4452-82ad-1b5487b68d29",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9987342953681946"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval_pred_test(far)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "c9a92eef-9649-439e-b669-15cd360a3019",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.9768388867378235"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e69f1778-22bf-47cc-8ee9-dd90d7e6cebf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}