File size: 36,478 Bytes
2d4243e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-07-07 17:13:01.457105: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
      "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import gensim\n",
    "import pprint\n",
    "from gensim import corpora\n",
    "from gensim.utils import simple_preprocess\n",
    "from gensim.models import TfidfModel\n",
    "from gensim.parsing import strip_tags, strip_numeric, \\\n",
    "    strip_multiple_whitespaces, stem_text, strip_punctuation, \\\n",
    "    remove_stopwords, preprocess_string\n",
    "import re\n",
    "import os\n",
    "\n",
    "from typing import List\n",
    "import spacy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "transform_to_lower = lambda s: s.lower()\n",
    "remove_single_char = lambda s: re.sub(r'\\s+\\w{1}\\s+', '', s)\n",
    "\n",
    "cleaning_filters = [\n",
    "    strip_tags,\n",
    "    strip_numeric,\n",
    "    strip_punctuation, \n",
    "    strip_multiple_whitespaces, \n",
    "    transform_to_lower,\n",
    "    remove_stopwords,\n",
    "    remove_single_char\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_parquet(\"/Users/luis.morales/Desktop/arxiv-paper-recommender/data/processed/reduced_arxiv_papers.parquet.gzip\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "638707"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(df.shape[0] * 0.75) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_parquet(\"/Users/luis.morales/Desktop/arxiv-paper-recommender/data/processed/reduced_arxiv_papers.parquet.gzip\").sample().reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "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>id</th>\n",
       "      <th>submitter</th>\n",
       "      <th>authors</th>\n",
       "      <th>title</th>\n",
       "      <th>comments</th>\n",
       "      <th>journal-ref</th>\n",
       "      <th>doi</th>\n",
       "      <th>report-no</th>\n",
       "      <th>categories</th>\n",
       "      <th>license</th>\n",
       "      <th>abstract</th>\n",
       "      <th>versions</th>\n",
       "      <th>update_date</th>\n",
       "      <th>authors_parsed</th>\n",
       "      <th>cleaned_abstracts</th>\n",
       "      <th>len_abstract</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2007.00905</td>\n",
       "      <td>Song Qingheng</td>\n",
       "      <td>Qingheng Song, Yong Zeng, Jie Xu, and Shi Jin</td>\n",
       "      <td>A Survey of Prototype and Experiment for UAV C...</td>\n",
       "      <td>24 pages, 6 figures</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>cs.IT eess.SP math.IT</td>\n",
       "      <td>http://creativecommons.org/licenses/by-nc-sa/4.0/</td>\n",
       "      <td>Unmanned aerial vehicle (UAV) communications...</td>\n",
       "      <td>[{'created': 'Thu, 2 Jul 2020 06:26:20 GMT', '...</td>\n",
       "      <td>2020-07-03</td>\n",
       "      <td>[[Song, Qingheng, ], [Zeng, Yong, ], [Xu, Jie,...</td>\n",
       "      <td>unmanned aerial vehicle uav communication a...</td>\n",
       "      <td>865</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2102.04209</td>\n",
       "      <td>Michael Stuart</td>\n",
       "      <td>Michael T. Stuart and Markus Kneer</td>\n",
       "      <td>Guilty Artificial Minds</td>\n",
       "      <td>20 pages, 4 figures, 1 table</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>cs.CY cs.AI cs.HC</td>\n",
       "      <td>http://creativecommons.org/licenses/by/4.0/</td>\n",
       "      <td>The concepts of blameworthiness and wrongnes...</td>\n",
       "      <td>[{'created': 'Sun, 24 Jan 2021 21:37:35 GMT', ...</td>\n",
       "      <td>2021-02-09</td>\n",
       "      <td>[[Stuart, Michael T., ], [Kneer, Markus, ]]</td>\n",
       "      <td>concept blameworthiness wrongness fundament...</td>\n",
       "      <td>739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1201.5796</td>\n",
       "      <td>Denis Jerome</td>\n",
       "      <td>Denis Jerome</td>\n",
       "      <td>Organic Superconductors: when correlations and...</td>\n",
       "      <td>41 pages, 21 figures to be published in Journa...</td>\n",
       "      <td>None</td>\n",
       "      <td>10.1007/s10948-012-1475-7</td>\n",
       "      <td>None</td>\n",
       "      <td>cond-mat.supr-con</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>This survey provides a brief account for the...</td>\n",
       "      <td>[{'created': 'Fri, 27 Jan 2012 15:24:46 GMT', ...</td>\n",
       "      <td>2012-02-21</td>\n",
       "      <td>[[Jerome, Denis, ]]</td>\n",
       "      <td>survey provide brief account start organic ...</td>\n",
       "      <td>649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1511.03076</td>\n",
       "      <td>Emma Platts Miss</td>\n",
       "      <td>George F.R. Ellis, Emma Platts, David Sloan an...</td>\n",
       "      <td>Current observations with a decaying cosmologi...</td>\n",
       "      <td>23 pages, 11 figures</td>\n",
       "      <td>None</td>\n",
       "      <td>10.1088/1475-7516/2016/04/026</td>\n",
       "      <td>None</td>\n",
       "      <td>astro-ph.CO gr-qc hep-th</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>We use the phase plane analysis technique of...</td>\n",
       "      <td>[{'created': 'Tue, 10 Nov 2015 12:08:23 GMT', ...</td>\n",
       "      <td>2016-04-27</td>\n",
       "      <td>[[Ellis, George F. R., ], [Platts, Emma, ], [S...</td>\n",
       "      <td>use phase plane analysis technique madsen e...</td>\n",
       "      <td>554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1710.02954</td>\n",
       "      <td>Kirk Bansak</td>\n",
       "      <td>Kirk Bansak</td>\n",
       "      <td>Estimating Causal Moderation Effects with Rand...</td>\n",
       "      <td>Forthcoming, Journal of the Royal Statistical ...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>stat.ME</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>Researchers are often interested in analyzin...</td>\n",
       "      <td>[{'created': 'Mon, 9 Oct 2017 06:34:01 GMT', '...</td>\n",
       "      <td>2020-08-25</td>\n",
       "      <td>[[Bansak, Kirk, ]]</td>\n",
       "      <td>researcher interested analyze conditional t...</td>\n",
       "      <td>799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>851605</th>\n",
       "      <td>1301.0707</td>\n",
       "      <td>Sebastian Klein</td>\n",
       "      <td>Sebastian Klein</td>\n",
       "      <td>Chow groups of tensor triangulated categories</td>\n",
       "      <td>40 pages. The presentation of the article has ...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>math.AG math.CT math.RT</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>We recall P. Balmer's definition of tensor t...</td>\n",
       "      <td>[{'created': 'Fri, 4 Jan 2013 11:06:40 GMT', '...</td>\n",
       "      <td>2015-10-02</td>\n",
       "      <td>[[Klein, Sebastian, ]]</td>\n",
       "      <td>recall p. balmer definition tensor triangul...</td>\n",
       "      <td>787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>851606</th>\n",
       "      <td>1707.00341</td>\n",
       "      <td>Giorgos Anastasiou</td>\n",
       "      <td>Giorgos Anastasiou, Rodrigo Olea, David Rivera...</td>\n",
       "      <td>Noether-Wald energy in Critical Gravity</td>\n",
       "      <td>7 pages, no figures, Final version for PLB</td>\n",
       "      <td>None</td>\n",
       "      <td>10.1016/j.physletb.2018.11.021</td>\n",
       "      <td>None</td>\n",
       "      <td>hep-th gr-qc</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>Criticality represents a specific point in t...</td>\n",
       "      <td>[{'created': 'Sun, 2 Jul 2017 19:52:32 GMT', '...</td>\n",
       "      <td>2018-11-21</td>\n",
       "      <td>[[Anastasiou, Giorgos, ], [Olea, Rodrigo, ], [...</td>\n",
       "      <td>criticality represent specific point parame...</td>\n",
       "      <td>631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>851607</th>\n",
       "      <td>1610.08526</td>\n",
       "      <td>Blagoje Oblak</td>\n",
       "      <td>Blagoje Oblak</td>\n",
       "      <td>BMS Particles in Three Dimensions</td>\n",
       "      <td>437 pages (including index), 33 figures. Appen...</td>\n",
       "      <td>None</td>\n",
       "      <td>10.1007/978-3-319-61878-4</td>\n",
       "      <td>None</td>\n",
       "      <td>hep-th gr-qc math-ph math.GR math.MP math.RT</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>This thesis is devoted to the group-theoreti...</td>\n",
       "      <td>[{'created': 'Wed, 26 Oct 2016 20:00:16 GMT', ...</td>\n",
       "      <td>2018-01-29</td>\n",
       "      <td>[[Oblak, Blagoje, ]]</td>\n",
       "      <td>thesis devoted group theoretic aspect dimen...</td>\n",
       "      <td>542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>851608</th>\n",
       "      <td>1211.6629</td>\n",
       "      <td>Philippe Joyez</td>\n",
       "      <td>Philippe Joyez</td>\n",
       "      <td>Self-consistent dynamics of a Josephson juncti...</td>\n",
       "      <td>7 pages, 1 figure</td>\n",
       "      <td>None</td>\n",
       "      <td>10.1103/PhysRevLett.110.217003</td>\n",
       "      <td>None</td>\n",
       "      <td>cond-mat.supr-con cond-mat.mes-hall</td>\n",
       "      <td>http://arxiv.org/licenses/nonexclusive-distrib...</td>\n",
       "      <td>We derive microscopically the dynamics assoc...</td>\n",
       "      <td>[{'created': 'Tue, 27 Nov 2012 17:29:04 GMT', ...</td>\n",
       "      <td>2013-05-29</td>\n",
       "      <td>[[Joyez, Philippe, ]]</td>\n",
       "      <td>derive microscopically dynamic associate d....</td>\n",
       "      <td>558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>851609</th>\n",
       "      <td>0705.2878</td>\n",
       "      <td>Benoit Perthame</td>\n",
       "      <td>Benoit Perthame (DMA), Panagiotis E. Souganidis</td>\n",
       "      <td>Asymmetric potentials and motor effect: a larg...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>math.AP</td>\n",
       "      <td>None</td>\n",
       "      <td>We provide a mathematical analysis of appear...</td>\n",
       "      <td>[{'created': 'Sun, 20 May 2007 17:43:39 GMT', ...</td>\n",
       "      <td>2007-05-23</td>\n",
       "      <td>[[Perthame, Benoit, , DMA], [Souganidis, Panag...</td>\n",
       "      <td>provide mathematical analysis appearance co...</td>\n",
       "      <td>518</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>851610 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                id           submitter   \n",
       "0       2007.00905       Song Qingheng  \\\n",
       "1       2102.04209      Michael Stuart   \n",
       "2        1201.5796        Denis Jerome   \n",
       "3       1511.03076    Emma Platts Miss   \n",
       "4       1710.02954         Kirk Bansak   \n",
       "...            ...                 ...   \n",
       "851605   1301.0707     Sebastian Klein   \n",
       "851606  1707.00341  Giorgos Anastasiou   \n",
       "851607  1610.08526       Blagoje Oblak   \n",
       "851608   1211.6629      Philippe Joyez   \n",
       "851609   0705.2878     Benoit Perthame   \n",
       "\n",
       "                                                  authors   \n",
       "0           Qingheng Song, Yong Zeng, Jie Xu, and Shi Jin  \\\n",
       "1                      Michael T. Stuart and Markus Kneer   \n",
       "2                                            Denis Jerome   \n",
       "3       George F.R. Ellis, Emma Platts, David Sloan an...   \n",
       "4                                             Kirk Bansak   \n",
       "...                                                   ...   \n",
       "851605                                    Sebastian Klein   \n",
       "851606  Giorgos Anastasiou, Rodrigo Olea, David Rivera...   \n",
       "851607                                      Blagoje Oblak   \n",
       "851608                                     Philippe Joyez   \n",
       "851609    Benoit Perthame (DMA), Panagiotis E. Souganidis   \n",
       "\n",
       "                                                    title   \n",
       "0       A Survey of Prototype and Experiment for UAV C...  \\\n",
       "1                                 Guilty Artificial Minds   \n",
       "2       Organic Superconductors: when correlations and...   \n",
       "3       Current observations with a decaying cosmologi...   \n",
       "4       Estimating Causal Moderation Effects with Rand...   \n",
       "...                                                   ...   \n",
       "851605      Chow groups of tensor triangulated categories   \n",
       "851606            Noether-Wald energy in Critical Gravity   \n",
       "851607                  BMS Particles in Three Dimensions   \n",
       "851608  Self-consistent dynamics of a Josephson juncti...   \n",
       "851609  Asymmetric potentials and motor effect: a larg...   \n",
       "\n",
       "                                                 comments journal-ref   \n",
       "0                                     24 pages, 6 figures        None  \\\n",
       "1                            20 pages, 4 figures, 1 table        None   \n",
       "2       41 pages, 21 figures to be published in Journa...        None   \n",
       "3                                    23 pages, 11 figures        None   \n",
       "4       Forthcoming, Journal of the Royal Statistical ...        None   \n",
       "...                                                   ...         ...   \n",
       "851605  40 pages. The presentation of the article has ...        None   \n",
       "851606         7 pages, no figures, Final version for PLB        None   \n",
       "851607  437 pages (including index), 33 figures. Appen...        None   \n",
       "851608                                  7 pages, 1 figure        None   \n",
       "851609                                               None        None   \n",
       "\n",
       "                                   doi report-no   \n",
       "0                                 None      None  \\\n",
       "1                                 None      None   \n",
       "2            10.1007/s10948-012-1475-7      None   \n",
       "3        10.1088/1475-7516/2016/04/026      None   \n",
       "4                                 None      None   \n",
       "...                                ...       ...   \n",
       "851605                            None      None   \n",
       "851606  10.1016/j.physletb.2018.11.021      None   \n",
       "851607       10.1007/978-3-319-61878-4      None   \n",
       "851608  10.1103/PhysRevLett.110.217003      None   \n",
       "851609                            None      None   \n",
       "\n",
       "                                          categories   \n",
       "0                              cs.IT eess.SP math.IT  \\\n",
       "1                                  cs.CY cs.AI cs.HC   \n",
       "2                                  cond-mat.supr-con   \n",
       "3                           astro-ph.CO gr-qc hep-th   \n",
       "4                                            stat.ME   \n",
       "...                                              ...   \n",
       "851605                       math.AG math.CT math.RT   \n",
       "851606                                  hep-th gr-qc   \n",
       "851607  hep-th gr-qc math-ph math.GR math.MP math.RT   \n",
       "851608           cond-mat.supr-con cond-mat.mes-hall   \n",
       "851609                                       math.AP   \n",
       "\n",
       "                                                  license   \n",
       "0       http://creativecommons.org/licenses/by-nc-sa/4.0/  \\\n",
       "1             http://creativecommons.org/licenses/by/4.0/   \n",
       "2       http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "3       http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "4       http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "...                                                   ...   \n",
       "851605  http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "851606  http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "851607  http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "851608  http://arxiv.org/licenses/nonexclusive-distrib...   \n",
       "851609                                               None   \n",
       "\n",
       "                                                 abstract   \n",
       "0         Unmanned aerial vehicle (UAV) communications...  \\\n",
       "1         The concepts of blameworthiness and wrongnes...   \n",
       "2         This survey provides a brief account for the...   \n",
       "3         We use the phase plane analysis technique of...   \n",
       "4         Researchers are often interested in analyzin...   \n",
       "...                                                   ...   \n",
       "851605    We recall P. Balmer's definition of tensor t...   \n",
       "851606    Criticality represents a specific point in t...   \n",
       "851607    This thesis is devoted to the group-theoreti...   \n",
       "851608    We derive microscopically the dynamics assoc...   \n",
       "851609    We provide a mathematical analysis of appear...   \n",
       "\n",
       "                                                 versions update_date   \n",
       "0       [{'created': 'Thu, 2 Jul 2020 06:26:20 GMT', '...  2020-07-03  \\\n",
       "1       [{'created': 'Sun, 24 Jan 2021 21:37:35 GMT', ...  2021-02-09   \n",
       "2       [{'created': 'Fri, 27 Jan 2012 15:24:46 GMT', ...  2012-02-21   \n",
       "3       [{'created': 'Tue, 10 Nov 2015 12:08:23 GMT', ...  2016-04-27   \n",
       "4       [{'created': 'Mon, 9 Oct 2017 06:34:01 GMT', '...  2020-08-25   \n",
       "...                                                   ...         ...   \n",
       "851605  [{'created': 'Fri, 4 Jan 2013 11:06:40 GMT', '...  2015-10-02   \n",
       "851606  [{'created': 'Sun, 2 Jul 2017 19:52:32 GMT', '...  2018-11-21   \n",
       "851607  [{'created': 'Wed, 26 Oct 2016 20:00:16 GMT', ...  2018-01-29   \n",
       "851608  [{'created': 'Tue, 27 Nov 2012 17:29:04 GMT', ...  2013-05-29   \n",
       "851609  [{'created': 'Sun, 20 May 2007 17:43:39 GMT', ...  2007-05-23   \n",
       "\n",
       "                                           authors_parsed   \n",
       "0       [[Song, Qingheng, ], [Zeng, Yong, ], [Xu, Jie,...  \\\n",
       "1             [[Stuart, Michael T., ], [Kneer, Markus, ]]   \n",
       "2                                     [[Jerome, Denis, ]]   \n",
       "3       [[Ellis, George F. R., ], [Platts, Emma, ], [S...   \n",
       "4                                      [[Bansak, Kirk, ]]   \n",
       "...                                                   ...   \n",
       "851605                             [[Klein, Sebastian, ]]   \n",
       "851606  [[Anastasiou, Giorgos, ], [Olea, Rodrigo, ], [...   \n",
       "851607                               [[Oblak, Blagoje, ]]   \n",
       "851608                              [[Joyez, Philippe, ]]   \n",
       "851609  [[Perthame, Benoit, , DMA], [Souganidis, Panag...   \n",
       "\n",
       "                                        cleaned_abstracts  len_abstract  \n",
       "0          unmanned aerial vehicle uav communication a...           865  \n",
       "1          concept blameworthiness wrongness fundament...           739  \n",
       "2          survey provide brief account start organic ...           649  \n",
       "3          use phase plane analysis technique madsen e...           554  \n",
       "4          researcher interested analyze conditional t...           799  \n",
       "...                                                   ...           ...  \n",
       "851605     recall p. balmer definition tensor triangul...           787  \n",
       "851606     criticality represent specific point parame...           631  \n",
       "851607     thesis devoted group theoretic aspect dimen...           542  \n",
       "851608     derive microscopically dynamic associate d....           558  \n",
       "851609     provide mathematical analysis appearance co...           518  \n",
       "\n",
       "[851610 rows x 16 columns]"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "corpus = df['cleaned_abstracts'].to_list()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "def gensim_tokenizer(docs: List[str]):\n",
    "    tokenized_docs = list()\n",
    "    for doc in docs:\n",
    "        processed_words = preprocess_string(doc, cleaning_filters)\n",
    "        tokenized_docs.append(processed_words)\n",
    "    \n",
    "    return tokenized_docs\n",
    "\n",
    "tokenized_corpus = gensim_tokenizer(corpus)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "851610"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(tokenized_corpus)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cleaning_pipe(document):\n",
    "    # Invoking gensim.parsing.preprocess_string method with set of filters\n",
    "    processed_words = preprocess_string(document, cleaning_filters)\n",
    "    return processed_words"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/luis.morales/Desktop/arxiv-paper-recommender/models\n",
      "/Users/luis.morales/Desktop/arxiv-paper-recommender\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def validate_if_dictionary_exists(dictionaty_name: str) -> bool:\n",
    "    dicts_folder = \"models/nlp_dictionaries\"\n",
    "    current_dir = os.getcwd()\n",
    "    parent_dir = os.path.dirname(current_dir)\n",
    "    dict_path = f\"{parent_dir}/{dicts_folder}/{dictionaty_name}\"\n",
    "    print(current_dir)\n",
    "    print(parent_dir)\n",
    "    return os.path.isfile(dict_path)\n",
    "    \n",
    "\n",
    "validate_if_dictionary_exists('30ktokens.dict')    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_gensim_dictionary(tokenized_docs: List[str], dict_name: str = \"corpus\", save_dict: bool = False):\n",
    "    \"\"\"\n",
    "        Create dictionary of words in preprocessed corpus and saves the dict object\n",
    "    \"\"\"\n",
    "    dictionary = corpora.Dictionary(tokenized_docs)\n",
    "    if save_dict:    \n",
    "        dict_lenght = len(tokenized_corpus)\n",
    "        parent_folder = \"/Users/luis.morales/Desktop/arxiv-paper-recommender/models/dictionaries\"\n",
    "        #if validate_if_dictionary_exists('30ktokens.dict'):\n",
    "        dictionary.save(f'{parent_folder}/{dict_name}.dict')\n",
    "        \n",
    "    return dictionary\n",
    "\n",
    "dictionary = get_gensim_dictionary(tokenized_docs=tokenized_corpus, dict_name=\"TextualTango\", save_dict=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# def get_gensim_dictionary(tokenized_docs: List[str], dict_name: str = \"corpus\", save_dict: bool = False):\n",
    "#     \"\"\"\n",
    "#         Create dictionary of words in preprocessed corpus and saves the dict object\n",
    "#     \"\"\"\n",
    "#     dictionary = corpora.Dictionary(tokenized_docs)\n",
    "#     if save_dict:    \n",
    "#         dict_lenght = len(tokenized_corpus)\n",
    "#         parent_folder = \"/Users/luis.morales/Desktop/arxiv-paper-recommender/models/nlp_dictionaries\"\n",
    "#         if validate_if_dictionary_exists('30ktokens.dict'):\n",
    "#             dictionary.save(f'{parent_folder}/{dict_name}.dict')\n",
    "        \n",
    "#     return dictionary\n",
    "\n",
    "# dictionary = get_gensim_dictionary(tokenized_docs=tokenized_corpus, dict_name=\"300Ktokens\", save_dict=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "BoW_corpus = [dictionary.doc2bow(doc, allow_update=True) for doc in tokenized_corpus]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "tfidf_model = TfidfModel(BoW_corpus)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "tfidf_model.save(\"/Users/luis.morales/Desktop/arxiv-paper-recommender/models/tfidf/TextualTango.model\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "# index the tfidf vector of corpus as sparse matrix\n",
    "from gensim import similarities\n",
    "index = similarities.SparseMatrixSimilarity(tfidf_model[BoW_corpus], num_features=len(dictionary))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "index.save(\"/Users/luis.morales/Desktop/arxiv-paper-recommender/models/similarities_matrix/TextualTangoSimilarities/TextualTango\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_closest_n(query, n):\n",
    "    '''get the top matching docs as per cosine similarity\n",
    "    between tfidf vector of query and all docs'''\n",
    "    query_document = cleaning_pipe(query)\n",
    "    query_bow = dictionary.doc2bow(query_document)\n",
    "    sims = index[tfidf_model[query_bow]]\n",
    "    top_idx = sims.argsort()[-1*n:][::-1]\n",
    "    return top_idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_recomendations_metadata(query: str, n: int, df: pd.DataFrame):\n",
    "    recommendations_idxs = get_closest_n(query, n)\n",
    "    return df.iloc[recommendations_idxs].reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "User Request ---- : \n",
      " Which papers discuss the use of statistical models and Bayesian inference for uncertainty quantification and risk assessment in engineering systems?\n",
      "User Request ---- : \n",
      " \n",
      "Title: A framework for benchmarking uncertainty in deep regression\n",
      "Abstract:   We propose a framework for the assessment of uncertainty quantification in\n",
      "deep regression. The framework is based on regression problems where the\n",
      "regression function is a linear combination of nonlinear functions. Basically,\n",
      "any level of complexity can be realized through the choice of the nonlinear\n",
      "functions and the dimensionality of their domain. Results of an uncertainty\n",
      "quantification for deep regression are compared against those obtained by a\n",
      "statistical reference method. The reference method utilizes knowledge of the\n",
      "underlying nonlinear functions and is based on a Bayesian linear regression\n",
      "using a reference prior. Reliability of uncertainty quantification is assessed\n",
      "in terms of coverage probabilities, and accuracy through the size of calculated\n",
      "uncertainties. We illustrate the proposed framework by applying it to current\n",
      "approaches for uncertainty quantification in deep regression. The flexibility,\n",
      "together with the availability of a reference solution, makes the framework\n",
      "suitable for defining benchmark sets for uncertainty quantification.\n",
      "\n",
      "\n",
      "--------------------------\n",
      "User Request ---- : \n",
      " Which papers discuss the use of statistical models and Bayesian inference for uncertainty quantification and risk assessment in engineering systems?\n",
      "User Request ---- : \n",
      " \n",
      "Title: Generative Parameter Sampler For Scalable Uncertainty Quantification\n",
      "Abstract:   Uncertainty quantification has been a core of the statistical machine\n",
      "learning, but its computational bottleneck has been a serious challenge for\n",
      "both Bayesians and frequentists. We propose a model-based framework in\n",
      "quantifying uncertainty, called predictive-matching Generative Parameter\n",
      "Sampler (GPS). This procedure considers an Uncertainty Quantification (UQ)\n",
      "distribution on the targeted parameter, which matches the corresponding\n",
      "predictive distribution to the observed data. This framework adopts a\n",
      "hierarchical modeling perspective such that each observation is modeled by an\n",
      "individual parameter. This individual parameterization permits the resulting\n",
      "inference to be computationally scalable and robust to outliers. Our approach\n",
      "is illustrated for linear models, Poisson processes, and deep neural networks\n",
      "for classification. The results show that the GPS is successful in providing\n",
      "uncertainty quantification as well as additional flexibility beyond what is\n",
      "allowed by classical statistical procedures under the postulated statistical\n",
      "models.\n",
      "\n",
      "\n",
      "--------------------------\n",
      "User Request ---- : \n",
      " Which papers discuss the use of statistical models and Bayesian inference for uncertainty quantification and risk assessment in engineering systems?\n",
      "User Request ---- : \n",
      " \n",
      "Title: Recent Advances in Uncertainty Quantification Methods for Engineering\n",
      "  Problems\n",
      "Abstract:   In the last few decades, uncertainty quantification (UQ) methods have been\n",
      "used widely to ensure the robustness of engineering designs. This chapter aims\n",
      "to detail recent advances in popular uncertainty quantification methods used in\n",
      "engineering applications. This chapter describes the two most popular\n",
      "meta-modeling methods for uncertainty quantification suitable for engineering\n",
      "applications (Polynomial Chaos Method and Gaussian Process). Further, the UQ\n",
      "methods are applied to an engineering test problem under multiple\n",
      "uncertainties. The test problem considered here is a supersonic nozzle under\n",
      "operational uncertainties. For the deterministic solution, an open-source\n",
      "computational fluid dynamics (CFD) solver SU2 is used. The UQ methods are\n",
      "developed in Matlab and are further combined with SU2 for the uncertainty and\n",
      "sensitivity estimates. The results are presented in terms of the mean and\n",
      "standard deviation of the output quantities.\n",
      "\n",
      "\n",
      "--------------------------\n"
     ]
    }
   ],
   "source": [
    "_input = \"Which papers discuss the use of statistical models and Bayesian inference for uncertainty quantification and risk assessment in engineering systems?\"\n",
    "results_df = get_recomendations_metadata(query=_input, df=df, n=3)\n",
    "\n",
    "\n",
    "for abstract in list(zip(results_df['abstract'].to_list(), results_df['title'].to_list())):\n",
    "    print(f\"User Request ---- : \\n {_input}\")\n",
    "    print(f\"User Request ---- : \\n \")\n",
    "    print(f\"Title: {abstract[1]}\")\n",
    "    print(f\"Abstract: {abstract[0]}\\n\")\n",
    "    print(f\"--------------------------\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.11.4 ('arxiv-env': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "aae17c2ae2f38cc6f211be9b71a2aa280701d8462782cbc1f67caa83a1603363"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}