File size: 52,331 Bytes
e137e27
 
 
 
 
 
 
87a6313
e137e27
 
4028499
564e0a1
e137e27
25a9fcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9f2fad
 
 
 
 
 
e8dab56
b9f2fad
e8dab56
b9f2fad
 
e8dab56
b9f2fad
 
e8dab56
b9f2fad
 
5e5aef1
e8dab56
 
b9f2fad
4254834
b9f2fad
 
 
 
67e65d7
b9f2fad
25a9fcb
5e5aef1
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
48b277d
5e5aef1
 
 
 
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
48b277d
5e5aef1
 
 
 
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
48b277d
5e5aef1
 
 
 
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
48b277d
5e5aef1
 
 
 
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
 
 
 
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
48b277d
5e5aef1
 
 
 
 
4254834
5e5aef1
 
 
 
 
 
25a9fcb
d82cc95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f66aa60
 
ee43c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87a6313
 
 
beddb3a
 
ee43c81
beddb3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa54686
ee43c81
0bc171c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d11c1f
0bc171c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
0bc171c
5171d34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fd33e
8a16e84
24b53c0
8feeca0
7cc1892
8feeca0
24b53c0
103b5cf
583d7c5
0dbc84f
24b53c0
f36591a
24b53c0
f36591a
67e65d7
ee43c81
 
6a7bb93
ee43c81
103b5cf
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
5672cf7
583d7c5
5672cf7
583d7c5
5672cf7
 
c642284
5672cf7
583d7c5
5e5aef1
8a16e84
 
 
 
5094bb7
583d7c5
 
5094bb7
9f2a4f7
9fd7ac0
583d7c5
 
 
 
 
 
0cee378
583d7c5
 
 
 
 
 
 
 
b4e3ff3
583d7c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e5aef1
8a16e84
 
 
 
5094bb7
583d7c5
 
5094bb7
5672cf7
9fd7ac0
583d7c5
 
 
 
 
 
 
 
 
b4e3ff3
583d7c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e5aef1
8a16e84
 
 
 
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
5672cf7
583d7c5
 
 
 
5e5aef1
0bc171c
 
 
 
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
5672cf7
583d7c5
5672cf7
5e5aef1
8a16e84
 
 
 
583d7c5
5094bb7
583d7c5
5094bb7
583d7c5
9fd7ac0
583d7c5
5672cf7
 
583d7c5
 
5672cf7
 
 
583d7c5
5e5aef1
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
5672cf7
583d7c5
 
5672cf7
 
 
583d7c5
5e5aef1
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
f43eed3
dac95a4
5672cf7
 
 
 
 
 
 
dac95a4
 
583d7c5
 
5672cf7
 
 
583d7c5
 
 
 
 
5e5aef1
beddb3a
 
 
 
f66aa60
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
063c1ad
5672cf7
 
583d7c5
 
 
 
 
 
 
 
5672cf7
583d7c5
 
5672cf7
583d7c5
5e5aef1
0bc171c
 
 
 
5094bb7
583d7c5
 
5094bb7
583d7c5
9fd7ac0
583d7c5
eee4211
5672cf7
ff67812
 
 
 
 
 
666337a
 
ff67812
 
 
 
583d7c5
 
5672cf7
 
 
583d7c5
ee43c81
5094bb7
583d7c5
 
5094bb7
 
9fd7ac0
583d7c5
5672cf7
 
 
 
583d7c5
 
5672cf7
583d7c5
 
 
 
 
5e5aef1
8a16e84
 
 
 
5094bb7
583d7c5
 
5094bb7
9fd7ac0
 
583d7c5
 
5672cf7
583d7c5
 
 
5672cf7
 
 
583d7c5
5e5aef1
8a16e84
 
 
 
5094bb7
24b53c0
 
 
 
 
 
31b08ca
 
25a9fcb
9f87a47
 
 
 
 
 
 
 
31b08ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e137e27
d82cc95
e137e27
 
 
 
 
 
 
 
 
 
2018e3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cc1892
2018e3d
 
 
 
 
 
 
 
 
 
f66aa60
858c4bf
e137e27
31b08ca
 
 
 
 
 
 
 
 
 
 
 
 
e137e27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5dd5e15
e137e27
 
 
 
89ba804
e137e27
7381c06
 
 
 
 
 
 
 
 
 
 
6e60fe2
7381c06
 
 
 
 
 
 
 
 
24b53c0
e137e27
baad9f2
5493cad
 
 
bb8c2a5
25a9fcb
8feeca0
7cc1892
 
24b53c0
89ba804
7cc1892
 
 
ee3ad0f
f3f6d37
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
from fasthtml.common import *
from fasthtml.components import *
from plotly import graph_objects as go
from fh_plotly import plotly2fasthtml
import pandas as pd
import json
from data_viewer import view_data, gen_random_id
from data_viewer import DV, DV2, DVS
from rich import print
import uuid
import plotly.express as px
from fasthtml.components import D_code

overview = Div(
            H2("Curated Source Processing Overview"),
            H3("What This Section Contains"),
            P("This section provides a complete discussion on the filtering applied to the 14 curated sources that comprise the non-web data section of TxT360. The section is split into the following topic areas: "),
            Ul(
                Li("Curated Sources Data Processing Summary", style = "margin-bottom: 5px"),
                Li("Individual Filtering Discussion for Each Source", style = "margin-bottom: 5px"),
            ),
        ),

overview_text = P("Curated sources comprise high-quality datasets that contain domain-specificity. These sources, such as Arxiv, Wikipedia, and Stack Exchange, provide valuable data that is excluded from the web dataset mentioned above. Analyzing and processing non-web data can yield insights and opportunities for various applications. Details about each of the sources are provided below. ")
copyright_disclaimer = P("We respect the copyright of the data sources and have not included the controversial data that was used in Pile like YouTube and Opensubtitles, Reddit threads, and books.")

treemap_data = {
  'Source': ['ArXiv', 'PubMed Central', 'PubMed Abstract', 'S2ORC Full Text', 'S2ORC Abstract', 'PhilPapers', 'Wikipedia', 'StackExchange', 'EuroParl', 'Ubuntu IRC', 'Freelaw', 'PG19', 'USPTO', 'HackerNews', 'DM Maths'],
  'Category': ['Papers', 'Papers', 'Papers', 'Papers', 'Papers', 'Papers', 'Internet', 'Conversational', 'Legal/Formal', 'Conversational', 'Legal/Formal', 'Books', 'Legal/Formal', 'Conversational', 'Reasoning'],
  'Count': [100, 200, 150, 120, 80, 90, 300, 250, 180, 150, 150, 250, 180, 120, 90],
  'Details': [
    'A repository of scientific papers in various disciplines, including computer science, physics, mathematics, and more.',
    'A database of biomedical and life sciences research articles.',
    'Abstracts of biomedical literature from various sources.',
    'Full-text articles from the Semantic Scholar Open Research Corpus.',
    'Abstracts of articles from the Semantic Scholar Open Research Corpus.',
    'Papers from the PhilPapers database, a comprehensive index and bibliography of philosophy research.',
    'A collaborative online encyclopedia that covers a wide range of topics.',
    'A network of question-and-answer websites on various subjects, including programming, science, mathematics, and more.',
    'A collection of multilingual parallel corpora of parliamentary debates from the European Parliament.',
    'Chat logs from the Ubuntu Internet Relay Chat (IRC) channels.',
    'Legal documents and court cases from various jurisdictions.',
    'A collection of books from Project Gutenberg, a digital library of public domain works.',
    'Patent documents from the United States Patent and Trademark Office.',
    'User-generated news and discussion platform focused on technology and startups.',
    'Deep Mind Maths dataset with generated questions.'
  ]
}
# Calculate percentage for each data source
total_count = sum(treemap_data['Count'])
treemap_data['Percentage'] = [count / total_count * 100 for count in treemap_data['Count']]

# Create treemap
fig = px.treemap(treemap_data, path=['Category', 'Source'], values='Count', hover_data=['Details', 'Percentage'], hover_name='Source')

# Set the size of the chart


# Display treemap if you want to update the size.update_layout(width=800, height=600)
treemap_chart = fig

wikipedia_filter = pd.DataFrame(
        {
            "Dataset": [
                "Wikipedia",
            ],
            "Lines Downloaded": [
                "61614907",
            ],
            "Percent Removed After Language Filter": [
                "0.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "1.86%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.00%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "",
            ],
        }
    )

table_html_wikipedia = wikipedia_filter.to_html(index=False, border=0)
table_div_wikipedia = Div(NotStr(table_html_wikipedia), style="margin: 40px;")

freelaw_filter = pd.DataFrame(
        {
            "Dataset": [
                "FreeLaw",
            ],
            "Lines Downloaded": [
                "75971288",
            ],
            "Percent Removed After Language Filter": [
                "3.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "7.49%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.07%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_freelaw = freelaw_filter.to_html(index=False, border=0)
table_div_freelaw = Div(NotStr(table_html_freelaw), style="margin: 40px;")

dmm_filter = pd.DataFrame(
        {
            "Dataset": [
                "DM Math",
            ],
            "Lines Downloaded": [
                "112559888",
            ],
            "Percent Removed After Language Filter": [
                "0.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.00%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_dmm = dmm_filter.to_html(index=False, border=0)
table_div_dmm = Div(NotStr(table_html_dmm), style="margin: 40px;")


uspto_filter = pd.DataFrame(
        {
            "Dataset": [
                "USPTO",
            ],
            "Lines Downloaded": [
                "6880276",
            ],
            "Percent Removed After Language Filter": [
                "0.02%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "1.88%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.01%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_uspto = uspto_filter.to_html(index=False, border=0)
table_div_uspto = Div(NotStr(table_html_uspto), style="margin: 40px;")

pg19_filter = pd.DataFrame(
        {
            "Dataset": [
                "PG-19",
            ],
            "Lines Downloaded": [
                "28752",
            ],
            "Percent Removed After Language Filter": [
                "0.24%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.17%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_pg19 = pg19_filter.to_html(index=False, border=0)
table_div_pg19 = Div(NotStr(table_html_pg19), style="margin: 40px;")


hn_filter = pd.DataFrame(
        {
            "Dataset": [
                "HackerNews",
            ],
            "Lines Downloaded": [
                "2064931",
            ],
            "Percent Removed After Language Filter": [
                "2.62%%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.02%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.34%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_hn = hn_filter.to_html(index=False, border=0)
table_div_hn = Div(NotStr(table_html_hn), style="margin: 40px;")


uirc_filter = pd.DataFrame(
        {
            "Dataset": [
                "Ubunutu IRC",
            ],
            "Lines Downloaded": [
                "37966",
            ],
            "Percent Removed After Language Filter": [
                "38.10%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.14%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "1.12%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_uirc = uirc_filter.to_html(index=False, border=0)
table_div_uirc = Div(NotStr(table_html_uirc), style="margin: 40px;")

up_filter = pd.DataFrame(
        {
            "Dataset": [
                "EuroParl",
            ],
            "Lines Downloaded": [
                "69814",
            ],
            "Percent Removed After Language Filter": [
                "0.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.00%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_up = up_filter.to_html(index=False, border=0)
table_div_up = Div(NotStr(table_html_up), style="margin: 40px;")

se_filter = pd.DataFrame(
        {
            "Dataset": [
                "StackExchange",
            ],
            "Lines Downloaded": [
                "23246548",
            ],
            "Percent Removed After Language Filter": [
                "0.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.00%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_se = se_filter.to_html(index=False, border=0)
table_div_se = Div(NotStr(table_html_se), style="margin: 40px;")

arx_filter = pd.DataFrame(
        {
            "Dataset": [
                "ArXiv",
            ],
            "Lines Downloaded": [
                "1911867",
            ],
            "Percent Removed After Language Filter": [
                "2.22%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "5.65%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.07%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_arx = arx_filter.to_html(index=False, border=0)
table_div_arx = Div(NotStr(table_html_arx), style="margin: 40px;")

s2o_filter = pd.DataFrame(
        {
            "Dataset": [
                "S2ORC",
            ],
            "Lines Downloaded": [
                "12963563",
            ],
            "Percent Removed After Language Filter": [
                "0.00%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.00%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_s2o = s2o_filter.to_html(index=False, border=0)
table_div_s2o = Div(NotStr(table_html_s2o), style="margin: 40px;")

med_filter = pd.DataFrame(
        {
            "Dataset": [
                "PubMed - Central",
            ],
            "Lines Downloaded": [
                "5230932",
            ],
            "Percent Removed After Language Filter": [
                "7.66%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "1.29%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.02%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_med = med_filter.to_html(index=False, border=0)
table_div_med = Div(NotStr(table_html_med), style="margin: 40px;")

phil_filter = pd.DataFrame(
        {
            "Dataset": [
                "Phil Papers",
            ],
            "Lines Downloaded": [
                "49389",
            ],
            "Percent Removed After Language Filter": [
                "20.68%",
            ],
            "Percent Removed After Min Word Count Filter": [
                "0.00%",
            ],
            "Percent Removed After Unigram Probability Filter": [
                "0.12%",
            ],
            "Percent Removed After Local Dedup": [
                "",
            ],
            "Total Percentage Remaining": [
                "%",
            ],
        }
    )

table_html_phil = phil_filter.to_html(index=False, border=0)
table_div_phil = Div(NotStr(table_html_phil), style="margin: 40px;")

data_sources = [
    "Freelaw",
    "Wikipedia",
    "PhilPapers",
    "Arxiv",
    "S2ORC",
    "S2ORC Abstract",
    "Pubmed",
    "USPTO",
    "Hackernews",
    "Ubuntu IRC",
    "StackExchange",
    "DM Maths",
    "PG19",
    "Europarl",
]



def get_wiki_data(data_source: str = "Wikipedia", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "Wikipedia":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/wiki.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="Wikipedia",
        data_sources="Wikipedia",
        target=target,
    )

wiki_examples = Div(
    Div(
        get_wiki_data(target=gen_random_id()),
        style="border: 1px solid #ccc; padding: 20px;",
    ),
)

wiki_examples = DV("data/curated_samples/wiki.json", 0, "Wikipedia")


def get_freelaw_data(data_source: str = "Freelaw", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "Freelaw":
        raw_sample_doc = json.load(open("data/curated_samples/freelaw_raw.json"))
        extracted_sample_doc = json.load(
            open("data/curated_samples/freelaw_extract.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="Freelaw",
        data_sources="Freelaw",
        target=target,
    )

freelaw_examples = DV2("data/curated_samples/freelaw_raw.json", "data/curated_samples/freelaw_extract.json", 2)

def get_se_data(data_source: str = "StackExchange", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "StackExchange":
        raw_sample_doc = json.load(open("data/curated_samples/stackexchange_raw.json"))
        extracted_sample_doc = json.load(
            open("data/curated_samples/stackexchange_extract.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="StackExchange",
        data_sources="StackExchange",
        target=target,
    )

se_examples = DV2("data/curated_samples/stackexchange_raw.json", "data/curated_samples/stackexchange_extract.json", 0)

def get_phil_data(data_source: str = "PhilPapers", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "PhilPapers":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/philpapers_raw.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="PhilPapers",
        data_sources="PhilPapers",
        target=target,
    )

phil_examples = DV("data/curated_samples/philpapers_raw.json", 0, "PhilPapers")

def get_arx_data(data_source: str = "Arxiv", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "Arxiv":
        raw_sample_doc = json.load(open("data/curated_samples/arxiv_raw.json"))
        extracted_sample_doc = json.load(
            open("data/curated_samples/arxiv_extract.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="Arxiv",
        data_sources="Arxiv",
        target=target,
    )

arx_examples = DV("data/curated_samples/arxiv_extract.json", 0, "Arxiv")

def get_S2ORC_data(data_source: str = "S2ORC", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "S2ORC":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/s2orc_raw.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="S2ORC",
        data_sources="S2ORC",
        target=target,
    )

s2o_examples = DV("data/curated_samples/s2orc_raw.json", 0, "S2ORC")

def get_S2ORCA_data(data_source: str = "S2ORC Abstract", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "S2ORC":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/s2orc_abstract_raw.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="S2ORC Abstract",
        data_sources="S2ORC Abstract",
        target=target,
    )

s2oa_examples = DV("data/curated_samples/s2orc_abstract_raw.json", 0, "S2ORC Abstract")

def get_pubmed_data(data_source: str = "Pubmed", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "Pubmed":
        raw_sample_doc = json.load(open("data/curated_samples/pubmed_raw.json"))
        extracted_sample_doc = json.load(
            open("data/curated_samples/pubmed_extract.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="Pubmed",
        data_sources="Pubmed",
        target=target,
    )

pubmed_examples = DV("data/curated_samples/pubmed_extract.json", 0, "PubMed")

def get_dmm_data(data_source: str = "DM Math", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "DM Math":
        raw_sample_doc = json.load(open("data/curated_samples/dm_maths_raw.json"))
        extracted_sample_doc = json.load(
            open("data/curated_samples/dm_maths_extract.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="DM Math",
        data_sources="DM Math",
        target=target,
    )

dmm_examples = DV("data/curated_samples/dm_maths_extract.json", 0, "DM Math")

def get_pg19_data(data_source: str = "PG19", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "PG19":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/pg19_raw.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="PG19",
        data_sources="PG19",
        target=target,
    )

pg19_examples = DV("data/curated_samples/pg19_raw.json", 0, "PG19")

def get_eu_data(data_source: str = "Europarl", doc_id: int = 3, target: str = "foo"):
    doc_id = max(0, min(int(doc_id), 9))

    if data_source == "Europarl":
        raw_sample_doc = extracted_sample_doc = json.load(
            open("data/curated_samples/europarl_raw.json")
        )
    else:
        raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]

    raw_json = raw_sample_doc[doc_id]
    extracted_json = extracted_sample_doc[doc_id]
    return view_data(
        raw_json,
        extracted_json,
        doc_id=doc_id,
        data_source="Europarl",
        data_sources="Europarl",
        target=target,
    )

eu_examples = DV("data/curated_samples/europarl_raw.json", 0, "Europarl")

filtering_process = Div(
    Section(
          H3("This section contains the specific filtering steps taken for all 14 curated datasets."),
    ),
    Section(
        Div(
        H3("Wikipedia"),
        P("Wikipedia is an encyclopedia form of high-quality text data used for language modeling. We have included filtered and deduplicated versions of complete Wikipedia data directly provided by the Wikipedia Foundation for more than 350 languages."),
        H4("Download and Extraction"),
        P("The Wikimedia dataset was downloaded from the official snapshot on Huggingface: ", A("https://huggingface.co/datasets/wikimedia/wikipedia/tree/main", href="https://huggingface.co/datasets/wikimedia/wikipedia/tree/main"), ". The", D_code("huggingface dataset.to_json", language="python"), " function was used to convert the original parqet format to the jsonl format."),
        H4("Filtering"),
        P("Manual inspection of the dataset demostrated high quality content. Only one filter was used to remove articles with few words. Based normal sentence constructs, the article was kept if it contained 10 or more words. Any article with fewer than 10 words was removed."),
        table_div_wikipedia,
        Details(
            Summary("Wikipedia Filtering Examples"),
            wiki_examples,
        ),
        ), 
    ),
    Section(
        Div(
        H3("ArXiv"),
        P("The ArXiv dataset is a vast collection of preprint research papers primarily in Mathematics, Computer Science, and Physics. Established in 1991, it offers high-quality text and mathematical knowledge, making it an invaluable resource for academic and scientific research. ArXiv papers are typically written in LaTeX, a popular typesetting system for these fields. We have extracted the information from latex and converted it into a text format."),
        H4("Download and Extraction"),
        P("All the data was downloaded in original latex format from Arxiv official S3 dump ", A("s3://arxic/src", href="s3://arxic/src"), ". We try to encode the downloaded data into utf-8 or guess encoding using chardet library. After that pandoc was used to extract information from the latex files and saved as markdown format",  D_code("pandoc -s {tex} -o out/{out_name}.md --wrap=none", language="python"), ". All markdowns were combined to create jsonl files."),
        H4("Filtering"),
        P("Multiple filters are used here after manually verifying output of all the filters as suggested by peS2o dataset (citation needed)"),
        Ol(
            Li("Language Filter: any language other than English are discarded"),
            Li("Minimum Word Count Filter: less than 500 words (not inclusive) are discarded"),
            Li("Unigram Log Probablity Filter: Documents were kept if they their average unigram log probability was higher than -20. To calculate the average log word probability, we use word frequencies extracted from the", A("1T Web-gram corpus", href= "https://catalog.ldc.upenn.edu/LDC2006T13"),". Specifically, we use the list available created by", A("Rachel Tatman", href="https://www.kaggle.com/datasets/rtatman/english-word-frequency"),"."),
            Li("Note: The Frequency Filter was calculated but not applied. The most frequent word in the paper consists of alpha characters only, and it appears in less than 7.5% of the document. Words are obtained by splitting the text on whitespace."),
        ),
        table_div_arx,
        Details(
            Summary("ArXiv Filtering Examples"),
            arx_examples,
        ),
        ),
    ),
    Section(
        Div(
        H3("S2ORC - NEED TO MAKE S2ORC ABSTRACT AND UPDATE THIS FILTERING SECTION"),
        P("The Semantic Scholar Open Research Corpus (S2ORC) is a comprehensive dataset designed for natural language processing (NLP) and text-mining research over scientific papers. It includes rich metadata, and abstract and full-text content for millions of academic papers across various disciplines. This dataset is further divided into two components, S2ORC abstract and S2ORC full text."),
        H4("Download and Extraction"),
        Ol(
            Li("This was downloaded directly in zip format using S2ORC api key and normal get request. code: response = urllib.request.urlopen(url)"),
            Li("There were two kind of datasets that was downloaded S2ORC and S2ORC abstract"),
        ),
        H4("Filtering - S2ORC"),
        P("1. Multiple filters are used here after manually verifying output of all the filters as suggested by peS2o dataset"),
        Ol(
            Li("title_abstract: must have title and abstract"),
            Li("The paper must be in English. To determine the language of each document, we use the pycld3 library. We run pycld3 on the first 2000 characters of each paragraph in the paper. The language of the paper is the most common language of the paragraphs."),
            Li("word_count: less than 500 words (not inclusive) are discarded"),
            Li("paragraph_count: The paper must have at least 5 paragraphs after removing paragraphs with less than -20 average log world probability"),
            Li("frequency: The most frequent word in the paper consists of alpha characters only, and it appears in less than 7.5% of the document. Words are obtained by splitting the text on whitespace."),
        ),
        H4("Filtering - S2ORC Abstract"),
        P("1. Multiple filters are used here after manually verifying output of all the filters as suggested by peS2o dataset. The frequency filter was not used as suggested by peS2o because it was removing good samples as inspected manually"),
        Ol(
            Li("title_abstract: must have title and abstract"),
            Li("language: abstract must be in English"),
            Li("word_count: less than 20 (not inclusive) are discarded"),
            Li("Unigram log probablity"),
            Li("frequency: The most frequent word in the paper consists of alpha characters only, and it appears in less than 7.5% of the document. Words are obtained by splitting the text on whitespace."),
        ),
        H4("Local Deduplication Process"),
        Ol(
            Li("Local dedup was done with all papers combined."),
        ),
        H4("Global Deduplication Process"),
        Ol(
            Li("This data was part of paper domain which are combined together and minhash was generated and deduped together with all the datasets after doing local dedup"),
        ),
        table_div_s2o,
        Details(
            Summary("FreeLaw Filtering Examples -- need to update"),
            freelaw_examples,
        ),
        ),
    ),
    Section(
        Div(
        H3("PubMed - need to update with abstract vs central"),
        P(""),
        H4("Download and Extraction"),
        Ol(
            Li("First all the urls of PMC and PMA files are parsed and stored as text file from FTP server https://ftp.ncbi.nlm.nih.gov/pub/pmc/oa_package/"),
            Li("All the urls are downloaded and the downloaded data is in xml.tar format"),
            Li("For pubmed central First tar files are opened using tarfile library and then converted to markdown format using pandoc: pandoc -f jats {nxml} -o {pmcid}.md --wrap=none"),
            Li("All the markdown files are combined to create jsonl files. In jsonl files, 1 line correspond to 1 markdown file."),
            Li("For pubmed abstract, the XML files are in very simple format and beautiful soup is directly used to extract the abstract, title and pmid and stored in jsonl format"),
        ),
        H4("Filtering"),
        P("1. Multiple filters are used here after manually verifying output of all the filters as suggested by peS2o dataset."),
        Ol(
            Li("min_word: less than 100 words (not inclusive) are discarded, less than 20 words for pubmed abstract"),
            Li("Language: any language other than English are discarded"),
            Li("Frequency: The most frequent word in the paper consists of alpha characters only, and it appears in less than 7.5% of the document. Words are obtained by splitting the text on whitespace. This filter is not used for pubmed abstract"),
            Li("Unigram log probablity: Must have higher than -20 average unigram log probability. To calculate the average log word probability, we use word frequencies extracted from the 1T Web Ngram corpus; specifically, we use the list available created by Rachel Tatman. A copy is hosted here."),
            Li("need to add the hyperlinks for the section above"),
        ),
        H4("Local Deduplication Process"),
        Ol(
            Li("Local dedup was done with all papers combined."),
        ),
        H4("Global Deduplication Process"),
        Ol(
            Li("This data was part of paper domain which are combined together and minhash was generated and deduped together with all the datasets after doing local dedup."),
        ),
        table_div_med,
        Details(
            Summary("PubMed Filtering Examples"),
            pubmed_examples,
        ),
        ),
    ),
    Section(
        Div(
        H3("Phil Papers"),
        P("Papers from the PhilPapers database, a comprehensive index and bibliography of philosophy research maintained by the Center for Digital Philosophy at the University of Western Ontario."),
        H4("Download and Extraction"),
        P("Original PDF files download from", A("https://philarchive.org/oai.pl", href="https://philarchive.org/oai.pl"), ". All available PDF's were downloaded. Each PDF was converted to text using java", D_code("-jar ../philpapers_resources/src/pdfbox-app-2.0.21.jar ExtractText {f0} {FOUT.name}", language="java"), ". After converting to text formatting, a language was detected and added using the langdetect (citation needed) library."),
        H4("Filtering"),
        Ol(
            Li("Many filters were used to clean the phil papers like double whitespaces, new lines etc. All filter details are here: https://github.com/thoppe/The-Pile-PhilPapers/blob/master/pdf_filter.py"),
        ),
        table_div_phil,
        Details(
            Summary("Phil Papers Filtering Examples"),
            phil_examples,
        ),
        ),
    ),
    Section(
        Div(
        H3("Europarl"),
        P("A collection of multilingual parallel corpora of parliamentary debates from the European Parliament. This is a high-quality legacy dataset earlier used for translation tasks."),
        H4("Download and Extraction"),
        P("Original dataset was downloaded from", A("http://www.statmt.org/europarl/v7/europarl.tgz", href="http://www.statmt.org/europarl/v7/europarl.tgz"),". The files were converted to jsonl lines for filtering."),
        H4("Filtering"),
        P("EuroParl was initially filtered during the download process. Documents with fewer than 200 characters were removed. The documents also contained 'TAGS' which were removed."),
        table_div_up,
        Details(
            Summary("EuroParl Filtering Examples"),
            eu_examples,
        ),
    ),
    ),
    Section(
        Div(
        H3("HackerNews"),
        P("High-quality dialog-based dataset where user comments on the links as the head post aggregated by Y Combinator."),
        H4("Download and Extraction"),
        P("The dataset was downloaded from the HackerNews repo here:", A("https://hacker-news.firebaseio.com/v0/item/", href="https://hacker-news.firebaseio.com/v0/item/"), ". The dataset was parsed using the Story ID. In this dataset each post is a story, and each reply is considered subsequent story. Story IDs were considered between ID 1 to 37500000.  The URL for all Story IDs was pinged. If that ID returned an error, the ID was removed. Each request was given a 2 second wait to account for network time."),
        P("The HackerNews dataset contains a vast amount of stories and is known for lively discussions. Due to the number of replies a story may contain, only longest threads included stories from the 3rd level onwards. All stories included the title (1st level) and all direct replies (2nd level). Replies to the replies (3rd level) are only included for X STORIES."),
        H4("Filtering"),
        Ol(
            Li("Language Filter: English"),
            Li("Minimum Word Count Filter: 10"),
            Li("Unigram Log Probability"),
        ),
        table_div_hn,
        ),
    ),
    Section(
        Div(
        H3("USPTO"),
        P("Patent documents from the United States Patent and Trademark Office."),
        H4("Download and Extraction"),
        P("Data was downloaded and extracted using tags from", A("https://bulkdata.uspto.gov/data/patent/grant/redbook/fulltext/", href="https://bulkdata.uspto.gov/data/patent/grant/redbook/fulltext/"),". There were three different formats that needed three different functions to download and extract the data based on year: I(Pre_2002), 2002_to_2004, and post_2004."),
        H4("Filtering"),
        Ol(
            Li("Language Filter: English"),
            Li("Minimum Word Count Filter: 50"),
            Li("Unigram Log Probability"),
        ),
        table_div_uspto,
        ),
    ),
    Section(
        Div(
        H3("FreeLaw"),
        P("Legal documents and court cases from various jurisdictions provided by US-registered non-profit firm Free Law Project. We have included data from CourtListener which included millions of legal opinions from federal and state courts."),
        H4("Download and Extraction"),
        #P("The dataset was downloaded from:" A("https://storage.courtlistener.com/bulk-data/", href="https://storage.courtlistener.com/bulk-data/"), )#". There are 19 CSV files which contain overlapping content. CSV files can contain content in multiple columns requiring a holistic extraction approach. Text was extracted from the following using html2text function. The block below shows how each text type was extracted."), 
        D_code("""
        ("html", html2text),
        ("html_lawbox", html2text),
        ("html_columbia", html2text),
        ("html_anon_2020", html2text),
        ("html_with_citations", html2text),
        ("xml_harvard", html2text),
        plain_text
        """, language ="SQL"),
        P("All content was downloaded leading to high number of documents filtered during local deduplication. Following The Pile, priorty was given to plain_text first, followed by the columns in the table in reverse order."),
        H4("Filtering"),
        Ol(
            Li("Language Filter: English"),
            Li("Minimum Word Count Filter: 50"),
            Li("Unigram Log Probability"),
        ),
        H4("Local Deduplication Process"),
        Ol(
            Li("Local dedup was done within freelaw itself which removed 90%+ duplicates"),
        ),
        table_div_freelaw,
        Details(
            Summary("FreeLaw Filtering Examples"),
            freelaw_examples,
        ),
            
        ),
    ),
    Section(
        Div(
        H3("StackExchange"),
        P("A network of question-and-answer websites on various subjects, including programming, science, mathematics, and more. This is one of the largest publicly available repositories for question-answer pairs. We have included comments also to include an overall discussion on each post."),
        H4("Download and Extraction"),
        P("The archive dataset was used to download all data from StackExchange and StackExchange's sub URLs including: ", A("math.stackexchange.com", href="math.stackexchange.com"),". Raw data was extracted an XML format and only two files Posts.xml and Comments.xml were considered. To match the StackExchange hierarchy, each file was parsed using post_id to connect questions to answers and then to comments."),
        P("""
        1. Questions:
  2. Comment1:
  3. Comment2:
  4. Answer1:
  5. Comment1:
  6. Comment2:
  7. Answer2:
  8. Comment1:
  9. Comment2:
        """),
        H4("Filtering"),
        Ol(
            Li("Minimum Word Count Filter: 10"),
        ),
        table_div_se,
        Details(
            Summary("StackExchange Filtering Examples"),
            se_examples,
        ),
        ),
    ),
    Section(
        Div(
        H3("Ubuntu IRC"),
        P("Chat logs from the Ubuntu Internet Relay Chat (IRC) channels on the Freenode IRC chat server. This data is also another form of dialog dataset on niche topics."),
        H4("Download and Extraction"),
        P("The dataset was downloaded from:", A("https://irclogs.ubuntu.com/{date.year}/{date.month:02d}/{date.day:02d}/", href="https://irclogs.ubuntu.com/{date.year}/{date.month:02d}/{date.day:02d}/"), " based on the year."),
        P("During extraction, the logs were cleaned using following functions:"),
        D_code("""
        def exclude_system(x):
            return '\n'.join(line for line in x.split('\n') if not line.startswith('==='))

        def exclude_select_system(x):
            return '\n'.join(line for line in x.split('\n') if not (line.startswith('===') 
                and any(term in line for term in 
                ['has joined #', 'has left #', 'Topic for #', "Topic (#", "is now known as"]) ))
        
        def clean(x):
            return '\n'.join('* ' + line[4:] if line.startswith('===') else line[8:] for line in x.split('\n'))
        """, block="block", language="python" ),
        H4("Filtering"),
        Ol(
            Li("Language Filter: English"),
            Li("Minimum Word Count Filter: 10"),
            Li("Unigram Log Probability"),
        ),
        table_div_uirc,   
        ),
    ),
    Section(
       Div(
        H3("DM Math"),
        P("DeepMind Math dataset with generated questions from various topics like algebra, calculus, geometry, etc. Maths data is included to improve model reasoning abilities in the downstream tasks."),
        H4("Download and Extraction"),
        P("The dataset was downloaded rirectly downloaded from the Huggingface repo:", A("https://huggingface.co/datasets/deepmind/math_dataset",href="https://huggingface.co/datasets/deepmind/math_dataset"), ". The data was converted to the jsonl format where lines is represented as:"),
        D_code(""" 
        Question: TEXT
        Answer: TEXT""", block="block", language="python"),
        H4("Filtering"),
        Ol(
            Li("No filtering was applied to DM Math"),
        ),
        H4("Local Deduplication Process"),
        Ol(
            Li("None"),
        ),
        table_div_dmm,
        Details(
            Summary("DM Math Filtering Examples"),
            dmm_examples,
        ),
       ),
    ),
    Section(
        Div(
        H3("PG-19"),
        P("A collection of books from Project Gutenberg, a digital library of public domain works. This contains all the books that were published before 1919."),
        H4("Download and Extraction"),
        Ol(
            Li("The dataset was downloaded directly from Huggingface:", A("https://huggingface.co/datasets/deepmind/pg19", href="https://huggingface.co/datasets/deepmind/pg19"), "."),
        ),
        H4("Filtering"),
        Ol(
            Li("Language Filter: ???"),
            Li("Minimum Word Count Filter: 20"),
            Li("Unigram Log Probability"),
        ),
        table_div_pg19,
        Details(
            Summary("PG-19 Filtering Examples"),
            pg19_examples,
        ),
        ),
    ),
)






local_dedup_text = P("Each curated data source has been prepared using its specific rules and has been locally deduped using min-hash near deduplication. Details about the dataset are shown below in the table:")








data_pipeline_table = pd.DataFrame(
        {
            "Data Source": [
                "Papers",
                "Wikipedia",
                "StackExchange",
                "Europarl",
                "Ubuntu IRC",
                "HackerNews",
                "PG-19",
                "USPTO",
                "Freelaw",
                "DM Math",
            ],
            "Percent Filtered": [
                "15%",
                "21%",
                "<0.1%",
                "1%",
                "0.4%",
                "60%",
                "0.8%",
                "22.5%",
                "94%",
                "0",
            ],
            "Unique Document Percentage": [
                "75.99%",
                "91.91%",
                "98.02%",
                "98.87%",
                "100%",
                "99.91%",
                "31.81%",
                "99.94%",
                "91.01%",
                "0",
            ],
            "2 - 5 Duplicates": [
                "19.4%",
                "4.7%",
                "1.27%",
                "0.94%",
                "0",
                "0.05%",
                "20.03%",
                "0.05%",
                "6,87%",
                "0",
            ],
            "6 - 10 Duplicates": [
                "2.89%",
                "1.58%",
                "0.35%",
                "0.09%",
                "0",
                "0.02%",
                "24.27%",
                "0.01%",
                "1.07%",
                "0",
            ],
            "11 - 100 Duplicates": [
                "1.17%",
                "1.76%",
                "0.35%",
                "0.1",
                "0",
                "0.02%",
                "22.26%",
                "0.01%",
                "1.05%",
                "0",
            ],
            "101 - 1000 Duplicates": [
                "0.01%",
                "0.05%",
                "0.01%",
                "0",
                "0",
                "<0.01%",
                "1.58%",
                "<0.01%",
                "0.01%",
                "0",
            ],
            "1001+ Duplicates": [
                "<0.01%",
                "<0.01%",
                "<0.01%",
                "0",
                "0",
                "<0.01%",
                "0.06%",
                "0",
                "0",
                "0",
            ],
        }
    )

table_html_data_pipe = data_pipeline_table.to_html(index=False, border=0)
table_div_data_pipe = Div(NotStr(table_html_data_pipe), style="margin: 40px;")




def update(target: str, request):
    params = request.query_params
    if data_source := params.get(f"data_source_{target}"):
        return get_data(
            data_source, params.get(f"doc_id_{target}", 3), target)
    if doc_id := params.get(f"doc_id_{target}"):
        return get_data(
            params.get(f"data_source_{target}"), doc_id, target)

# Data for the stacked bar chart
data = {
    'Filter': ['Downloaded Lines', 'Language Filter', 'Min Word Count', 'Unigram Log Probability'],
    'Wikipedia': [61614907, 61614907, 60468491, 60468491],
    'Freelaw': [75971288, 73690766, 68171834, 68123174],
    'DM Maths': [112559888, 112559888, 112559888, 112559888],
    'USPTO': [6880276, 6878964, 6749922, 6749389],
    'PG19': [28752, 28683, 28682, 28632],
    'Hackernews': [2064931, 2010802, 2010488, 2003636],
    'Ubuntu IRC': [37966, 23501, 23468, 23205],
    'Europarl': [69814, 69814, 69814, 69814],
    'StackExchange': [23246548, 23246548, 23246352, 23246352],
    'Arxiv': [1911867, 1869441, 1763840, 1762661],
    'S2ORC': [12963563, 12963563, 12963563, 12963563],
    'S2ORC Abstract': [102324176, 83867601, 82889293, 82777912],
    'Pubmed Central': [5230932, 4830486, 4768310, 4767474],
    'Pubmed Abstract': [25787474, 25784374, 25747955, 25746724],
    'Phil Papers': [49389, 39175, 39175, 39128]
}

# Creating a dataframe
df = pd.DataFrame(data)

# Creating the stacked bar chart
fig = go.Figure()

# Add trace for each dataset
for dataset in df.columns[1:]:
    fig.add_trace(go.Bar(
        name=dataset,
        x=df['Filter'],
        y=df[dataset]
    ))

# Update the layout
fig.update_layout(
    barmode='stack',
    title='Document Reduction by Filter for Each Dataset',
    xaxis_title='Filter',
    yaxis_title='Number of Lines',
    legend_title='Dataset',
    height=600,
    width=1000
)

# Show the plot
diff2_stacked_bar = fig



def curated(request):

    # Partial Updates
    params = dict(request.query_params)
    if target := params.get("target"):
        if data_source := params.get(f"data_source_{target}"):
            return get_data(
                data_source, params.get(f"doc_id_{target}", 3), params.get("target")
            )
        if doc_id := params.get(f"doc_id_{target}"):
            return get_data(
                params.get(f"data_source_{target}"), doc_id, params.get("target")
            )
    
    data_preparation_steps = pd.DataFrame(
        {
            "Method": [
                "HTTP/FTP dumps",
                "Web crawling",
                "Archive snapshot",
                "Generated",
                "Curated",
            ],
            "Description": [
                "Acquiring data from HTTP/FTP dumps",
                "Crawling websites to extract data",
                "Working with archive dumps",
                "Generating synthetic data",
                "High quality curated data",
            ],
            "Source": [
                "Freelaw | Wikipedia | PhilPapers | Arxiv | S2ORC | Pubmeds",
                "USPTO | Hackernews | Ubuntu IRC",
                "StackExchange",
                "DM Maths",
                "PG19 | Europarl",
            ],
        }
    )

    table_html = data_preparation_steps.to_html(index=False, border=0)
    table_div = Div(NotStr(table_html), style="margin: 40px;")

    text = P("""This initial stage serves as the foundation for the entire
    process. Here, we focus on acquiring and extracting the raw data, which can
    come from various sources such as crawling websites, using HTTP/FTP dumps,
    or working with archive dumps.  For instance, to download and prepare a
    dataset, we can specific downloaders based on the data source. Each dataset
    might have its own downloader script which can be updated in real time to
    handle changes in the data source.  Here is a general outline of the data
    preparation process: It is worth noting that some pipelines might require
    invoking additional functions or scripts to handle specific data sources or
    formats.  These helper scripts can be located within specific directories
    or modules dedicated to the dataset.""")

 


    data_preprocessing_div = Div(
        H2("Data Preprocessing"),
        P("Data preprocessing is a crucial step in the data science pipeline. It involves cleaning and transforming raw data into a format that is suitable for analysis. This process includes handling missing values, normalizing data, encoding categorical variables, and more."),
        H3("Language Filter"),
        P("The Language Filter removes documents in unwanted languages. This step improves data quality by removing irrelevant documents."),
        H3("Minimum Word Count Filter"),
        P("The Minimum Word Count Filter sets a threshold for required words within a document. This step filters out low-quality or incomplete documents. However, this step may remove documents that contain valuable information so a proper analysis is important for each datasource."),
        H3("Unigram Log Probability"),
        P("The Unigram Log Probability Filter calculates the log probability of each unigram to measure the significance of individual words. This step quantifies the importance of individual words but maay not capture the semantic meaning of words."),
        H2("Data Processing for S2ORC"),
        P("The formating of the S2ORC dataset required special filters to be applied. These filters were not applied to the other data sources."),
        H3("Title Abstract Filter"),
        P("The Title Abstract Filter extracts information from the title and abstract. This step provides additional information for analysis but may introduce bias in the analysis."),
        H3("Majority Language Filter"),
        P("The Majority Language Filter identifies the majority language in the dataset. This step displays the distribution of languages in the dataset to enable language-specific analysis and insights."),
        H3("Paragraph Count Filter"),
        P("The Paragraph Count Filter counts the number of paragraphs in each document. This step helps to analyze the structure and length of documents which can be a useful hueristic for document complexity."),
        H3("Frequency Filter"),
        P("The Frequency Filter calculates the frequency of each word in the dataset. This step serves to identify important words and topics in the dataset but may be sensitive to noise and outliers."),
        )
    
    return Div(
            overview,    
            H2("Curated Sources: Overview"),
            overview_text,
            copyright_disclaimer,
            plotly2fasthtml(treemap_chart),
            data_preprocessing_div,
            H2("Curated Sources Processing"),
            plotly2fasthtml(diff2_stacked_bar),
            P("The figure above provides a global view of the document filtering results. ~8% of documents were removed during these three steps."),
            filtering_process,
            #data_preparation_div,
            #H2("Local Deduplication"), are these numbers even right?
            #local_dedup_text,
            #table_div_data_pipe,
            id="inner-text",
)