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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
WEBVTT

00:00:00.399 --> 00:00:04.120
so this time I'm going to be talking

00:00:02.080 --> 00:00:05.799
about language modeling uh obviously

00:00:04.120 --> 00:00:07.240
language modeling is a big topic and I'm

00:00:05.799 --> 00:00:09.880
not going to be able to cover it all in

00:00:07.240 --> 00:00:11.320
one class but this is kind of the basics

00:00:09.880 --> 00:00:13.080
of uh what does it mean to build a

00:00:11.320 --> 00:00:15.320
language model what is a language model

00:00:13.080 --> 00:00:18.439
how do we evaluate language models and

00:00:15.320 --> 00:00:19.920
other stuff like that and around the end

00:00:18.439 --> 00:00:21.320
I'm going to talk a little bit about

00:00:19.920 --> 00:00:23.039
efficiently implementing things in

00:00:21.320 --> 00:00:25.080
neural networks it's not directly

00:00:23.039 --> 00:00:27.760
related to language models but it's very

00:00:25.080 --> 00:00:31.200
important to know how to do uh to solve

00:00:27.760 --> 00:00:34.200
your assignments so I'll cover both

00:00:31.200 --> 00:00:34.200
is

00:00:34.239 --> 00:00:38.480
cool okay so the first thing I'd like to

00:00:36.760 --> 00:00:41.239
talk about is generative versus

00:00:38.480 --> 00:00:43.000
discriminative models and the reason why

00:00:41.239 --> 00:00:45.280
is up until now we've been talking about

00:00:43.000 --> 00:00:47.559
discriminative models and these are

00:00:45.280 --> 00:00:49.640
models uh that are mainly designed to

00:00:47.559 --> 00:00:53.800
calculate the probability of a latent

00:00:49.640 --> 00:00:56.039
trait uh given the data and so this is

00:00:53.800 --> 00:00:58.800
uh P of Y given X where Y is the lat and

00:00:56.039 --> 00:01:00.800
trait we want to calculate and X is uh

00:00:58.800 --> 00:01:04.760
the input data that we're calculating it

00:01:00.800 --> 00:01:07.799
over so just review from last class what

00:01:04.760 --> 00:01:10.240
was X from last class from the example

00:01:07.799 --> 00:01:10.240
in L

00:01:11.360 --> 00:01:15.880
class

00:01:13.040 --> 00:01:18.280
anybody yeah some text yeah and then

00:01:15.880 --> 00:01:18.280
what was

00:01:20.400 --> 00:01:26.119
why it shouldn't be too

00:01:23.799 --> 00:01:27.920
hard yeah it was a category or a

00:01:26.119 --> 00:01:31.680
sentiment label precisely in the

00:01:27.920 --> 00:01:33.399
sentiment analysis tasks so so um a

00:01:31.680 --> 00:01:35.560
generative model on the other hand is a

00:01:33.399 --> 00:01:38.840
model that calculates the probability of

00:01:35.560 --> 00:01:40.880
data itself and is not specifically

00:01:38.840 --> 00:01:43.439
conditional and there's a couple of

00:01:40.880 --> 00:01:45.439
varieties um this isn't like super

00:01:43.439 --> 00:01:48.280
standard terminology I just uh wrote it

00:01:45.439 --> 00:01:51.520
myself but here we have a standalone

00:01:48.280 --> 00:01:54.360
probability of P of X and we can also

00:01:51.520 --> 00:01:58.000
calculate the joint probability P of X

00:01:54.360 --> 00:01:58.000
and Y

00:01:58.159 --> 00:02:02.880
so probabilistic language models

00:02:01.079 --> 00:02:06.640
basically what they do is they calculate

00:02:02.880 --> 00:02:08.560
this uh probability usually uh we think

00:02:06.640 --> 00:02:10.360
of it as a standalone probability of P

00:02:08.560 --> 00:02:11.800
of X where X is something like a

00:02:10.360 --> 00:02:15.160
sentence or a

00:02:11.800 --> 00:02:16.920
document and it's a generative model

00:02:15.160 --> 00:02:19.640
that calculates the probability of

00:02:16.920 --> 00:02:22.360
language recently the definition of

00:02:19.640 --> 00:02:23.959
language model has expanded a little bit

00:02:22.360 --> 00:02:26.160
so now

00:02:23.959 --> 00:02:28.640
um people also call things that

00:02:26.160 --> 00:02:31.080
calculate the probability of text and

00:02:28.640 --> 00:02:35.200
images as like multimodal language

00:02:31.080 --> 00:02:38.160
models or uh what are some of the other

00:02:35.200 --> 00:02:40.480
ones yeah I think that's the main the

00:02:38.160 --> 00:02:42.840
main exception to this rule usually

00:02:40.480 --> 00:02:45.080
usually it's calculating either of text

00:02:42.840 --> 00:02:47.680
or over text in some multimodal data but

00:02:45.080 --> 00:02:47.680
for now we're going to

00:02:48.800 --> 00:02:54.200
consider

00:02:50.319 --> 00:02:56.440
um then there's kind of two fundamental

00:02:54.200 --> 00:02:58.159
operations that we perform with LMS

00:02:56.440 --> 00:03:00.519
almost everything else we do with LMS

00:02:58.159 --> 00:03:03.640
can be considered like one of these two

00:03:00.519 --> 00:03:05.319
types of things the first thing is calc

00:03:03.640 --> 00:03:06.440
scoring sentences or calculating the

00:03:05.319 --> 00:03:09.599
probability of

00:03:06.440 --> 00:03:12.280
sentences and this

00:03:09.599 --> 00:03:14.720
is uh for example if we calculate the

00:03:12.280 --> 00:03:16.400
probability of Jane went to the store uh

00:03:14.720 --> 00:03:19.000
this would have a high probability

00:03:16.400 --> 00:03:20.879
ideally um and if we have this kind of

00:03:19.000 --> 00:03:23.400
word salid like this this would be given

00:03:20.879 --> 00:03:26.080
a low probability uh according to a

00:03:23.400 --> 00:03:28.000
English language model if we had a

00:03:26.080 --> 00:03:30.000
Chinese language model ideally it would

00:03:28.000 --> 00:03:31.319
also probably give low probability first

00:03:30.000 --> 00:03:32.879
sentence too because it's a language

00:03:31.319 --> 00:03:35.000
model of natural Chinese and not of

00:03:32.879 --> 00:03:36.200
natural English so there's also

00:03:35.000 --> 00:03:37.360
different types of language models

00:03:36.200 --> 00:03:38.400
depending on the type of data you play

00:03:37.360 --> 00:03:41.360
in

00:03:38.400 --> 00:03:43.599
the another thing I can do is generate

00:03:41.360 --> 00:03:45.239
sentences and we'll talk more about the

00:03:43.599 --> 00:03:48.280
different methods for generating

00:03:45.239 --> 00:03:50.319
sentences but typically they fall into

00:03:48.280 --> 00:03:51.799
one of two categories one is sampling

00:03:50.319 --> 00:03:53.200
like this where you try to sample a

00:03:51.799 --> 00:03:55.480
sentence from the probability

00:03:53.200 --> 00:03:57.280
distribution of the language model

00:03:55.480 --> 00:03:58.360
possibly with some modifications to the

00:03:57.280 --> 00:04:00.760
probability

00:03:58.360 --> 00:04:03.079
distribution um the other thing which I

00:04:00.760 --> 00:04:04.760
didn't write on the slide is uh finding

00:04:03.079 --> 00:04:07.439
the highest scoring sentence according

00:04:04.760 --> 00:04:09.760
to the language model um and we do both

00:04:07.439 --> 00:04:09.760
of those

00:04:10.560 --> 00:04:17.600
S so more concretely how can we apply

00:04:15.199 --> 00:04:21.199
these these can be applied to answer

00:04:17.600 --> 00:04:23.840
questions so for example um if we have a

00:04:21.199 --> 00:04:27.240
multiple choice question we can score

00:04:23.840 --> 00:04:30.639
possible multiple choice answers and uh

00:04:27.240 --> 00:04:32.880
the way we do this is we calculate

00:04:30.639 --> 00:04:35.440
we first

00:04:32.880 --> 00:04:38.440
take uh like we have

00:04:35.440 --> 00:04:38.440
like

00:04:38.560 --> 00:04:43.919
um

00:04:40.960 --> 00:04:46.919
where is

00:04:43.919 --> 00:04:46.919
CMU

00:04:47.560 --> 00:04:51.600
located um

00:04:51.960 --> 00:04:59.560
that's and actually maybe promete this

00:04:54.560 --> 00:05:01.360
all again to an a here and then we say X

00:04:59.560 --> 00:05:05.800
X1 is equal to

00:05:01.360 --> 00:05:07.520
this and then we have X2 which is

00:05:05.800 --> 00:05:09.720
Q

00:05:07.520 --> 00:05:12.479
where is

00:05:09.720 --> 00:05:14.120
CMU

00:05:12.479 --> 00:05:18.080
located

00:05:14.120 --> 00:05:19.720
a um what's something

00:05:18.080 --> 00:05:21.960
plausible

00:05:19.720 --> 00:05:24.560
uh what was

00:05:21.960 --> 00:05:26.319
it okay now now you're going to make it

00:05:24.560 --> 00:05:27.960
tricky and make me talk about when we

00:05:26.319 --> 00:05:29.960
have multiple right answers and how we

00:05:27.960 --> 00:05:31.759
evaluate and stuff let let's ignore that

00:05:29.960 --> 00:05:35.080
for now it's say New

00:05:31.759 --> 00:05:37.199
York it's not located in New York is

00:05:35.080 --> 00:05:40.560
it

00:05:37.199 --> 00:05:40.560
okay let's say

00:05:40.960 --> 00:05:45.199
Birmingham hopefully there's no CMU

00:05:43.199 --> 00:05:47.120
affiliate in Birmingham I think we're

00:05:45.199 --> 00:05:49.000
we're pretty so um and then you would

00:05:47.120 --> 00:05:53.880
just calculate the probability of X1 and

00:05:49.000 --> 00:05:56.440
the probability of X2 X3 X4 Etc and um

00:05:53.880 --> 00:06:01.479
then pick the highest saring one and

00:05:56.440 --> 00:06:01.479
actually um there's a famous

00:06:03.199 --> 00:06:07.440
there's a famous uh leaderboard for

00:06:05.840 --> 00:06:08.759
language models that probably a lot of

00:06:07.440 --> 00:06:09.759
people know about it's called the open

00:06:08.759 --> 00:06:13.120
llm

00:06:09.759 --> 00:06:15.639
leaderboard and a lot of these tasks

00:06:13.120 --> 00:06:17.319
here basically correspond to doing

00:06:15.639 --> 00:06:21.000
something like that like hel swag is

00:06:17.319 --> 00:06:22.599
kind of a multiple choice uh is a

00:06:21.000 --> 00:06:24.160
multiple choice question answering thing

00:06:22.599 --> 00:06:27.880
about common sense where they calculate

00:06:24.160 --> 00:06:30.280
it by scoring uh scoring the

00:06:27.880 --> 00:06:31.880
outputs so that's a very common way to

00:06:30.280 --> 00:06:35.000
use language

00:06:31.880 --> 00:06:36.960
models um another thing is generating a

00:06:35.000 --> 00:06:40.080
continuation of a question prompt so

00:06:36.960 --> 00:06:42.639
basically this is when you uh

00:06:40.080 --> 00:06:44.759
sample and so what you would do is you

00:06:42.639 --> 00:06:48.440
would prompt the

00:06:44.759 --> 00:06:50.560
model with this uh X here and then you

00:06:48.440 --> 00:06:53.800
would ask it to generate either the most

00:06:50.560 --> 00:06:56.400
likely uh completion or generate um

00:06:53.800 --> 00:06:58.960
sample multiple completions to get the

00:06:56.400 --> 00:07:00.720
answer so this is very common uh people

00:06:58.960 --> 00:07:03.759
are very familiar with this there's lots

00:07:00.720 --> 00:07:07.160
of other uh things you can do though so

00:07:03.759 --> 00:07:09.400
um you can classify text and there's a

00:07:07.160 --> 00:07:12.720
couple ways you can do this uh one way

00:07:09.400 --> 00:07:15.960
you can do this is um like let's say we

00:07:12.720 --> 00:07:15.960
have a sentiment sentence

00:07:16.160 --> 00:07:21.520
here

00:07:17.759 --> 00:07:25.440
um you can say uh

00:07:21.520 --> 00:07:30.919
this is

00:07:25.440 --> 00:07:33.919
gr and then you can say um

00:07:30.919 --> 00:07:37.680
star

00:07:33.919 --> 00:07:38.879
rating five or something like that and

00:07:37.680 --> 00:07:41.400
then you could also have star rating

00:07:38.879 --> 00:07:43.680
four star rating three star rating two

00:07:41.400 --> 00:07:45.080
star rating one and calculate the

00:07:43.680 --> 00:07:46.639
probability of all of these and find

00:07:45.080 --> 00:07:50.360
which one has the highest probability so

00:07:46.639 --> 00:07:51.800
this is a a common way you can do things

00:07:50.360 --> 00:07:54.319
another thing you can do which is kind

00:07:51.800 --> 00:07:55.240
of interesting and um there are papers

00:07:54.319 --> 00:07:58.319
on this but they're kind of

00:07:55.240 --> 00:08:00.800
underexplored is you can do like star

00:07:58.319 --> 00:08:04.800
rating

00:08:00.800 --> 00:08:04.800
five and then

00:08:04.879 --> 00:08:13.280
generate generate the output um and so

00:08:10.319 --> 00:08:15.039
that basically says Okay I I want a

00:08:13.280 --> 00:08:16.680
positive sentence now I'm going to score

00:08:15.039 --> 00:08:19.120
the actual review and see whether that

00:08:16.680 --> 00:08:22.319
matches my like conception of a positive

00:08:19.120 --> 00:08:24.080
sentence and there's a few uh papers

00:08:22.319 --> 00:08:25.680
that do

00:08:24.080 --> 00:08:28.240
this

00:08:25.680 --> 00:08:31.240
um let

00:08:28.240 --> 00:08:31.240
me

00:08:34.640 --> 00:08:38.760
this is a kind of older one and then

00:08:36.240 --> 00:08:42.080
there's another more recent one by Sean

00:08:38.760 --> 00:08:43.839
Min I believe um uh but they demonstrate

00:08:42.080 --> 00:08:45.480
how you can do both generative and

00:08:43.839 --> 00:08:47.600
discriminative classification in this

00:08:45.480 --> 00:08:51.760
way so that's another thing that you can

00:08:47.600 --> 00:08:51.760
do uh with language

00:08:53.279 --> 00:08:56.839
models and then the other thing you can

00:08:55.200 --> 00:08:59.000
do is you can generate the label given a

00:08:56.839 --> 00:09:00.680
classification proc so you you say this

00:08:59.000 --> 00:09:03.079
is is great star rating and then

00:09:00.680 --> 00:09:05.720
generate five

00:09:03.079 --> 00:09:09.320
whatever finally um you can do things

00:09:05.720 --> 00:09:10.920
like correct a grammar so uh for example

00:09:09.320 --> 00:09:12.560
if you score the probability of each

00:09:10.920 --> 00:09:14.839
word and you find words that are really

00:09:12.560 --> 00:09:17.760
low probability then you can uh replace

00:09:14.839 --> 00:09:20.160
them with higher probability words um or

00:09:17.760 --> 00:09:21.720
you could ask a model please paraphrase

00:09:20.160 --> 00:09:24.000
this output and it will paraphrase it

00:09:21.720 --> 00:09:27.640
into something that gives you uh you

00:09:24.000 --> 00:09:30.720
know that has better gra so basically

00:09:27.640 --> 00:09:33.079
like as I said language models are very

00:09:30.720 --> 00:09:34.600
diverse um and they can do a ton of

00:09:33.079 --> 00:09:35.680
different things but most of them boil

00:09:34.600 --> 00:09:38.440
down to doing one of these two

00:09:35.680 --> 00:09:42.079
operations scoring or

00:09:38.440 --> 00:09:42.079
generating any questions

00:09:42.480 --> 00:09:47.600
s

00:09:44.640 --> 00:09:50.000
okay so next I I want to talk about a

00:09:47.600 --> 00:09:52.279
specific type of language models uh Auto

00:09:50.000 --> 00:09:54.240
regressive language models and auto

00:09:52.279 --> 00:09:56.720
regressive language models are language

00:09:54.240 --> 00:10:00.240
models that specifically calculate this

00:09:56.720 --> 00:10:02.320
probability um in a fashion where you

00:10:00.240 --> 00:10:03.680
calculate the probability of one token

00:10:02.320 --> 00:10:05.519
and then you calculate the probability

00:10:03.680 --> 00:10:07.680
of the next token given the previous

00:10:05.519 --> 00:10:10.519
token the probability of the third token

00:10:07.680 --> 00:10:13.760
G given the previous two tokens almost

00:10:10.519 --> 00:10:18.600
always this happens left to right um or

00:10:13.760 --> 00:10:20.519
start to finish um and so this is the

00:10:18.600 --> 00:10:25.000
next token here this is a context where

00:10:20.519 --> 00:10:28.440
usually um the context is the previous

00:10:25.000 --> 00:10:29.640
tokens Can anyone think of a time when

00:10:28.440 --> 00:10:32.440
you might want to do

00:10:29.640 --> 00:10:37.839
right to left instead of left to

00:10:32.440 --> 00:10:40.399
right yeah language that's from right to

00:10:37.839 --> 00:10:41.680
yeah that's actually exactly what I what

00:10:40.399 --> 00:10:43.079
I was looking for so if you have a

00:10:41.680 --> 00:10:46.839
language that's written from right to

00:10:43.079 --> 00:10:49.320
left actually uh things like uh Arabic

00:10:46.839 --> 00:10:51.360
and Hebrew are written right to left so

00:10:49.320 --> 00:10:53.720
um both of those are

00:10:51.360 --> 00:10:56.360
chronologically like earlier to later

00:10:53.720 --> 00:10:59.399
because you know if if you're thinking

00:10:56.360 --> 00:11:01.079
about how people speak um the the first

00:10:59.399 --> 00:11:02.440
word that an English speaker speaks is

00:11:01.079 --> 00:11:04.000
on the left just because that's the way

00:11:02.440 --> 00:11:06.079
you write it but the first word that an

00:11:04.000 --> 00:11:09.639
Arabic speaker speaks is on the the

00:11:06.079 --> 00:11:12.360
right because chronologically that's uh

00:11:09.639 --> 00:11:13.519
that's how it works um there's other

00:11:12.360 --> 00:11:16.320
reasons why you might want to do right

00:11:13.519 --> 00:11:17.839
to left but uh it's not really that left

00:11:16.320 --> 00:11:21.720
to right is important it's that like

00:11:17.839 --> 00:11:24.440
start to finish is important in spoken

00:11:21.720 --> 00:11:27.880
language so um one thing I should

00:11:24.440 --> 00:11:30.240
mention here is that this is just a rule

00:11:27.880 --> 00:11:31.560
of probability that if you have multiple

00:11:30.240 --> 00:11:33.720
variables and you're calculating the

00:11:31.560 --> 00:11:35.760
joint probability of variables the

00:11:33.720 --> 00:11:38.000
probability of all of the variables

00:11:35.760 --> 00:11:40.240
together is equal to this probability

00:11:38.000 --> 00:11:41.920
here so we're not making any

00:11:40.240 --> 00:11:44.399
approximations we're not making any

00:11:41.920 --> 00:11:46.959
compromises in order to do this but it

00:11:44.399 --> 00:11:51.639
all hinges on whether we can predict

00:11:46.959 --> 00:11:53.440
this probability um accurately uh

00:11:51.639 --> 00:11:56.160
actually another question does anybody

00:11:53.440 --> 00:11:57.800
know why we do this decomposition why

00:11:56.160 --> 00:12:00.959
don't we just try to predict the

00:11:57.800 --> 00:12:00.959
probability of x

00:12:02.120 --> 00:12:05.399
directly any

00:12:07.680 --> 00:12:12.760
ideas uh of big X sorry uh why don't we

00:12:11.079 --> 00:12:17.560
try to calculate the probability of this

00:12:12.760 --> 00:12:21.360
is great directly without deated the

00:12:17.560 --> 00:12:21.360
IND that

00:12:25.519 --> 00:12:31.560
possibility it could be word salid if

00:12:27.760 --> 00:12:35.279
you did it in a in a particular way yes

00:12:31.560 --> 00:12:35.279
um so that that's a good point

00:12:39.519 --> 00:12:47.000
yeah yeah so for example we talked about

00:12:43.760 --> 00:12:50.120
um uh we'll talk about

00:12:47.000 --> 00:12:51.920
models um or I I mentioned this briefly

00:12:50.120 --> 00:12:54.000
last time you can mention it in more

00:12:51.920 --> 00:12:55.639
detail this time but this is great we

00:12:54.000 --> 00:12:59.880
probably have never seen this before

00:12:55.639 --> 00:13:01.399
right so if we predict only things that

00:12:59.880 --> 00:13:03.199
we've seen before if we only assign a

00:13:01.399 --> 00:13:04.600
non-zero probability to the things we've

00:13:03.199 --> 00:13:06.000
seen before there's going to be lots of

00:13:04.600 --> 00:13:07.079
sentences that we've never seen before

00:13:06.000 --> 00:13:10.000
it makes it

00:13:07.079 --> 00:13:13.760
supercars um that that's basically close

00:13:10.000 --> 00:13:16.399
to what I wanted to say so um the reason

00:13:13.760 --> 00:13:18.040
why we don't typically do it with um

00:13:16.399 --> 00:13:21.240
predicting the whole sentence directly

00:13:18.040 --> 00:13:22.800
is because if we think about the size of

00:13:21.240 --> 00:13:24.959
the classification problem we need to

00:13:22.800 --> 00:13:27.880
solve in order to predict the next word

00:13:24.959 --> 00:13:30.320
it's a v uh where V is the size of the

00:13:27.880 --> 00:13:33.120
vocabulary but the size of the

00:13:30.320 --> 00:13:35.399
classification problem that we need to

00:13:33.120 --> 00:13:38.040
um we need to solve if we predict

00:13:35.399 --> 00:13:40.079
everything directly is V to the N where

00:13:38.040 --> 00:13:42.240
n is the length of the sequence and

00:13:40.079 --> 00:13:45.240
that's just huge the vocabulary is so

00:13:42.240 --> 00:13:48.440
big that it's hard to kind of uh know

00:13:45.240 --> 00:13:51.000
how we handle that so basically by doing

00:13:48.440 --> 00:13:53.160
this sort of decomposition we decompose

00:13:51.000 --> 00:13:56.440
this into uh

00:13:53.160 --> 00:13:58.120
n um prediction problems of size V and

00:13:56.440 --> 00:13:59.519
that's kind of just a lot more

00:13:58.120 --> 00:14:03.079
manageable for from the point of view of

00:13:59.519 --> 00:14:06.000
how we train uh know how we train

00:14:03.079 --> 00:14:09.399
models um that being said there are

00:14:06.000 --> 00:14:11.360
other Alternatives um something very

00:14:09.399 --> 00:14:13.920
widely known uh very widely used is

00:14:11.360 --> 00:14:16.440
called a MK language model um a mast

00:14:13.920 --> 00:14:19.480
language model is something like Bert or

00:14:16.440 --> 00:14:21.680
debera or Roberta or all of these models

00:14:19.480 --> 00:14:25.000
that you might have heard if you've been

00:14:21.680 --> 00:14:28.279
in MLP for more than two years I guess

00:14:25.000 --> 00:14:30.680
um and basically what they do is they

00:14:28.279 --> 00:14:30.680
predict

00:14:32.199 --> 00:14:37.480
uh they like mask out this word and they

00:14:34.839 --> 00:14:39.480
predict the middle word so they mask out

00:14:37.480 --> 00:14:41.440
is and then try to predict that given

00:14:39.480 --> 00:14:45.320
all the other words the problem with

00:14:41.440 --> 00:14:48.959
these models is uh twofold number one

00:14:45.320 --> 00:14:51.880
they don't actually give you a uh good

00:14:48.959 --> 00:14:55.399
probability here uh like a a properly

00:14:51.880 --> 00:14:57.800
formed probability here

00:14:55.399 --> 00:14:59.160
because this is true only as long as

00:14:57.800 --> 00:15:01.920
you're only conditioning on things that

00:14:59.160 --> 00:15:03.480
you've previously generated so that

00:15:01.920 --> 00:15:04.839
they're not actually true language

00:15:03.480 --> 00:15:06.920
models from the point of view of being

00:15:04.839 --> 00:15:10.040
able to easily predict the probability

00:15:06.920 --> 00:15:11.399
of a sequence um and also it's hard to

00:15:10.040 --> 00:15:13.399
generate from them because you need to

00:15:11.399 --> 00:15:15.440
generate in some order and mass language

00:15:13.399 --> 00:15:17.600
models don't specify economical orders

00:15:15.440 --> 00:15:19.120
so they're good for some things like

00:15:17.600 --> 00:15:21.720
calculating representations of the

00:15:19.120 --> 00:15:22.920
output but they're not useful uh they're

00:15:21.720 --> 00:15:25.240
not as useful for

00:15:22.920 --> 00:15:26.880
Generation Um there's also energy based

00:15:25.240 --> 00:15:28.759
language models which basically create a

00:15:26.880 --> 00:15:30.000
scoring function that's not necessarily

00:15:28.759 --> 00:15:31.279
left to right or right to left or

00:15:30.000 --> 00:15:33.120
anything like that but that's very

00:15:31.279 --> 00:15:34.639
Advanced um if you're interested in them

00:15:33.120 --> 00:15:36.319
I can talk more about them that we'll

00:15:34.639 --> 00:15:38.920
skip

00:15:36.319 --> 00:15:41.600
them and um also all of the language

00:15:38.920 --> 00:15:45.639
models that you hear about nowadays GPT

00:15:41.600 --> 00:15:48.800
uh llama whatever else are all other

00:15:45.639 --> 00:15:52.880
models cool so I'm going to go into the

00:15:48.800 --> 00:15:52.880
very um any questions about that

00:15:57.600 --> 00:16:00.600
yeah

00:16:00.680 --> 00:16:04.160
yeah so in Mass language models the

00:16:02.680 --> 00:16:06.000
question was in Mass language models

00:16:04.160 --> 00:16:08.360
couldn't you just mask out the last

00:16:06.000 --> 00:16:10.759
token and predict that sure you could do

00:16:08.360 --> 00:16:13.079
that but there it's just not trained

00:16:10.759 --> 00:16:14.720
that way so it won't do a very good job

00:16:13.079 --> 00:16:16.880
if you always trained it that way it's

00:16:14.720 --> 00:16:18.160
an autor regressive language model so

00:16:16.880 --> 00:16:22.240
you're you're back to where you were in

00:16:18.160 --> 00:16:24.800
the first place um cool so now we I'll

00:16:22.240 --> 00:16:26.399
talk about unigram language models and

00:16:24.800 --> 00:16:29.319
so the simplest language models are

00:16:26.399 --> 00:16:33.560
count-based unigram language models and

00:16:29.319 --> 00:16:35.319
the way they work is um basically we

00:16:33.560 --> 00:16:38.519
want to calculate this probability

00:16:35.319 --> 00:16:41.240
conditioned on all the previous ones and

00:16:38.519 --> 00:16:42.360
the way we do this is we just say

00:16:41.240 --> 00:16:45.680
actually we're not going to worry about

00:16:42.360 --> 00:16:48.759
the order at all and we're just going to

00:16:45.680 --> 00:16:52.240
uh predict the probability of the next

00:16:48.759 --> 00:16:55.279
word uh independently of all the other

00:16:52.240 --> 00:16:57.519
words so if you have something like this

00:16:55.279 --> 00:16:59.720
it's actually extremely easy to predict

00:16:57.519 --> 00:17:02.480
the probability of this word and the way

00:16:59.720 --> 00:17:04.280
you do this is you just count up the

00:17:02.480 --> 00:17:08.360
number of times this word appeared in

00:17:04.280 --> 00:17:10.480
the training data set and divide by the

00:17:08.360 --> 00:17:12.559
uh divide by the total number of words

00:17:10.480 --> 00:17:14.240
in the pring data set and now you have a

00:17:12.559 --> 00:17:15.959
language model this is like language

00:17:14.240 --> 00:17:17.760
model 101 it's the easiest possible

00:17:15.959 --> 00:17:19.520
language model you can write in you know

00:17:17.760 --> 00:17:21.120
three lines of python

00:17:19.520 --> 00:17:25.039
basically

00:17:21.120 --> 00:17:28.480
um so it has a few problems uh the first

00:17:25.039 --> 00:17:31.120
problem with this language model is um

00:17:28.480 --> 00:17:32.960
handling unknown words so what happens

00:17:31.120 --> 00:17:38.679
if you have a word that you've never

00:17:32.960 --> 00:17:41.000
seen before um in this language model

00:17:38.679 --> 00:17:42.240
here what is the probability of any

00:17:41.000 --> 00:17:44.720
sequence that has a word that you've

00:17:42.240 --> 00:17:47.440
never seen before yeah the probability

00:17:44.720 --> 00:17:49.240
of the sequence gets zero so there might

00:17:47.440 --> 00:17:51.120
not be such a big problem for generating

00:17:49.240 --> 00:17:52.480
things from the language model because

00:17:51.120 --> 00:17:54.520
you know maybe it's fine if you only

00:17:52.480 --> 00:17:55.960
generate words that you've seen before

00:17:54.520 --> 00:17:57.679
uh but it is definitely a problem of

00:17:55.960 --> 00:17:59.720
scoring things with the language model

00:17:57.679 --> 00:18:02.039
and it's also a problem of uh for

00:17:59.720 --> 00:18:04.440
something like translation if you get an

00:18:02.039 --> 00:18:05.840
unknown word uh when you're translating

00:18:04.440 --> 00:18:07.799
something then you would like to be able

00:18:05.840 --> 00:18:11.320
to translate it reasonably but you can't

00:18:07.799 --> 00:18:13.799
do that so um that's an issue so how do

00:18:11.320 --> 00:18:15.840
we how do we fix this um there's a

00:18:13.799 --> 00:18:17.640
couple options the first option is to

00:18:15.840 --> 00:18:19.440
segment to characters and subwords and

00:18:17.640 --> 00:18:21.720
this is now the preferred option that

00:18:19.440 --> 00:18:24.360
most people use nowadays uh just run

00:18:21.720 --> 00:18:26.840
sentence piece segment your vocabulary

00:18:24.360 --> 00:18:28.400
and you're all set you're you'll now no

00:18:26.840 --> 00:18:29.679
longer have any unknown words because

00:18:28.400 --> 00:18:30.840
all the unknown words get split into

00:18:29.679 --> 00:18:33.559
shorter

00:18:30.840 --> 00:18:36.240
units there's also other options that

00:18:33.559 --> 00:18:37.919
you can use if you're uh very interested

00:18:36.240 --> 00:18:41.280
in or serious about this and want to

00:18:37.919 --> 00:18:43.720
handle this like uh as part of a

00:18:41.280 --> 00:18:45.960
research project or something like this

00:18:43.720 --> 00:18:48.520
and uh the way you can do this is you

00:18:45.960 --> 00:18:50.120
can build an unknown word model and an

00:18:48.520 --> 00:18:52.200
unknown word model basically what it

00:18:50.120 --> 00:18:54.520
does is it uh predicts the probability

00:18:52.200 --> 00:18:56.200
of unknown words using characters and

00:18:54.520 --> 00:18:59.559
then it models the probability of words

00:18:56.200 --> 00:19:01.159
using words and so now you can you have

00:18:59.559 --> 00:19:02.559
kind of like a hierarchical model where

00:19:01.159 --> 00:19:03.919
you first try to predict words and then

00:19:02.559 --> 00:19:06.720
if you can't predict words you predict

00:19:03.919 --> 00:19:08.960
unknown words so this isn't us as widely

00:19:06.720 --> 00:19:11.520
anymore but it's worth thinking about uh

00:19:08.960 --> 00:19:11.520
or knowing

00:19:11.840 --> 00:19:20.880
about okay uh so a second detail um a

00:19:17.200 --> 00:19:22.799
parameter uh so parameterizing in log

00:19:20.880 --> 00:19:25.880
space

00:19:22.799 --> 00:19:28.400
so the um multiplication of

00:19:25.880 --> 00:19:29.840
probabilities can be reexpressed is the

00:19:28.400 --> 00:19:31.840
addition of log

00:19:29.840 --> 00:19:34.159
probabilities uh so this is really

00:19:31.840 --> 00:19:35.720
important and this is widely used in all

00:19:34.159 --> 00:19:37.520
language models whether they're unigram

00:19:35.720 --> 00:19:39.640
language models or or neural language

00:19:37.520 --> 00:19:41.799
models there's actually a very simple

00:19:39.640 --> 00:19:45.440
reason why we why we do it this way does

00:19:41.799 --> 00:19:45.440
anybody uh know the

00:19:46.440 --> 00:19:52.679
answer what would happen if we

00:19:48.280 --> 00:19:56.720
multiplied uh let's say uh 30 30 tokens

00:19:52.679 --> 00:20:00.360
worth of probabilities together um

00:19:56.720 --> 00:20:02.120
yeah uh yeah too too small um so

00:20:00.360 --> 00:20:06.120
basically the problem is numerical

00:20:02.120 --> 00:20:07.520
underflow um so modern computers if if

00:20:06.120 --> 00:20:08.840
we weren't doing this on a computer and

00:20:07.520 --> 00:20:11.240
we were just doing math it wouldn't

00:20:08.840 --> 00:20:14.280
matter at all um but because we're doing

00:20:11.240 --> 00:20:17.280
it on a computer uh we

00:20:14.280 --> 00:20:17.280
have

00:20:20.880 --> 00:20:26.000
ours we have our

00:20:23.000 --> 00:20:26.000
32bit

00:20:27.159 --> 00:20:30.159
float

00:20:32.320 --> 00:20:37.720
where we have uh the exponent in the the

00:20:35.799 --> 00:20:40.159
fraction over here so the largest the

00:20:37.720 --> 00:20:41.960
exponent can get is limited by the

00:20:40.159 --> 00:20:45.880
number of exponent bits that we have in

00:20:41.960 --> 00:20:48.039
a 32-bit float and um if that's the case

00:20:45.880 --> 00:20:52.480
I forget exactly how large it is it's

00:20:48.039 --> 00:20:53.440
like yeah something like 30 minus 38 is

00:20:52.480 --> 00:20:56.640
that

00:20:53.440 --> 00:20:58.520
right yeah but anyway like if the number

00:20:56.640 --> 00:21:00.640
gets too small you'll underflow it goes

00:20:58.520 --> 00:21:02.400
to zero and you'll get a zero

00:21:00.640 --> 00:21:05.720
probability despite the fact that it's

00:21:02.400 --> 00:21:07.640
not actually zero so um that's usually

00:21:05.720 --> 00:21:09.440
why we do this it's also a little bit

00:21:07.640 --> 00:21:12.960
easier for people just to look at like

00:21:09.440 --> 00:21:15.200
minus 30 instead of looking to something

00:21:12.960 --> 00:21:19.960
something time 10 to the minus 30 or

00:21:15.200 --> 00:21:24.520
something so uh that is why we normally

00:21:19.960 --> 00:21:27.159
go um another thing that you can note is

00:21:24.520 --> 00:21:28.760
uh you can treat each of these in a

00:21:27.159 --> 00:21:31.360
unigram model you can treat each of

00:21:28.760 --> 00:21:37.039
these as parameters so we talked about

00:21:31.360 --> 00:21:39.640
parameters of a model uh like a um like

00:21:37.039 --> 00:21:41.120
a bag of words model and we can

00:21:39.640 --> 00:21:44.080
similarly treat these unigram

00:21:41.120 --> 00:21:47.760
probabilities as parameters so um how

00:21:44.080 --> 00:21:47.760
many parameters does a unigram model

00:21:48.080 --> 00:21:51.320
have any

00:21:57.039 --> 00:22:02.400
ideas

00:21:59.600 --> 00:22:04.440
yeah yeah exactly parameters equal to

00:22:02.400 --> 00:22:08.120
the size of the vocabulary so this one's

00:22:04.440 --> 00:22:10.880
easy and then we can go um we can go to

00:22:08.120 --> 00:22:13.880
the slightly less easy ones

00:22:10.880 --> 00:22:16.039
there so anyway this is a unigram model

00:22:13.880 --> 00:22:17.960
uh it's it's not too hard um you

00:22:16.039 --> 00:22:20.480
basically count up and divide and then

00:22:17.960 --> 00:22:22.720
you add the the probabilities here you

00:22:20.480 --> 00:22:25.440
could easily do it in a short Python

00:22:22.720 --> 00:22:28.400
program higher order engram models so

00:22:25.440 --> 00:22:31.600
higher order engram models um what these

00:22:28.400 --> 00:22:35.520
do is they essentially limit the context

00:22:31.600 --> 00:22:40.240
length to a length of N and then they

00:22:35.520 --> 00:22:42.600
count and divide so the way it works

00:22:40.240 --> 00:22:45.559
here maybe this is a little bit uh

00:22:42.600 --> 00:22:47.320
tricky but I can show an example so what

00:22:45.559 --> 00:22:49.840
we do is we count up the number of times

00:22:47.320 --> 00:22:51.320
we've seen this is an example and then

00:22:49.840 --> 00:22:53.480
we divide by the number of times we've

00:22:51.320 --> 00:22:55.960
seen this is n and that's the

00:22:53.480 --> 00:22:56.960
probability of example given the the

00:22:55.960 --> 00:22:58.720
previous

00:22:56.960 --> 00:23:00.559
coms

00:22:58.720 --> 00:23:02.039
so the problem with this is anytime we

00:23:00.559 --> 00:23:03.400
get a sequence that we've never seen

00:23:02.039 --> 00:23:04.960
before like we would like to model

00:23:03.400 --> 00:23:07.200
longer sequences to make this more

00:23:04.960 --> 00:23:08.600
accurate but anytime we've get a uh we

00:23:07.200 --> 00:23:10.720
get a sequence that we've never seen

00:23:08.600 --> 00:23:12.919
before um it will get a probability of

00:23:10.720 --> 00:23:15.919
zero similarly because this count on top

00:23:12.919 --> 00:23:19.919
of here will be zero so the way that uh

00:23:15.919 --> 00:23:22.640
engram language models work with this uh

00:23:19.919 --> 00:23:27.320
handle this is they have fall back to

00:23:22.640 --> 00:23:31.840
Shorter uh engram models so um this

00:23:27.320 --> 00:23:33.480
model sorry when I say NR uh n is the

00:23:31.840 --> 00:23:35.520
length of the context so this is a four

00:23:33.480 --> 00:23:37.679
gr model here because the top context is

00:23:35.520 --> 00:23:40.520
four so the photogram model would

00:23:37.679 --> 00:23:46.640
calculate this and then interpolate it

00:23:40.520 --> 00:23:48.640
like this with a um with a trigram model

00:23:46.640 --> 00:23:50.400
uh and then the trigram model itself

00:23:48.640 --> 00:23:51.720
would interpolate with the Byram model

00:23:50.400 --> 00:23:53.440
the Byram model would interpolate with

00:23:51.720 --> 00:23:56.880
the unram

00:23:53.440 --> 00:23:59.880
model oh this one oh

00:23:56.880 --> 00:23:59.880
okay

00:24:02.159 --> 00:24:05.440
um one

00:24:07.039 --> 00:24:12.320
second could you uh help get it from the

00:24:10.000 --> 00:24:12.320
lock

00:24:26.799 --> 00:24:29.799
box

00:24:43.640 --> 00:24:50.200
um okay sorry

00:24:46.880 --> 00:24:53.640
so getting bad

00:24:50.200 --> 00:24:56.640
here just

00:24:53.640 --> 00:24:56.640
actually

00:24:56.760 --> 00:25:02.559
okay uh oh wow that's a lot

00:25:02.960 --> 00:25:12.080
better cool okay so

00:25:08.279 --> 00:25:14.159
um so this is uh how we deal with the

00:25:12.080 --> 00:25:18.799
fact that models can

00:25:14.159 --> 00:25:23.919
be um models can be more precise but

00:25:18.799 --> 00:25:26.679
more sparse and less precise but less

00:25:23.919 --> 00:25:28.720
sparse this is also another concept that

00:25:26.679 --> 00:25:31.039
we're going to talk about more later uh

00:25:28.720 --> 00:25:33.240
in another class but this is a variety

00:25:31.039 --> 00:25:33.240
of

00:25:33.679 --> 00:25:38.440
ensembling where we have different

00:25:35.960 --> 00:25:40.360
models that are good at different things

00:25:38.440 --> 00:25:42.279
and we combine them together so this is

00:25:40.360 --> 00:25:44.760
the first instance that you would see of

00:25:42.279 --> 00:25:46.159
this there are other instances of this

00:25:44.760 --> 00:25:50.320
but the reason why I mentioned that this

00:25:46.159 --> 00:25:51.840
is a a variety of ensembling is actually

00:25:50.320 --> 00:25:55.520
you're probably not going to be using

00:25:51.840 --> 00:25:57.840
engram models super widely unless you

00:25:55.520 --> 00:26:00.520
really want to process huge data sets

00:25:57.840 --> 00:26:02.399
because that is one advantage of them

00:26:00.520 --> 00:26:03.960
but some of these smoothing methods

00:26:02.399 --> 00:26:05.720
actually might be interesting even if

00:26:03.960 --> 00:26:10.520
you're using other models and ensembling

00:26:05.720 --> 00:26:10.520
them together so

00:26:10.600 --> 00:26:15.679
the in order to decide this

00:26:13.679 --> 00:26:19.559
interpolation coefficient one way we can

00:26:15.679 --> 00:26:23.440
do it is just set a fixed um set a fixed

00:26:19.559 --> 00:26:26.039
amount of probability that we use for

00:26:23.440 --> 00:26:29.000
every um every time so we could say that

00:26:26.039 --> 00:26:32.000
we always set this Lambda to 0.8 and

00:26:29.000 --> 00:26:34.320
some always set this Lambda 1us Lambda

00:26:32.000 --> 00:26:36.559
to 0.2 and interpolate those two

00:26:34.320 --> 00:26:39.120
together but actually there's more

00:26:36.559 --> 00:26:42.240
sophisticated methods of doing this and

00:26:39.120 --> 00:26:44.080
so one way of doing this is uh called

00:26:42.240 --> 00:26:47.240
additive

00:26:44.080 --> 00:26:50.600
smoothing excuse me and the the way that

00:26:47.240 --> 00:26:54.039
additive smoothing works is um basically

00:26:50.600 --> 00:26:54.919
we add Alpha to the uh to the top and

00:26:54.039 --> 00:26:58.000
the

00:26:54.919 --> 00:27:02.159
bottom and the reason why this is slight

00:26:58.000 --> 00:27:06.279
different as is as our accounts get

00:27:02.159 --> 00:27:10.799
larger we start to approach the true

00:27:06.279 --> 00:27:10.799
distribution so just to give an

00:27:12.080 --> 00:27:19.480
example let's say we have uh the

00:27:17.640 --> 00:27:21.640
box

00:27:19.480 --> 00:27:26.279
is

00:27:21.640 --> 00:27:26.279
um let's say initially we

00:27:26.520 --> 00:27:29.520
have

00:27:31.159 --> 00:27:37.600
uh let let's say our Alpha is

00:27:33.840 --> 00:27:43.559
one so initially if we have

00:27:37.600 --> 00:27:47.320
nothing um if we have no no evidence for

00:27:43.559 --> 00:27:47.320
our sorry I I

00:27:49.720 --> 00:27:54.960
realize let's say this is

00:27:52.640 --> 00:27:56.840
our fallback

00:27:54.960 --> 00:27:59.240
distribution um where this is a

00:27:56.840 --> 00:28:01.880
probability of Z 0.5 this is a

00:27:59.240 --> 00:28:03.360
probability of 0.3 and this is a

00:28:01.880 --> 00:28:06.559
probability of

00:28:03.360 --> 00:28:09.919
0.2 so now let's talk about our byr

00:28:06.559 --> 00:28:13.399
model um and our byr

00:28:09.919 --> 00:28:18.000
model has counts which is the

00:28:13.399 --> 00:28:18.000
the the box and the

00:28:19.039 --> 00:28:24.480
is so if we do something like this then

00:28:22.720 --> 00:28:26.720
um initially we have no counts like

00:28:24.480 --> 00:28:28.159
let's say we we have no data uh about

00:28:26.720 --> 00:28:30.760
this distribution

00:28:28.159 --> 00:28:33.200
um our counts would be zero and our

00:28:30.760 --> 00:28:35.919
Alpha would be

00:28:33.200 --> 00:28:37.840
one and so we would just fall back to

00:28:35.919 --> 00:28:40.960
this distribution we just have like one

00:28:37.840 --> 00:28:43.320
times uh one times this distribution

00:28:40.960 --> 00:28:45.679
let's say we then we have one piece of

00:28:43.320 --> 00:28:48.640
evidence and once we have one piece of

00:28:45.679 --> 00:28:52.279
evidence now this would be

00:28:48.640 --> 00:28:53.960
0.33 um and this would uh be Alpha equal

00:28:52.279 --> 00:28:56.399
to 1 so we'd have

00:28:53.960 --> 00:28:58.679
0.5 *

00:28:56.399 --> 00:29:00.399
0.33

00:28:58.679 --> 00:29:04.039
uh and

00:29:00.399 --> 00:29:07.720
0.5 time

00:29:04.039 --> 00:29:10.840
0.3 uh is the probability of the Box

00:29:07.720 --> 00:29:12.840
because um basically we we have one

00:29:10.840 --> 00:29:14.720
piece of evidence and we are adding a

00:29:12.840 --> 00:29:17.080
count of one to the lower order

00:29:14.720 --> 00:29:18.320
distribution then if we increase our

00:29:17.080 --> 00:29:24.159
count

00:29:18.320 --> 00:29:24.159
here um now we rely more

00:29:24.880 --> 00:29:30.960
strongly sorry that that would be wrong

00:29:27.720 --> 00:29:32.399
so so now we rely more strongly on the

00:29:30.960 --> 00:29:33.880
higher order distribution because we

00:29:32.399 --> 00:29:37.039
have more evidence for the higher order

00:29:33.880 --> 00:29:39.610
distribution so basically in this case

00:29:37.039 --> 00:29:41.240
um the probability

00:29:39.610 --> 00:29:44.559
[Music]

00:29:41.240 --> 00:29:48.200
of Lambda which I showed

00:29:44.559 --> 00:29:52.000
before is equal to the the sum of the

00:29:48.200 --> 00:29:54.200
counts plus um the sum of the counts

00:29:52.000 --> 00:29:56.480
over the sum of the counts plus

00:29:54.200 --> 00:29:58.159
Ali so as the sum of the counts gets

00:29:56.480 --> 00:30:00.240
larger you rely on the higher order

00:29:58.159 --> 00:30:01.640
distribution is the sum of the counts is

00:30:00.240 --> 00:30:02.760
if the sum of the counts is smaller you

00:30:01.640 --> 00:30:04.320
rely more on the lower order

00:30:02.760 --> 00:30:06.720
distribution so the more evidence you

00:30:04.320 --> 00:30:11.640
have the more you rely on so that's the

00:30:06.720 --> 00:30:11.640
basic idea behind these smoothing things

00:30:11.679 --> 00:30:16.679
um there's also a number of other

00:30:14.519 --> 00:30:18.760
varieties called uh

00:30:16.679 --> 00:30:20.799
discounting so uh the discount

00:30:18.760 --> 00:30:23.679
hyperparameter basically you subtract

00:30:20.799 --> 00:30:26.080
this off um uh you subtract this from

00:30:23.679 --> 00:30:27.840
the count so you would subtract like 0.5

00:30:26.080 --> 00:30:32.679
from each of the counts that you it's

00:30:27.840 --> 00:30:36.279
just empirically this is a better match

00:30:32.679 --> 00:30:38.600
for the fact that um natural language

00:30:36.279 --> 00:30:40.039
has a very longtailed distribution um

00:30:38.600 --> 00:30:41.600
you can kind of do the math and show

00:30:40.039 --> 00:30:43.720
that that works and that's actually in

00:30:41.600 --> 00:30:46.080
this um in this paper if you're

00:30:43.720 --> 00:30:49.880
interested in looking at more details of

00:30:46.080 --> 00:30:51.519
that um and then kind of the

00:30:49.880 --> 00:30:53.440
stateoftheart in language modeling

00:30:51.519 --> 00:30:56.600
before neural language models came out

00:30:53.440 --> 00:30:59.919
was this kesser smoothing and what it

00:30:56.600 --> 00:31:02.440
does is it discounts but it also

00:30:59.919 --> 00:31:04.480
modifies the lower order distribution so

00:31:02.440 --> 00:31:07.200
in the lower order distribution you

00:31:04.480 --> 00:31:09.039
basically um modify the counts with

00:31:07.200 --> 00:31:11.919
respect to how many times that word has

00:31:09.039 --> 00:31:13.519
appeared in new contexts with the IDE

00:31:11.919 --> 00:31:16.360
idea being that you only use the lower

00:31:13.519 --> 00:31:18.880
order distribution when you have uh new

00:31:16.360 --> 00:31:21.200
contexts um and so you can kind of Be

00:31:18.880 --> 00:31:23.600
Clever

00:31:21.200 --> 00:31:25.399
About You Can Be Clever about how you

00:31:23.600 --> 00:31:27.639
build this distribution based on the

00:31:25.399 --> 00:31:29.360
fact that you're only using it in the

00:31:27.639 --> 00:31:31.320
case when this distribution is not very

00:31:29.360 --> 00:31:33.960
Rel

00:31:31.320 --> 00:31:36.080
so I I would spend a lot more time

00:31:33.960 --> 00:31:37.960
teaching this when uh engram models were

00:31:36.080 --> 00:31:39.840
kind of the thing uh that people were

00:31:37.960 --> 00:31:41.960
using but now I'm going to go over them

00:31:39.840 --> 00:31:43.600
very quickly so you know don't worry if

00:31:41.960 --> 00:31:46.559
you weren't able to follow all the

00:31:43.600 --> 00:31:47.960
details but the basic um the basic thing

00:31:46.559 --> 00:31:49.279
take away from this is number one these

00:31:47.960 --> 00:31:51.639
are the methods that people use for

00:31:49.279 --> 00:31:53.440
engram language models number two if

00:31:51.639 --> 00:31:55.720
you're thinking about combining language

00:31:53.440 --> 00:31:57.519
models together in some way through you

00:31:55.720 --> 00:31:59.279
know ensembling their probability or

00:31:57.519 --> 00:32:00.480
something like this this is something

00:31:59.279 --> 00:32:02.279
that you should think about a little bit

00:32:00.480 --> 00:32:03.679
more carefully because like some

00:32:02.279 --> 00:32:05.240
language models might be good in some

00:32:03.679 --> 00:32:07.440
context other language models might be

00:32:05.240 --> 00:32:09.440
good in other contexts so you would need

00:32:07.440 --> 00:32:11.799
to think about that when you're doing um

00:32:09.440 --> 00:32:18.200
when you're combining the model

00:32:11.799 --> 00:32:18.200
that cool um any any questions about

00:32:19.080 --> 00:32:24.840
this Okay

00:32:21.159 --> 00:32:27.840
cool so there's a lot of problems that

00:32:24.840 --> 00:32:30.760
we have to deal with um when were

00:32:27.840 --> 00:32:32.600
creating engram models and that actually

00:32:30.760 --> 00:32:35.279
kind of motivated the reason why we

00:32:32.600 --> 00:32:36.639
moved to neural language models the

00:32:35.279 --> 00:32:38.720
first one is similar to what I talked

00:32:36.639 --> 00:32:40.519
about last time with text classification

00:32:38.720 --> 00:32:42.600
um that they can't share strength among

00:32:40.519 --> 00:32:45.159
similar words like bought and

00:32:42.600 --> 00:32:46.919
purchase um another thing is that they

00:32:45.159 --> 00:32:49.440
can't easily condition on context with

00:32:46.919 --> 00:32:51.240
intervening words so engram models if

00:32:49.440 --> 00:32:52.799
you have a rare word in your context

00:32:51.240 --> 00:32:54.320
immediately start falling back to the

00:32:52.799 --> 00:32:56.799
unigram distribution and they end up

00:32:54.320 --> 00:32:58.720
being very bad so uh that was another

00:32:56.799 --> 00:33:01.000
issue

00:32:58.720 --> 00:33:04.760
and they couldn't handle long distance

00:33:01.000 --> 00:33:09.080
um dependencies so if this was beyond

00:33:04.760 --> 00:33:10.559
the engram context that they would uh be

00:33:09.080 --> 00:33:14.320
handling then you wouldn't be able to

00:33:10.559 --> 00:33:15.840
manage this so actually before neural

00:33:14.320 --> 00:33:18.000
language models became a really big

00:33:15.840 --> 00:33:19.960
thing uh people came up with a bunch of

00:33:18.000 --> 00:33:22.760
individual solutions for this in order

00:33:19.960 --> 00:33:24.440
to solve the problems but actually it

00:33:22.760 --> 00:33:26.679
wasn't that these Solutions didn't work

00:33:24.440 --> 00:33:29.159
at all it was just that engineering all

00:33:26.679 --> 00:33:30.519
of them together was so hard that nobody

00:33:29.159 --> 00:33:32.120
actually ever did that and so they

00:33:30.519 --> 00:33:35.120
relied on just engram models out of the

00:33:32.120 --> 00:33:37.600
box and that wasn't scalable so it's

00:33:35.120 --> 00:33:39.279
kind of a funny example of how like

00:33:37.600 --> 00:33:42.000
actually neural networks despite all the

00:33:39.279 --> 00:33:43.559
pain that they cause in some areas are a

00:33:42.000 --> 00:33:47.120
much better engineering solution to

00:33:43.559 --> 00:33:51.279
solve all the issues that previous

00:33:47.120 --> 00:33:53.159
method cool um so when they use uh Eng

00:33:51.279 --> 00:33:54.799
grab models neural language models

00:33:53.159 --> 00:33:56.559
achieve better performance but Eng grab

00:33:54.799 --> 00:33:58.440
models are very very fast to estimate

00:33:56.559 --> 00:33:59.880
and apply you can even estimate them

00:33:58.440 --> 00:34:04.399
completely in

00:33:59.880 --> 00:34:07.720
parallel um engram models also I I don't

00:34:04.399 --> 00:34:10.399
know if this is necessarily

00:34:07.720 --> 00:34:13.200
A a thing that

00:34:10.399 --> 00:34:15.079
you a reason to use engram language

00:34:13.200 --> 00:34:17.720
models but it is a reason to think a

00:34:15.079 --> 00:34:20.320
little bit critically about uh neural

00:34:17.720 --> 00:34:22.720
language models which is neural language

00:34:20.320 --> 00:34:24.320
models actually can be worse than engram

00:34:22.720 --> 00:34:26.679
language models at modeling very low

00:34:24.320 --> 00:34:28.480
frequency phenomenas so engram language

00:34:26.679 --> 00:34:29.960
model can learn from a single example

00:34:28.480 --> 00:34:32.119
they only need a single example of

00:34:29.960 --> 00:34:36.879
anything before the probability of that

00:34:32.119 --> 00:34:38.639
continuation goes up very high um and uh

00:34:36.879 --> 00:34:41.359
but neural language models actually can

00:34:38.639 --> 00:34:43.599
forget or not memorize uh appropriately

00:34:41.359 --> 00:34:46.280
from single examples so they can be

00:34:43.599 --> 00:34:48.040
better at that um there's a toolkit the

00:34:46.280 --> 00:34:49.919
standard toolkit for estimating engram

00:34:48.040 --> 00:34:54.359
language models is called KLM it's kind

00:34:49.919 --> 00:34:57.599
of frighteningly fast um and so people

00:34:54.359 --> 00:35:00.400
have been uh saying like I've seen some

00:34:57.599 --> 00:35:01.599
jokes which are like job postings that

00:35:00.400 --> 00:35:04.040
say people who have been working on

00:35:01.599 --> 00:35:05.880
large language models uh for we want

00:35:04.040 --> 00:35:07.359
people who have been 10 years of

00:35:05.880 --> 00:35:09.240
experience working on large language

00:35:07.359 --> 00:35:11.960
models or something like that and a lot

00:35:09.240 --> 00:35:13.440
of people are saying wait nobody has 10

00:35:11.960 --> 00:35:16.400
years of experience working on large

00:35:13.440 --> 00:35:18.160
language models well Kenneth hfield who

00:35:16.400 --> 00:35:19.440
created KLM does have 10 years of

00:35:18.160 --> 00:35:22.800
experience working on large language

00:35:19.440 --> 00:35:24.599
models because he was estimating uh

00:35:22.800 --> 00:35:27.720
seven gr

00:35:24.599 --> 00:35:30.320
bottles um seven models with a

00:35:27.720 --> 00:35:35.040
vocabulary of let's say

00:35:30.320 --> 00:35:37.720
100,000 on um you know web text so how

00:35:35.040 --> 00:35:41.119
many parameters is at that's more than

00:35:37.720 --> 00:35:44.320
any you know large neural language model

00:35:41.119 --> 00:35:45.640
that we have nowadays so um they they

00:35:44.320 --> 00:35:47.520
have a lot of these parameters are

00:35:45.640 --> 00:35:49.400
sparse they're zero counts so obviously

00:35:47.520 --> 00:35:52.160
you don't uh you don't memorize all of

00:35:49.400 --> 00:35:55.040
them but uh

00:35:52.160 --> 00:35:57.800
yeah cool um another thing that maybe I

00:35:55.040 --> 00:35:59.359
should mention like so this doesn't

00:35:57.800 --> 00:36:01.960
sound completely outdated there was a

00:35:59.359 --> 00:36:05.400
really good paper

00:36:01.960 --> 00:36:08.400
recently that used the fact that engrams

00:36:05.400 --> 00:36:08.400
are

00:36:11.079 --> 00:36:17.319
so uses effect that engram models are so

00:36:14.280 --> 00:36:18.960
scalable it's this paper um it's called

00:36:17.319 --> 00:36:21.079
Data selection for language models via

00:36:18.960 --> 00:36:22.359
importance rese sampling and one

00:36:21.079 --> 00:36:24.359
interesting thing that they do in this

00:36:22.359 --> 00:36:28.920
paper is that they don't

00:36:24.359 --> 00:36:31.560
actually um they don't

00:36:28.920 --> 00:36:32.800
actually use neural models in any way

00:36:31.560 --> 00:36:34.920
despite the fact that they use the

00:36:32.800 --> 00:36:36.880
downstream data that they sample in

00:36:34.920 --> 00:36:41.319
order to calculate neural models but

00:36:36.880 --> 00:36:42.880
they run engram models over um over lots

00:36:41.319 --> 00:36:47.359
and lots of data and then they fit a

00:36:42.880 --> 00:36:50.000
gaussian distribution to the enr model

00:36:47.359 --> 00:36:51.520
counts basically uh in order to select

00:36:50.000 --> 00:36:53.040
the data in the reason why they do this

00:36:51.520 --> 00:36:55.280
is they want to do this over the entire

00:36:53.040 --> 00:36:56.760
web and running a neural model over the

00:36:55.280 --> 00:36:58.920
entire web would be too expensive so

00:36:56.760 --> 00:37:00.319
they use angr models instead so that's

00:36:58.920 --> 00:37:02.359
just an example of something in the

00:37:00.319 --> 00:37:04.920
modern context where keeping this in

00:37:02.359 --> 00:37:04.920
mind is a good

00:37:08.200 --> 00:37:14.000
idea okay I'd like to move to the next

00:37:10.960 --> 00:37:15.319
part so a language model evaluation uh

00:37:14.000 --> 00:37:17.200
this is important to know I'm not going

00:37:15.319 --> 00:37:19.079
to talk about language model evaluation

00:37:17.200 --> 00:37:20.599
on other tasks I'm only going to talk

00:37:19.079 --> 00:37:23.800
right now about language model

00:37:20.599 --> 00:37:26.280
evaluation on the task of language

00:37:23.800 --> 00:37:29.079
modeling and there's a number of metrics

00:37:26.280 --> 00:37:30.680
that we use for the task of language

00:37:29.079 --> 00:37:32.720
modeling evaluating language models on

00:37:30.680 --> 00:37:35.560
the task of language modeling the first

00:37:32.720 --> 00:37:38.480
one is log likelihood and basically uh

00:37:35.560 --> 00:37:40.160
the way we calculate log likelihood is

00:37:38.480 --> 00:37:41.640
uh sorry there's an extra parenthesis

00:37:40.160 --> 00:37:45.480
here but the way we calculate log

00:37:41.640 --> 00:37:47.160
likelihood is we get a test set that

00:37:45.480 --> 00:37:50.400
ideally has not been included in our

00:37:47.160 --> 00:37:52.520
training data and we take all of the

00:37:50.400 --> 00:37:54.200
documents or sentences in the test set

00:37:52.520 --> 00:37:57.040
we calculate the log probability of all

00:37:54.200 --> 00:37:59.520
of them uh we don't actually use this

00:37:57.040 --> 00:38:02.640
super broadly to evaluate models and the

00:37:59.520 --> 00:38:04.200
reason why is because this number is

00:38:02.640 --> 00:38:05.720
very dependent on the size of the data

00:38:04.200 --> 00:38:07.119
set so if you have a larger data set

00:38:05.720 --> 00:38:08.720
this number will be larger if you have a

00:38:07.119 --> 00:38:10.960
smaller data set this number will be

00:38:08.720 --> 00:38:14.040
smaller so the more common thing to do

00:38:10.960 --> 00:38:15.839
is per word uh log likelihood and per

00:38:14.040 --> 00:38:19.800
word log likelihood is basically

00:38:15.839 --> 00:38:22.760
dividing the um dividing the log

00:38:19.800 --> 00:38:25.520
probability of the entire corpus with uh

00:38:22.760 --> 00:38:28.359
the number of words that you have in the

00:38:25.520 --> 00:38:31.000
corpus

00:38:28.359 --> 00:38:34.599
um it's also common for papers to report

00:38:31.000 --> 00:38:36.359
negative log likelihood uh where because

00:38:34.599 --> 00:38:37.800
that's used as a loss and there lower is

00:38:36.359 --> 00:38:40.440
better so you just need to be careful

00:38:37.800 --> 00:38:42.560
about which one is being

00:38:40.440 --> 00:38:43.880
reported so this is pretty common I

00:38:42.560 --> 00:38:45.400
think most people are are somewhat

00:38:43.880 --> 00:38:49.040
familiar with

00:38:45.400 --> 00:38:49.800
this another thing that you might see is

00:38:49.040 --> 00:38:53.079
uh

00:38:49.800 --> 00:38:55.000
entropy and uh specifically this is

00:38:53.079 --> 00:38:57.319
often called cross entropy because

00:38:55.000 --> 00:38:59.880
you're calculating

00:38:57.319 --> 00:39:01.599
the you're estimating the model on a

00:38:59.880 --> 00:39:05.079
training data set and then evaluating it

00:39:01.599 --> 00:39:08.400
on a separate data set uh so uh on the

00:39:05.079 --> 00:39:12.200
test data set and this is calcul often

00:39:08.400 --> 00:39:14.640
or usually calculated as log 2 um of the

00:39:12.200 --> 00:39:17.119
probability divided by the number of

00:39:14.640 --> 00:39:18.760
words or units in the Corpus does anyone

00:39:17.119 --> 00:39:23.839
know why this is log

00:39:18.760 --> 00:39:23.839
two as opposed to a normal uh

00:39:25.440 --> 00:39:31.319
log

00:39:28.440 --> 00:39:31.319
anyone yeah

00:39:33.119 --> 00:39:38.720
so yeah so it's calculating as bits um

00:39:36.760 --> 00:39:43.160
and this is kind of

00:39:38.720 --> 00:39:45.240
a um this is kind of a historical thing

00:39:43.160 --> 00:39:47.119
and it's not super super important for

00:39:45.240 --> 00:39:51.800
language models but it's actually pretty

00:39:47.119 --> 00:39:54.599
interesting uh to to think about and so

00:39:51.800 --> 00:39:57.480
actually any probabilistic distribution

00:39:54.599 --> 00:40:00.040
can also be used for data compression

00:39:57.480 --> 00:40:03.319
um and so you know when you're running a

00:40:00.040 --> 00:40:05.000
zip file or you're running gzip or bz2

00:40:03.319 --> 00:40:07.359
or something like that uh you're

00:40:05.000 --> 00:40:09.240
compressing a file into a smaller file

00:40:07.359 --> 00:40:12.000
and any language model can also be used

00:40:09.240 --> 00:40:15.280
to compress a SM file into a smaller

00:40:12.000 --> 00:40:17.119
file um and so the way it does this is

00:40:15.280 --> 00:40:19.200
if you have more likely

00:40:17.119 --> 00:40:20.960
sequences uh for example more likely

00:40:19.200 --> 00:40:25.079
sentences or more likely documents you

00:40:20.960 --> 00:40:26.920
can press them into a a shorter uh

00:40:25.079 --> 00:40:29.440
output and

00:40:26.920 --> 00:40:29.440
kind of

00:40:29.640 --> 00:40:33.800
the

00:40:31.480 --> 00:40:35.720
ideal I I think it's pretty safe to say

00:40:33.800 --> 00:40:37.920
ideal because I think you can't get a

00:40:35.720 --> 00:40:42.920
better method for compression than this

00:40:37.920 --> 00:40:45.000
uh if I unless I'm uh you know not well

00:40:42.920 --> 00:40:46.800
versed enough in information Theory but

00:40:45.000 --> 00:40:49.240
I I think this is basically the ideal

00:40:46.800 --> 00:40:51.960
method for data compression and the way

00:40:49.240 --> 00:40:54.640
it works is um I have a figure up here

00:40:51.960 --> 00:40:58.800
but I'd like to recreate it here which

00:40:54.640 --> 00:41:02.640
is let's say we have a vocabulary of

00:40:58.800 --> 00:41:07.200
a um which has

00:41:02.640 --> 00:41:08.800
50% and then we have a vocabulary uh B

00:41:07.200 --> 00:41:11.560
which is

00:41:08.800 --> 00:41:14.040
33% and a vocabulary

00:41:11.560 --> 00:41:18.520
C

00:41:14.040 --> 00:41:18.520
uh yeah C which is about

00:41:18.640 --> 00:41:25.640
17% and so if you have a single token

00:41:22.960 --> 00:41:26.839
sequence um if you have a single token

00:41:25.640 --> 00:41:30.880
sequence

00:41:26.839 --> 00:41:30.880
what you do is you can

00:41:31.319 --> 00:41:38.800
see divide this into zero and one so if

00:41:36.400 --> 00:41:40.680
your single token sequence is a you can

00:41:38.800 --> 00:41:42.760
just put zero and you'll be done

00:41:40.680 --> 00:41:46.800
encoding it if your single token

00:41:42.760 --> 00:41:51.920
sequence is B

00:41:46.800 --> 00:41:56.520
then um one overlaps with b and c so now

00:41:51.920 --> 00:42:00.920
you need to further split this up into

00:41:56.520 --> 00:42:00.920
uh o and one and you can see

00:42:04.880 --> 00:42:11.440
that let make sure I did that right yeah

00:42:08.359 --> 00:42:11.440
you can you can see

00:42:15.599 --> 00:42:25.720
that one zero is entirely encompassed by

00:42:19.680 --> 00:42:29.200
uh by B so now B is one Z and C uh C is

00:42:25.720 --> 00:42:32.359
not L encompassed by that so you would

00:42:29.200 --> 00:42:39.240
need to further break this up and say

00:42:32.359 --> 00:42:41.880
it's Z one here and now one one

00:42:39.240 --> 00:42:45.520
one is encompassed by this so you would

00:42:41.880 --> 00:42:48.680
get uh you would get C if it was 111 and

00:42:45.520 --> 00:42:51.119
so every every sequence that started

00:42:48.680 --> 00:42:53.000
with zero would start out with a every

00:42:51.119 --> 00:42:54.960
sequence that started out with one zero

00:42:53.000 --> 00:42:57.200
would start with b and every sequence

00:42:54.960 --> 00:43:02.079
that started with 11 one1

00:42:57.200 --> 00:43:04.920
start um and so then you can look at the

00:43:02.079 --> 00:43:06.960
next word and let's say we're using a

00:43:04.920 --> 00:43:09.839
unigram model if we're using a unigram

00:43:06.960 --> 00:43:12.960
model for the next uh the next token

00:43:09.839 --> 00:43:18.200
let's say the next token is C

00:43:12.960 --> 00:43:23.640
so now the next token being C we already

00:43:18.200 --> 00:43:27.920
have B and now we take we subdivide

00:43:23.640 --> 00:43:33.040
B into

00:43:27.920 --> 00:43:35.720
a BC ba a BB and BC and then we find the

00:43:33.040 --> 00:43:40.720
next binary sequence that is entirely

00:43:35.720 --> 00:43:44.000
encompassed by uh BC by this like

00:43:40.720 --> 00:43:45.359
interval and so the moment we find a a

00:43:44.000 --> 00:43:48.520
binary sequence that's entirely

00:43:45.359 --> 00:43:50.599
encompassed by the interval uh then that

00:43:48.520 --> 00:43:53.400
is the the sequence that we can use to

00:43:50.599 --> 00:43:54.640
represent that SC and so um if you're

00:43:53.400 --> 00:43:56.520
interested in this you can look up the

00:43:54.640 --> 00:44:00.400
arithmetic coding on on wikip it's

00:43:56.520 --> 00:44:02.079
pretty fascinating but basically um here

00:44:00.400 --> 00:44:04.040
this is showing the example of the

00:44:02.079 --> 00:44:07.160
unigram model where the probabilities

00:44:04.040 --> 00:44:10.240
don't change based on the context but

00:44:07.160 --> 00:44:13.000
what if we knew that

00:44:10.240 --> 00:44:15.599
c had a really high probability of

00:44:13.000 --> 00:44:22.160
following B so if that's the case now we

00:44:15.599 --> 00:44:24.559
have like a a b c here um like based on

00:44:22.160 --> 00:44:25.880
our our byr model or neural language

00:44:24.559 --> 00:44:29.319
model or something like that so now this

00:44:25.880 --> 00:44:31.240
is interval is much much larger so it's

00:44:29.319 --> 00:44:35.079
much more likely to entirely Encompass a

00:44:31.240 --> 00:44:39.720
shorter string and because of that the

00:44:35.079 --> 00:44:42.440
um the output can be much shorter and so

00:44:39.720 --> 00:44:45.760
if you use this arithmetic encoding um

00:44:42.440 --> 00:44:49.440
over a very long sequence of outputs

00:44:45.760 --> 00:44:52.440
your the length of the sequence that is

00:44:49.440 --> 00:44:56.000
needed to encode this uh this particular

00:44:52.440 --> 00:45:00.359
output is going to be essentially um the

00:44:56.000 --> 00:45:03.319
number of bits according to times the

00:45:00.359 --> 00:45:06.480
times the sequence so this is very

00:45:03.319 --> 00:45:10.000
directly connected to like compression

00:45:06.480 --> 00:45:13.160
and information Theory and stuff like

00:45:10.000 --> 00:45:15.359
that so that that's where entropy comes

00:45:13.160 --> 00:45:17.680
from uh are are there any questions

00:45:15.359 --> 00:45:17.680
about

00:45:19.319 --> 00:45:22.319
this

00:45:24.880 --> 00:45:28.119
yeah

00:45:26.800 --> 00:45:31.880
uh for

00:45:28.119 --> 00:45:34.319
c um so

00:45:31.880 --> 00:45:36.599
111 is

00:45:34.319 --> 00:45:37.920
because let me let me see if I can do

00:45:36.599 --> 00:45:40.559
this

00:45:37.920 --> 00:45:44.240
again

00:45:40.559 --> 00:45:44.240
so I had one

00:45:46.079 --> 00:45:54.520
one so here this interval is

00:45:50.920 --> 00:45:56.839
one this interval is one one this

00:45:54.520 --> 00:46:00.079
interval is 111

00:45:56.839 --> 00:46:03.520
and 111 is the first interval that is

00:46:00.079 --> 00:46:05.520
entirely overlapping with with c um and

00:46:03.520 --> 00:46:08.760
it's not one Z because one one Z is

00:46:05.520 --> 00:46:08.760
overlaping with b and

00:46:09.960 --> 00:46:13.599
c so which

00:46:14.280 --> 00:46:21.720
Cas so which case one

00:46:20.160 --> 00:46:24.800
Z

00:46:21.720 --> 00:46:26.319
one one one

00:46:24.800 --> 00:46:30.800
Z

00:46:26.319 --> 00:46:30.800
when would you use 110 to represent

00:46:32.119 --> 00:46:38.839
something it's a good question I guess

00:46:36.119 --> 00:46:40.599
maybe you wouldn't which seems a little

00:46:38.839 --> 00:46:43.280
bit wasteful

00:46:40.599 --> 00:46:46.160
so let me let me think about that I

00:46:43.280 --> 00:46:49.920
think um it might be the case that you

00:46:46.160 --> 00:46:52.319
just don't use it um

00:46:49.920 --> 00:46:53.559
but yeah I'll try to think about that a

00:46:52.319 --> 00:46:55.920
little bit more because it seems like

00:46:53.559 --> 00:46:59.200
you should use every bet string right so

00:46:55.920 --> 00:47:01.559
um yeah if anybody uh has has the answer

00:46:59.200 --> 00:47:05.160
I'd be happy to hear it otherwise I take

00:47:01.559 --> 00:47:07.079
you cool um so next thing is perplexity

00:47:05.160 --> 00:47:10.640
so this is another one that you see

00:47:07.079 --> 00:47:13.240
commonly and um so perplexity is

00:47:10.640 --> 00:47:16.880
basically two to the ENT uh two to the

00:47:13.240 --> 00:47:20.760
per word entropy or e to the uh negative

00:47:16.880 --> 00:47:24.880
word level log likelihood in log space

00:47:20.760 --> 00:47:28.240
um and so this uh T larger tends to be

00:47:24.880 --> 00:47:32.559
better I'd like to do a little exercise

00:47:28.240 --> 00:47:34.599
to see uh if this works so like let's

00:47:32.559 --> 00:47:39.079
say we have one a dog sees a squirrel it

00:47:34.599 --> 00:47:40.960
will usually um and can anyone guess the

00:47:39.079 --> 00:47:43.480
next word just yell it

00:47:40.960 --> 00:47:46.400
out bar

00:47:43.480 --> 00:47:47.400
okay uh what about that what about

00:47:46.400 --> 00:47:50.400
something

00:47:47.400 --> 00:47:50.400
else

00:47:52.640 --> 00:47:57.520
Chase Run

00:47:54.720 --> 00:48:00.800
Run

00:47:57.520 --> 00:48:00.800
okay John

00:48:01.960 --> 00:48:05.280
John anything

00:48:07.000 --> 00:48:10.400
else any other

00:48:11.280 --> 00:48:16.960
ones so basically what this shows is

00:48:13.640 --> 00:48:16.960
humans are really bad language

00:48:17.160 --> 00:48:24.079
models so uh interestingly every single

00:48:21.520 --> 00:48:26.559
one of the words you predicted here is a

00:48:24.079 --> 00:48:32.240
uh a regular verb

00:48:26.559 --> 00:48:35.200
um but in natural language model gpt2 uh

00:48:32.240 --> 00:48:38.079
the first thing it predicts is B uh

00:48:35.200 --> 00:48:40.440
which is kind of a like the Cula there's

00:48:38.079 --> 00:48:43.400
also start and that will be like start

00:48:40.440 --> 00:48:44.880
running start something um and humans

00:48:43.400 --> 00:48:46.400
actually are really bad at doing this

00:48:44.880 --> 00:48:49.079
are really bad at predicting next words

00:48:46.400 --> 00:48:51.760
we're not trained that way um and so uh

00:48:49.079 --> 00:48:54.319
we end up having these biases but anyway

00:48:51.760 --> 00:48:55.799
um the reason why I did this quiz was

00:48:54.319 --> 00:48:57.280
because that's essentially what

00:48:55.799 --> 00:49:01.160
perplexity

00:48:57.280 --> 00:49:02.680
means um and what what perplexity is is

00:49:01.160 --> 00:49:04.559
it's the number of times you'd have to

00:49:02.680 --> 00:49:07.000
sample from the probability distribution

00:49:04.559 --> 00:49:09.200
before you get the answer right so you

00:49:07.000 --> 00:49:11.160
were a little bit biased here because we

00:49:09.200 --> 00:49:13.359
were doing sampling without replacement

00:49:11.160 --> 00:49:15.480
so like nobody was actually picking a

00:49:13.359 --> 00:49:17.000
word that had already been said but it's

00:49:15.480 --> 00:49:18.319
essentially like if you guessed over and

00:49:17.000 --> 00:49:20.839
over and over again how many times would

00:49:18.319 --> 00:49:22.720
you need until you get it right and so

00:49:20.839 --> 00:49:25.119
here like if the actual answer was start

00:49:22.720 --> 00:49:27.480
the perplexity would be 4.66 so we'd

00:49:25.119 --> 00:49:30.240
expect language model to get it in uh

00:49:27.480 --> 00:49:34.400
four guesses uh between four and five

00:49:30.240 --> 00:49:38.559
guesses and you guys all did six so you

00:49:34.400 --> 00:49:41.599
lose um so uh another important thing to

00:49:38.559 --> 00:49:42.799
mention is evaluation in vocabulary uh

00:49:41.599 --> 00:49:44.880
so for fair

00:49:42.799 --> 00:49:47.319
comparison um make sure that the

00:49:44.880 --> 00:49:49.559
denominator is the same so uh if you're

00:49:47.319 --> 00:49:51.559
calculating the perplexity make sure

00:49:49.559 --> 00:49:53.359
that you're dividing by the same number

00:49:51.559 --> 00:49:55.799
uh every time you're dividing by words

00:49:53.359 --> 00:49:58.520
if it's uh the other paper or whatever

00:49:55.799 --> 00:50:00.680
is dividing by words or like let's say

00:49:58.520 --> 00:50:02.160
you're comparing llama to gp2 they have

00:50:00.680 --> 00:50:04.880
different tokenizers so they'll have

00:50:02.160 --> 00:50:07.040
different numbers of tokens so comparing

00:50:04.880 --> 00:50:10.880
uh with different denominators is not uh

00:50:07.040 --> 00:50:12.440
not fair um if you're allowing unknown

00:50:10.880 --> 00:50:14.559
words or characters so if you allow the

00:50:12.440 --> 00:50:17.640
model to not predict

00:50:14.559 --> 00:50:19.119
any token then you need to be fair about

00:50:17.640 --> 00:50:22.040
that

00:50:19.119 --> 00:50:25.160
too um so I'd like to go into a few

00:50:22.040 --> 00:50:27.960
Alternatives these are very similar to

00:50:25.160 --> 00:50:29.400
the Network classifiers and bag of words

00:50:27.960 --> 00:50:30.680
classifiers that I talked about before

00:50:29.400 --> 00:50:32.480
so I'm going to go through them rather

00:50:30.680 --> 00:50:35.480
quickly because I think you should get

00:50:32.480 --> 00:50:38.119
the basic idea but basically the

00:50:35.480 --> 00:50:40.000
alternative is uh featued models so we

00:50:38.119 --> 00:50:42.559
calculate features of to account based

00:50:40.000 --> 00:50:44.599
models as featued models so we calculate

00:50:42.559 --> 00:50:46.880
features of the context and based on the

00:50:44.599 --> 00:50:48.280
features calculate probabilities

00:50:46.880 --> 00:50:50.480
optimize the feature weights using

00:50:48.280 --> 00:50:53.839
gradient descent uh

00:50:50.480 --> 00:50:56.119
Etc and so for example if we have uh

00:50:53.839 --> 00:50:58.880
input giving a

00:50:56.119 --> 00:51:02.960
uh we calculate features so um we might

00:50:58.880 --> 00:51:05.400
look up uh the word identity of the two

00:51:02.960 --> 00:51:08.240
previous words look up the word identity

00:51:05.400 --> 00:51:11.000
of the word uh directly previous add a

00:51:08.240 --> 00:51:13.480
bias add them all together get scores

00:51:11.000 --> 00:51:14.960
and calculate probabilities where each

00:51:13.480 --> 00:51:16.920
Vector is the size of the output

00:51:14.960 --> 00:51:19.680
vocabulary and feature weights are

00:51:16.920 --> 00:51:21.799
optimized using SGD so this is basically

00:51:19.680 --> 00:51:24.240
a bag of words classifier but it's a

00:51:21.799 --> 00:51:27.200
multiclass bag of words classifier over

00:51:24.240 --> 00:51:28.960
the next token so it's very similar to

00:51:27.200 --> 00:51:30.839
our classification task before except

00:51:28.960 --> 00:51:33.160
now instead of having two classes we

00:51:30.839 --> 00:51:36.280
have you know 10,000 classes or 100,000

00:51:33.160 --> 00:51:38.480
classes oh yeah sorry very quick aside

00:51:36.280 --> 00:51:40.280
um these were actually invented by Rony

00:51:38.480 --> 00:51:41.440
Rosenfeld who's the head of the machine

00:51:40.280 --> 00:51:45.119
learning department at the end the

00:51:41.440 --> 00:51:47.799
machine learning Department uh so um 27

00:51:45.119 --> 00:51:50.760
years ago I guess so he has even more

00:51:47.799 --> 00:51:52.680
experience large language modeling than

00:51:50.760 --> 00:51:55.880
um

00:51:52.680 --> 00:51:58.599
cool so um the one difference with a bag

00:51:55.880 --> 00:52:02.119
of words classifier is

00:51:58.599 --> 00:52:05.480
um we we have

00:52:02.119 --> 00:52:07.640
biases um and we have the probability

00:52:05.480 --> 00:52:09.400
Vector given the previous word but

00:52:07.640 --> 00:52:11.720
instead of using a bag of words this

00:52:09.400 --> 00:52:15.440
actually is using uh How likely is it

00:52:11.720 --> 00:52:16.960
giving given two words previous so uh

00:52:15.440 --> 00:52:18.040
the feature design would be a little bit

00:52:16.960 --> 00:52:19.119
different and that would give you a

00:52:18.040 --> 00:52:22.920
total

00:52:19.119 --> 00:52:24.359
score um as a reminder uh last time we

00:52:22.920 --> 00:52:26.440
did a training algorithm where we

00:52:24.359 --> 00:52:27.480
calculated gradients loss function with

00:52:26.440 --> 00:52:29.960
respect to the

00:52:27.480 --> 00:52:32.319
parameters and uh we can use the chain

00:52:29.960 --> 00:52:33.839
Rule and back propagation and updates to

00:52:32.319 --> 00:52:36.400
move in the direction that increases

00:52:33.839 --> 00:52:39.040
enough so nothing extremely different

00:52:36.400 --> 00:52:42.640
from what we had for our

00:52:39.040 --> 00:52:44.240
B um similarly this solves some problems

00:52:42.640 --> 00:52:47.240
so this didn't solve the problem of

00:52:44.240 --> 00:52:49.119
sharing strength among similar words it

00:52:47.240 --> 00:52:50.839
did solve the problem of conditioning on

00:52:49.119 --> 00:52:52.839
context with intervening words because

00:52:50.839 --> 00:52:56.920
now we can condition directly on Doctor

00:52:52.839 --> 00:52:59.680
without having to um combine with

00:52:56.920 --> 00:53:01.200
gitrid um and it doesn't necessarily

00:52:59.680 --> 00:53:03.480
handle longdistance dependencies because

00:53:01.200 --> 00:53:05.240
we're still limited in our context with

00:53:03.480 --> 00:53:09.079
the model I just

00:53:05.240 --> 00:53:11.920
described so um if we so sorry back to

00:53:09.079 --> 00:53:13.480
neural networks is what I should say um

00:53:11.920 --> 00:53:15.160
so if we have a feedforward neural

00:53:13.480 --> 00:53:18.480
network language model the way this

00:53:15.160 --> 00:53:20.400
could work is instead of looking up

00:53:18.480 --> 00:53:23.079
discrete features uh like we had in a

00:53:20.400 --> 00:53:25.960
bag of words model uh we would look up

00:53:23.079 --> 00:53:27.400
dents embeddings and so we concatenate

00:53:25.960 --> 00:53:29.359
together these dense

00:53:27.400 --> 00:53:32.319
embeddings and based on the dense

00:53:29.359 --> 00:53:34.599
embeddings uh we do some sort of uh

00:53:32.319 --> 00:53:36.079
intermediate layer transforms to extract

00:53:34.599 --> 00:53:37.200
features like we did for our neural

00:53:36.079 --> 00:53:39.359
network based

00:53:37.200 --> 00:53:41.520
classifier um we multiply this by

00:53:39.359 --> 00:53:43.559
weights uh we have a bias and we

00:53:41.520 --> 00:53:46.559
calculate

00:53:43.559 --> 00:53:49.200
scores and uh then we take a soft Max to

00:53:46.559 --> 00:53:49.200
do

00:53:50.400 --> 00:53:55.799
classification so um this can calculate

00:53:53.359 --> 00:53:58.000
combination features uh like we we also

00:53:55.799 --> 00:54:02.280
used in our uh neural network based

00:53:58.000 --> 00:54:04.119
classifiers so um this could uh give us

00:54:02.280 --> 00:54:05.760
a positive number for example if the

00:54:04.119 --> 00:54:07.760
previous word is a determiner and the

00:54:05.760 --> 00:54:10.440
second previous word is a verb so that

00:54:07.760 --> 00:54:14.520
would be like uh in giving and then that

00:54:10.440 --> 00:54:14.520
would allow us upway to that particular

00:54:15.000 --> 00:54:19.559
examples um so this allows us to share

00:54:17.640 --> 00:54:21.640
strength in various places in our model

00:54:19.559 --> 00:54:23.520
which was also You Know instrumental in

00:54:21.640 --> 00:54:25.599
making our our neural network

00:54:23.520 --> 00:54:28.000
classifiers work for similar work and

00:54:25.599 --> 00:54:30.119
stuff and so these would be word

00:54:28.000 --> 00:54:32.160
embeddings so similar words get similar

00:54:30.119 --> 00:54:35.079
embeddings another really important

00:54:32.160 --> 00:54:38.480
thing is uh similar output words also

00:54:35.079 --> 00:54:41.839
get similar rows in The softmax Matrix

00:54:38.480 --> 00:54:44.440
and so here remember if you remember

00:54:41.839 --> 00:54:48.240
from last class this was a big Matrix

00:54:44.440 --> 00:54:50.400
where the size of the Matrix was the

00:54:48.240 --> 00:54:53.319
number of vocabulary items times the

00:54:50.400 --> 00:54:55.920
size of a word embedding this is also a

00:54:53.319 --> 00:54:58.319
matrix where this is

00:54:55.920 --> 00:55:02.200
the number of vocabulary items times the

00:54:58.319 --> 00:55:04.160
size of a context embedding gr and so

00:55:02.200 --> 00:55:06.160
these will also be similar because words

00:55:04.160 --> 00:55:08.280
that appear in similar contexts will

00:55:06.160 --> 00:55:11.920
also you know want similar embeddings so

00:55:08.280 --> 00:55:15.119
they get uploaded in at the same

00:55:11.920 --> 00:55:17.119
time and similar hidden States will have

00:55:15.119 --> 00:55:19.799
similar context so ideally like if you

00:55:17.119 --> 00:55:20.920
have giving a or delivering a or

00:55:19.799 --> 00:55:22.680
something like that those would be

00:55:20.920 --> 00:55:27.000
similar contexts so they would get

00:55:22.680 --> 00:55:27.000
similar purple embeddings out out of the

00:55:28.440 --> 00:55:31.599
so one trick that's widely used in

00:55:30.200 --> 00:55:34.960
language model that further takes

00:55:31.599 --> 00:55:38.799
advantage of this is uh tying

00:55:34.960 --> 00:55:44.160
embeddings so here what this does is

00:55:38.799 --> 00:55:48.280
sharing parameters between this um

00:55:44.160 --> 00:55:49.920
lookup Matrix here and this uh Matrix

00:55:48.280 --> 00:55:51.119
over here that we use for calculating

00:55:49.920 --> 00:55:56.200
the

00:55:51.119 --> 00:55:58.839
softmax and um the reason why this is

00:55:56.200 --> 00:56:00.559
useful is twofold number one it gives

00:55:58.839 --> 00:56:02.079
you essentially more training data to

00:56:00.559 --> 00:56:04.440
learn these embeddings because instead

00:56:02.079 --> 00:56:05.799
of learning the embeddings whenever a

00:56:04.440 --> 00:56:08.520
word is in

00:56:05.799 --> 00:56:10.599
context separately from learning the

00:56:08.520 --> 00:56:13.520
embeddings whenever a word is predicted

00:56:10.599 --> 00:56:15.480
you learn the the same embedding Matrix

00:56:13.520 --> 00:56:19.319
whenever the word is in the context or

00:56:15.480 --> 00:56:21.520
whatever it's predicted and so um that

00:56:19.319 --> 00:56:24.119
makes it more accurate to learn these uh

00:56:21.520 --> 00:56:26.960
embeddings well another thing is the

00:56:24.119 --> 00:56:31.119
embedding mat can actually be very large

00:56:26.960 --> 00:56:34.920
so like let's say we have aab of

00:56:31.119 --> 00:56:37.520
10 100,000 and we have an embedding a

00:56:34.920 --> 00:56:40.799
word embedding size of like 512 or

00:56:37.520 --> 00:56:45.319
something like that

00:56:40.799 --> 00:56:45.319
that's um 51 million

00:56:46.839 --> 00:56:52.440
parameters um and this doesn't sound

00:56:49.559 --> 00:56:55.520
like a lot of parameters at first but it

00:56:52.440 --> 00:56:57.880
actually is a lot to learn when um

00:56:55.520 --> 00:57:01.000
these get updated relatively

00:56:57.880 --> 00:57:03.400
infrequently uh because

00:57:01.000 --> 00:57:06.079
um these get updated relatively

00:57:03.400 --> 00:57:07.960
infrequently because they only are

00:57:06.079 --> 00:57:09.559
updated whenever that word or token

00:57:07.960 --> 00:57:12.319
actually appears in your training data

00:57:09.559 --> 00:57:14.119
so um this can be a good thing for

00:57:12.319 --> 00:57:16.319
parameter savings parameter efficiency

00:57:14.119 --> 00:57:16.319
as

00:57:16.440 --> 00:57:22.520
well um so this uh solves most of the

00:57:19.599 --> 00:57:24.319
problems here um but it doesn't solve

00:57:22.520 --> 00:57:26.839
the problem of longdistance dependencies

00:57:24.319 --> 00:57:29.839
because still limited by the overall

00:57:26.839 --> 00:57:31.359
length of uh the context that we're

00:57:29.839 --> 00:57:32.520
concatenating together here sure we

00:57:31.359 --> 00:57:35.760
could make that longer but that would

00:57:32.520 --> 00:57:37.200
make our model larger and um and bring

00:57:35.760 --> 00:57:39.720
various

00:57:37.200 --> 00:57:42.520
issues and so what I'm going to talk

00:57:39.720 --> 00:57:44.599
about in on thur day is how we solve

00:57:42.520 --> 00:57:47.559
this problem of modeling long contexts

00:57:44.599 --> 00:57:49.720
so how do we um build recurrent neural

00:57:47.559 --> 00:57:52.559
networks uh how do we build

00:57:49.720 --> 00:57:54.960
convolutional uh convolutional networks

00:57:52.559 --> 00:57:57.520
or how do we build attention based

00:57:54.960 --> 00:58:00.720
Transformer models and these are all

00:57:57.520 --> 00:58:02.119
options that are used um Transformers

00:58:00.720 --> 00:58:04.359
are kind of

00:58:02.119 --> 00:58:06.039
the the main thing that people use

00:58:04.359 --> 00:58:08.400
nowadays but there's a lot of versions

00:58:06.039 --> 00:58:11.880
of Transformers that borrow ideas from

00:58:08.400 --> 00:58:14.960
recurrent uh and convolutional models

00:58:11.880 --> 00:58:17.359
um recently a lot of long context models

00:58:14.960 --> 00:58:19.440
us use ideas from recurrent networks and

00:58:17.359 --> 00:58:22.160
a lot of for example speech models or

00:58:19.440 --> 00:58:24.160
things like or image models use ideas

00:58:22.160 --> 00:58:25.920
from convolutional networks so I think

00:58:24.160 --> 00:58:28.760
learning all but at the same time is a

00:58:25.920 --> 00:58:32.160
good idea in comparing

00:58:28.760 --> 00:58:34.319
them cool uh any any questions about

00:58:32.160 --> 00:58:35.799
this part I went through this kind of

00:58:34.319 --> 00:58:37.319
quickly because it's pretty similar to

00:58:35.799 --> 00:58:40.079
the the classification stuff that we

00:58:37.319 --> 00:58:42.680
covered last time but uh any any things

00:58:40.079 --> 00:58:42.680
that people want to

00:58:43.880 --> 00:58:49.039
ask okay so next I'm going to talk about

00:58:46.839 --> 00:58:51.559
a few other desiderata of language

00:58:49.039 --> 00:58:53.039
models so the next one is really really

00:58:51.559 --> 00:58:55.640
important it's a concept I want

00:58:53.039 --> 00:58:57.640
everybody to know I actually

00:58:55.640 --> 00:58:59.520
taught this informally up until this

00:58:57.640 --> 00:59:02.039
class but now I I actually made slides

00:58:59.520 --> 00:59:05.079
for it starting this time which is

00:59:02.039 --> 00:59:07.240
calibration so the idea of calibration

00:59:05.079 --> 00:59:10.200
is that the model quote unquote knows

00:59:07.240 --> 00:59:14.559
when it knows or the the fact that it is

00:59:10.200 --> 00:59:17.480
able to provide a a good answer um uh

00:59:14.559 --> 00:59:21.640
provide a good confidence in its answer

00:59:17.480 --> 00:59:23.640
and more formally this can be specified

00:59:21.640 --> 00:59:25.240
as

00:59:23.640 --> 00:59:27.799
the

00:59:25.240 --> 00:59:29.200
feature that the model probability of

00:59:27.799 --> 00:59:33.119
the answer matches the actual

00:59:29.200 --> 00:59:37.319
probability of getting it right um and

00:59:33.119 --> 00:59:37.319
so what this means

00:59:41.960 --> 00:59:47.480
is the

00:59:44.240 --> 00:59:51.839
probability of the

00:59:47.480 --> 00:59:51.839
answer um is

00:59:52.720 --> 00:59:59.880
correct given the fact that

00:59:56.319 --> 00:59:59.880
the model

01:00:00.160 --> 01:00:07.440
probability is equal to

01:00:03.640 --> 01:00:07.440
P is equal to

01:00:08.559 --> 01:00:12.760
ke

01:00:10.480 --> 01:00:15.319
so I know this is a little bit hard to

01:00:12.760 --> 01:00:18.240
parse I it always took me like a few

01:00:15.319 --> 01:00:21.720
seconds to parse before I uh like when I

01:00:18.240 --> 01:00:25.160
looked at it but basically if the model

01:00:21.720 --> 01:00:26.920
if the model says the probability of it

01:00:25.160 --> 01:00:29.440
being correct is

01:00:26.920 --> 01:00:33.559
0.7 then the probability that the answer

01:00:29.440 --> 01:00:35.960
is correct is actually 0.7 so um you

01:00:33.559 --> 01:00:41.520
know if it says uh the probability is

01:00:35.960 --> 01:00:41.520
0.7 100 times then it will be right 70

01:00:43.640 --> 01:00:52.160
times and so the way we formalize this

01:00:48.039 --> 01:00:55.200
um is is by this uh it was proposed by

01:00:52.160 --> 01:00:57.760
this seminal paper by gu it all in

01:00:55.200 --> 01:01:00.319
2017

01:00:57.760 --> 01:01:03.319
and

01:01:00.319 --> 01:01:05.520
unfortunately this data itself is hard

01:01:03.319 --> 01:01:08.119
to collect

01:01:05.520 --> 01:01:11.200
because the model probability is always

01:01:08.119 --> 01:01:13.359
different right and so if the model

01:01:11.200 --> 01:01:15.359
probability is like if the model

01:01:13.359 --> 01:01:20.480
probability was actually 0.7 that'd be

01:01:15.359 --> 01:01:22.000
nice but actually it's 0.793 to 6 8 5

01:01:20.480 --> 01:01:24.599
and you never get another example where

01:01:22.000 --> 01:01:26.319
the probability is exactly the same so

01:01:24.599 --> 01:01:28.280
what we do instead is we divide the

01:01:26.319 --> 01:01:30.240
model probabilities into buckets so we

01:01:28.280 --> 01:01:32.880
say the model probability is between 0

01:01:30.240 --> 01:01:36.599
and 0.1 we say the model probability is

01:01:32.880 --> 01:01:40.319
between 0.1 and 0.2 0.2 and 0.3 so we

01:01:36.599 --> 01:01:44.599
create buckets like this like these and

01:01:40.319 --> 01:01:46.520
then we looked at the model confidence

01:01:44.599 --> 01:01:52.839
the average model confidence within that

01:01:46.520 --> 01:01:55.000
bucket so maybe uh between 0.1 and 0 uh

01:01:52.839 --> 01:01:58.000
between 0 and 0.1 the model confidence

01:01:55.000 --> 01:02:00.920
on average is 0 055 or something like

01:01:58.000 --> 01:02:02.640
that so that would be this T here and

01:02:00.920 --> 01:02:05.079
then the accuracy is how often did it

01:02:02.640 --> 01:02:06.680
actually get a correct and this can be

01:02:05.079 --> 01:02:09.720
plotted in this thing called a

01:02:06.680 --> 01:02:15.039
reliability diagram and the reliability

01:02:09.720 --> 01:02:17.599
diagram basically um the the

01:02:15.039 --> 01:02:20.359
outputs uh

01:02:17.599 --> 01:02:26.359
here so this is

01:02:20.359 --> 01:02:26.359
um the this is the model

01:02:27.520 --> 01:02:34.119
yeah I think the red is the model

01:02:30.760 --> 01:02:36.400
um expected probability and then the

01:02:34.119 --> 01:02:40.559
blue uh the blue is the actual

01:02:36.400 --> 01:02:43.240
probability and then um

01:02:40.559 --> 01:02:45.160
the difference between the expected and

01:02:43.240 --> 01:02:47.160
the actual probability is kind of like

01:02:45.160 --> 01:02:48.359
the penalty there is how how poorly

01:02:47.160 --> 01:02:52.000
calibrated

01:02:48.359 --> 01:02:55.880
the and one really important thing to

01:02:52.000 --> 01:02:58.440
know is that calibration in accuracy are

01:02:55.880 --> 01:03:00.599
not necessarily they don't go hand inand

01:02:58.440 --> 01:03:02.359
uh they do to some extent but they don't

01:03:00.599 --> 01:03:06.440
uh they don't necessarily go hand in

01:03:02.359 --> 01:03:06.440
hand and

01:03:07.200 --> 01:03:14.319
the example on the left is a a bad model

01:03:11.200 --> 01:03:16.279
but a well calibrated so its accuracy is

01:03:14.319 --> 01:03:18.720
uh its error is

01:03:16.279 --> 01:03:20.000
44.9% um but it's well calibrated as you

01:03:18.720 --> 01:03:21.440
can see like when it says it knows the

01:03:20.000 --> 01:03:23.880
answer it knows the answer when it

01:03:21.440 --> 01:03:27.799
doesn't answer does this model on the

01:03:23.880 --> 01:03:30.000
other hand has better erir and um but

01:03:27.799 --> 01:03:31.880
worse calibration so the reason why is

01:03:30.000 --> 01:03:36.680
the model is very very confident all the

01:03:31.880 --> 01:03:39.640
time and usually what happens is um

01:03:36.680 --> 01:03:41.200
models that overfit to the data

01:03:39.640 --> 01:03:43.359
especially when you do early stopping on

01:03:41.200 --> 01:03:44.760
something like accuracy uh when you stop

01:03:43.359 --> 01:03:47.279
the training on something like accuracy

01:03:44.760 --> 01:03:49.960
will become very overconfident and uh

01:03:47.279 --> 01:03:52.599
give confidence estimates um that are in

01:03:49.960 --> 01:03:54.000
cor like this so this is important to

01:03:52.599 --> 01:03:56.079
know and the reason why it's important

01:03:54.000 --> 01:03:58.000
to know is actually because you know

01:03:56.079 --> 01:04:00.960
models are very good at making up things

01:03:58.000 --> 01:04:02.359
that aren't actually correct nowadays um

01:04:00.960 --> 01:04:04.920
and but if you have a really well

01:04:02.359 --> 01:04:07.760
calibrated model you could at least say

01:04:04.920 --> 01:04:09.920
with what confidence you have this

01:04:07.760 --> 01:04:12.760
working so how do you calculate the

01:04:09.920 --> 01:04:14.160
probability of an answer so H yeah sorry

01:04:12.760 --> 01:04:17.599
uh yes

01:04:14.160 --> 01:04:17.599
yes yeah please

01:04:17.799 --> 01:04:26.559
go the probability of percent or

01:04:23.200 --> 01:04:28.039
percent um usually this would be for a

01:04:26.559 --> 01:04:29.599
generated output because you want to

01:04:28.039 --> 01:04:32.559
know the the probability that the

01:04:29.599 --> 01:04:32.559
generated output is

01:04:53.160 --> 01:04:56.160
cor

01:05:01.079 --> 01:05:06.319
great that's what I'm about to talk

01:05:03.000 --> 01:05:07.839
about so perfect perfect question um so

01:05:06.319 --> 01:05:10.160
how do we calculate the answer

01:05:07.839 --> 01:05:13.279
probability or um how do we calculate

01:05:10.160 --> 01:05:15.039
the confidence in an answer um we're

01:05:13.279 --> 01:05:18.319
actually going to go into more detail

01:05:15.039 --> 01:05:20.760
about this um in a a later class but the

01:05:18.319 --> 01:05:23.200
first thing is probability of the answer

01:05:20.760 --> 01:05:25.799
and this is easy when there's a single

01:05:23.200 --> 01:05:29.079
answer um like if there's only one

01:05:25.799 --> 01:05:31.839
correct answer and you want your model

01:05:29.079 --> 01:05:34.160
to be solving math problems and you want

01:05:31.839 --> 01:05:38.319
it to return only the answer and nothing

01:05:34.160 --> 01:05:40.760
else if it returns anything else like it

01:05:38.319 --> 01:05:44.920
won't work then you can just use the

01:05:40.760 --> 01:05:47.119
probability of the answer but what

01:05:44.920 --> 01:05:49.559
if

01:05:47.119 --> 01:05:52.000
um what if there are multiple acceptable

01:05:49.559 --> 01:05:54.680
answers um and maybe a perfect example

01:05:52.000 --> 01:06:02.240
of that is like where is CMU located

01:05:54.680 --> 01:06:04.400
or um uh where where are we right now um

01:06:02.240 --> 01:06:06.960
if the answer is where are we right

01:06:04.400 --> 01:06:08.880
now um could be

01:06:06.960 --> 01:06:12.880
Pittsburgh could be

01:06:08.880 --> 01:06:12.880
CMU could be carnegy

01:06:16.200 --> 01:06:24.440
melon could be other other things like

01:06:18.760 --> 01:06:26.760
this right um and so another way that

01:06:24.440 --> 01:06:28.319
you can calculate the confidence is

01:06:26.760 --> 01:06:31.240
calculating the probability of the

01:06:28.319 --> 01:06:33.680
answer plus uh you know paraphrases of

01:06:31.240 --> 01:06:35.799
the answer or other uh other things like

01:06:33.680 --> 01:06:37.680
this and so then you would just sum the

01:06:35.799 --> 01:06:38.839
probability over all the qu like

01:06:37.680 --> 01:06:41.680
acceptable

01:06:38.839 --> 01:06:45.359
answers

01:06:41.680 --> 01:06:47.680
um another thing that you can do is um

01:06:45.359 --> 01:06:49.279
sample multiple outputs and count the

01:06:47.680 --> 01:06:51.000
number of times you get a particular

01:06:49.279 --> 01:06:54.440
answer this doesn't solve the problem of

01:06:51.000 --> 01:06:58.119
paraphrasing ex paraphrases existing but

01:06:54.440 --> 01:06:59.880
it does solve the problem of uh it does

01:06:58.119 --> 01:07:01.480
solve two problems sometimes there are

01:06:59.880 --> 01:07:05.240
language models where you can't get

01:07:01.480 --> 01:07:06.640
probabilities out of them um this is not

01:07:05.240 --> 01:07:08.680
so much of a problem anymore with the

01:07:06.640 --> 01:07:11.240
GPT models because they're reintroducing

01:07:08.680 --> 01:07:12.440
the ability to get probabilities but um

01:07:11.240 --> 01:07:13.720
there are some models where you can just

01:07:12.440 --> 01:07:16.279
sample from them and you can't get

01:07:13.720 --> 01:07:18.680
probabilities out but also more

01:07:16.279 --> 01:07:21.039
importantly um sometimes when you're

01:07:18.680 --> 01:07:23.000
using things like uh Chain of Thought

01:07:21.039 --> 01:07:26.520
reasoning which I'll talk about in more

01:07:23.000 --> 01:07:29.839
detail but basically it's like um please

01:07:26.520 --> 01:07:31.480
solve this math problem and explain

01:07:29.839 --> 01:07:33.480
explain your solution and then if it

01:07:31.480 --> 01:07:35.119
will do that it will generate you know a

01:07:33.480 --> 01:07:36.279
really long explanation of how it got to

01:07:35.119 --> 01:07:40.119
the solution and then it will give you

01:07:36.279 --> 01:07:41.640
the answer at the very end and so then

01:07:40.119 --> 01:07:44.960
you can't calculate the probability of

01:07:41.640 --> 01:07:47.720
the actual like answer itself because

01:07:44.960 --> 01:07:49.359
there's this long reasoning chain in

01:07:47.720 --> 01:07:51.960
between and you have like all these

01:07:49.359 --> 01:07:53.559
other all that other text there but what

01:07:51.960 --> 01:07:55.480
you can do is you can sample those

01:07:53.559 --> 01:07:56.920
reasoning chains 100 times and then see

01:07:55.480 --> 01:07:59.599
how many times you got a particular

01:07:56.920 --> 01:08:02.960
answer and that's actually a pretty um a

01:07:59.599 --> 01:08:06.079
Prett pretty reasonable way of uh

01:08:02.960 --> 01:08:09.000
getting a have

01:08:06.079 --> 01:08:11.200
yet this is my favorite one I I love how

01:08:09.000 --> 01:08:12.880
we can do this now it's just absolutely

01:08:11.200 --> 01:08:16.480
ridiculous but you could ask the model

01:08:12.880 --> 01:08:20.279
how confident it is and um it sometimes

01:08:16.480 --> 01:08:22.359
gives you a reasonable uh a reasonable

01:08:20.279 --> 01:08:24.600
answer um there's a really nice

01:08:22.359 --> 01:08:26.400
comparison of different methods uh in

01:08:24.600 --> 01:08:29.679
this paper which is also on on the

01:08:26.400 --> 01:08:31.960
website and basically long story short

01:08:29.679 --> 01:08:34.000
the conclusion from this paper is the

01:08:31.960 --> 01:08:35.640
sampling multiple outputs one is the

01:08:34.000 --> 01:08:36.839
best way to do it if you can't directly

01:08:35.640 --> 01:08:39.520
calculate

01:08:36.839 --> 01:08:41.359
probabilities um another thing that I'd

01:08:39.520 --> 01:08:42.600
like people to pay very close attention

01:08:41.359 --> 01:08:45.040
to is in the

01:08:42.600 --> 01:08:46.480
Generation Um in the generation class

01:08:45.040 --> 01:08:49.600
we're going to be talking about minimum

01:08:46.480 --> 01:08:52.600
based risk which is a Criterion for

01:08:49.600 --> 01:08:54.719
deciding how risky an output is and it's

01:08:52.600 --> 01:08:56.199
actually a really good uh confidence

01:08:54.719 --> 01:08:58.000
metric as well but I'm going to leave

01:08:56.199 --> 01:08:59.440
that till when we discuss it more detail

01:08:58.000 --> 01:09:02.759
with

01:08:59.440 --> 01:09:05.359
it um any any questions

01:09:02.759 --> 01:09:08.440
here okay

01:09:05.359 --> 01:09:10.480
cool um so the other Criterion uh this

01:09:08.440 --> 01:09:12.520
is just yet another Criterion that we

01:09:10.480 --> 01:09:15.239
would like language models to be good at

01:09:12.520 --> 01:09:17.600
um its efficiency and so basically the

01:09:15.239 --> 01:09:21.920
model is easy to run on limited Hardware

01:09:17.600 --> 01:09:25.400
by some you know uh metric of easy and

01:09:21.920 --> 01:09:29.319
some metrics that we like to talk about

01:09:25.400 --> 01:09:32.400
our parameter account so often you will

01:09:29.319 --> 01:09:34.239
see oh this is the best model under

01:09:32.400 --> 01:09:35.520
three billion parameters or this is the

01:09:34.239 --> 01:09:37.960
best model under seven billion

01:09:35.520 --> 01:09:39.600
parameters or um we trained a model with

01:09:37.960 --> 01:09:42.159
one trillion parameters or something

01:09:39.600 --> 01:09:44.719
like that you know

01:09:42.159 --> 01:09:46.839
uh the thing is parameter count doesn't

01:09:44.719 --> 01:09:49.640
really mean that much um from the point

01:09:46.839 --> 01:09:52.839
of view of like ease of using the model

01:09:49.640 --> 01:09:54.400
um unless you also think about other uh

01:09:52.839 --> 01:09:56.480
you know deser

01:09:54.400 --> 01:09:58.840
like just to give one example this is a

01:09:56.480 --> 01:10:00.880
parameter count um let's say you have a

01:09:58.840 --> 01:10:02.960
parameter count of 7 billion is that 7

01:10:00.880 --> 01:10:05.719
billion parameters at 32-bit Precision

01:10:02.960 --> 01:10:07.800
or is that 7 billion parameters at 4bit

01:10:05.719 --> 01:10:09.400
Precision um will make a huge difference

01:10:07.800 --> 01:10:12.960
in your memory footprint your speed

01:10:09.400 --> 01:10:14.920
other things like that um so some of the

01:10:12.960 --> 01:10:18.040
things that are more direct with respect

01:10:14.920 --> 01:10:19.800
to efficiency are memory usage um and

01:10:18.040 --> 01:10:22.440
there's two varieties of memory usage

01:10:19.800 --> 01:10:24.280
one is model uh model only memory usage

01:10:22.440 --> 01:10:27.120
so when you load loaded the model into

01:10:24.280 --> 01:10:29.120
memory uh how much space does it take

01:10:27.120 --> 01:10:31.159
and also Peak memory consumption when

01:10:29.120 --> 01:10:33.159
you run have run the model over a

01:10:31.159 --> 01:10:35.920
sequence of a certain length how much is

01:10:33.159 --> 01:10:40.040
it going to P so that's another

01:10:35.920 --> 01:10:43.000
thing another thing is latency um and

01:10:40.040 --> 01:10:46.440
with respect to latency this can be

01:10:43.000 --> 01:10:49.440
either how long does it take to start

01:10:46.440 --> 01:10:52.080
outputting the first token um and how

01:10:49.440 --> 01:10:54.840
long does it take to uh finish

01:10:52.080 --> 01:10:59.480
outputting uh a generation of a certain

01:10:54.840 --> 01:11:01.199
length and the first will have more to

01:10:59.480 --> 01:11:04.960
do with how long does it take to encode

01:11:01.199 --> 01:11:06.480
a sequence um which is usually faster

01:11:04.960 --> 01:11:09.080
than how long does it take to generate a

01:11:06.480 --> 01:11:11.360
sequence so this will have to do with

01:11:09.080 --> 01:11:13.000
like encoding time this will require

01:11:11.360 --> 01:11:15.880
encoding time of course but it will also

01:11:13.000 --> 01:11:15.880
require generation

01:11:16.280 --> 01:11:21.840
time also throughput so you know how

01:11:19.239 --> 01:11:23.679
much um how many sentences can you

01:11:21.840 --> 01:11:25.400
process in a certain amount of time so

01:11:23.679 --> 01:11:26.480
of these are kind of desad that you you

01:11:25.400 --> 01:11:29.000
would

01:11:26.480 --> 01:11:30.280
say um we're going to be talking about

01:11:29.000 --> 01:11:31.920
this more in the distillation and

01:11:30.280 --> 01:11:33.199
compression and generation algorithms

01:11:31.920 --> 01:11:35.640
classes so I won't go into a whole lot

01:11:33.199 --> 01:11:36.840
of detail about this but um it's just

01:11:35.640 --> 01:11:39.960
another thing that we want to be

01:11:36.840 --> 01:11:43.560
thinking about in addition to

01:11:39.960 --> 01:11:45.360
complexity um but since I'm I'm on the

01:11:43.560 --> 01:11:47.800
topic of efficiency I would like to talk

01:11:45.360 --> 01:11:49.480
just a little bit about it um in terms

01:11:47.800 --> 01:11:51.000
of especially things that will be useful

01:11:49.480 --> 01:11:53.600
for implementing your first

01:11:51.000 --> 01:11:55.840
assignment and uh one thing that every

01:11:53.600 --> 01:11:58.639
body should know about um if you've done

01:11:55.840 --> 01:11:59.920
any like deep learning with pytorch or

01:11:58.639 --> 01:12:02.639
something like this you already know

01:11:59.920 --> 01:12:05.880
about this probably but uh I think it's

01:12:02.639 --> 01:12:08.760
worth mentioning but basically mini

01:12:05.880 --> 01:12:12.120
batching or batching uh is uh very

01:12:08.760 --> 01:12:15.320
useful and the basic idea behind it is

01:12:12.120 --> 01:12:17.560
that on Modern Hardware if you do many

01:12:15.320 --> 01:12:20.520
of the same operations at once it's much

01:12:17.560 --> 01:12:24.320
faster than doing um

01:12:20.520 --> 01:12:25.480
like uh operations executively and

01:12:24.320 --> 01:12:27.280
that's especially the case if you're

01:12:25.480 --> 01:12:30.520
programming in an extremely slow

01:12:27.280 --> 01:12:33.239
programming language like python um I

01:12:30.520 --> 01:12:37.239
love python but it's slow I mean like

01:12:33.239 --> 01:12:38.719
there's no argument about that um and so

01:12:37.239 --> 01:12:40.520
what mini batching does is it combines

01:12:38.719 --> 01:12:43.600
together smaller operations into one big

01:12:40.520 --> 01:12:47.480
one and the basic idea uh for example if

01:12:43.600 --> 01:12:51.679
we want to calculate our um our linear

01:12:47.480 --> 01:12:56.560
layer with a t uh nonlinearity after it

01:12:51.679 --> 01:12:59.760
we will take several inputs X1 X2 X3

01:12:56.560 --> 01:13:02.040
concatenate them together and do a

01:12:59.760 --> 01:13:04.600
Matrix Matrix multiply instead of doing

01:13:02.040 --> 01:13:07.960
three Vector Matrix

01:13:04.600 --> 01:13:09.239
multiplies and so what we do is we take

01:13:07.960 --> 01:13:11.280
a whole bunch of examples we take like

01:13:09.239 --> 01:13:13.840
64 examples or something like that and

01:13:11.280 --> 01:13:18.000
we combine them together and calculate

01:13:13.840 --> 01:13:21.280
out thingsit one thing to know is that

01:13:18.000 --> 01:13:22.560
if you're working with sentences there's

01:13:21.280 --> 01:13:24.719
different ways you can calculate the

01:13:22.560 --> 01:13:27.360
size of your mini

01:13:24.719 --> 01:13:28.880
normally nowadays the thing that people

01:13:27.360 --> 01:13:30.400
do and the thing that I recommend is to

01:13:28.880 --> 01:13:31.679
calculate the size of your mini batches

01:13:30.400 --> 01:13:33.639
based on the number of tokens in the

01:13:31.679 --> 01:13:35.840
mini batch it used to be that you would

01:13:33.639 --> 01:13:39.719
do it based on the number of sequences

01:13:35.840 --> 01:13:43.800
but the the problem is um one like 50

01:13:39.719 --> 01:13:47.120
sequences of length like 100 is much

01:13:43.800 --> 01:13:49.480
more memory intensive than uh 50

01:13:47.120 --> 01:13:51.960
sequences of Link five and so you get

01:13:49.480 --> 01:13:53.920
these vastly varying these mini batches

01:13:51.960 --> 01:13:57.000
of vastly varying size and that's both

01:13:53.920 --> 01:13:59.800
bad for you know memory overflows and

01:13:57.000 --> 01:14:01.639
bad for um and bad for learning

01:13:59.800 --> 01:14:04.280
stability so I I definitely recommend

01:14:01.639 --> 01:14:06.880
doing it based on the number of

01:14:04.280 --> 01:14:09.080
comps uh another thing is gpus versus

01:14:06.880 --> 01:14:12.400
CPUs so

01:14:09.080 --> 01:14:14.600
um uh CPUs one way you can think of it

01:14:12.400 --> 01:14:17.320
is a CPUs kind of like a motorcycle it's

01:14:14.600 --> 01:14:19.600
very fast at picking up and doing a

01:14:17.320 --> 01:14:23.960
bunch of uh things very quickly

01:14:19.600 --> 01:14:26.600
accelerating uh into starting new uh new

01:14:23.960 --> 01:14:28.760
tasks a GPU is more like an airplane

01:14:26.600 --> 01:14:30.719
which uh you wait forever in line in

01:14:28.760 --> 01:14:33.360
security and

01:14:30.719 --> 01:14:34.800
then and then uh it takes a long time to

01:14:33.360 --> 01:14:40.400
get off the ground and start working but

01:14:34.800 --> 01:14:43.679
once it does it's extremely fast um and

01:14:40.400 --> 01:14:45.360
so if we do a simple example of how long

01:14:43.679 --> 01:14:47.600
does it take to do a Matrix Matrix

01:14:45.360 --> 01:14:49.040
multiply I calculated this a really long

01:14:47.600 --> 01:14:51.280
time ago it's probably horribly out of

01:14:49.040 --> 01:14:55.120
date now but the same general principle

01:14:51.280 --> 01:14:56.560
stands which is if we have have um the

01:14:55.120 --> 01:14:58.480
number of seconds that it takes to do a

01:14:56.560 --> 01:15:02.080
Matrix Matrix multiply doing one of size

01:14:58.480 --> 01:15:03.920
16 is actually faster on CPU because uh

01:15:02.080 --> 01:15:07.760
the overhead it takes to get started is

01:15:03.920 --> 01:15:10.880
very low but if you um once you start

01:15:07.760 --> 01:15:13.360
getting up to size like 128 by 128

01:15:10.880 --> 01:15:15.800
Matrix multiplies then doing it on GPU

01:15:13.360 --> 01:15:17.320
is faster and then um it's you know a

01:15:15.800 --> 01:15:19.679
100 times faster once you start getting

01:15:17.320 --> 01:15:21.600
up to very large matrices so um if

01:15:19.679 --> 01:15:24.000
you're dealing with very large networks

01:15:21.600 --> 01:15:26.800
handling a GPU is good

01:15:24.000 --> 01:15:30.159
um and this is the the speed up

01:15:26.800 --> 01:15:31.440
percentage um one thing I should mention

01:15:30.159 --> 01:15:34.239
is

01:15:31.440 --> 01:15:36.440
um compute with respect to like doing

01:15:34.239 --> 01:15:39.800
the assignments for this class if you

01:15:36.440 --> 01:15:43.199
have a relatively recent Mac you're kind

01:15:39.800 --> 01:15:44.760
of in luck because actually the gpus on

01:15:43.199 --> 01:15:47.239
the Mac are pretty fast and they're well

01:15:44.760 --> 01:15:48.960
integrated with um they're well

01:15:47.239 --> 01:15:52.080
integrated with pipor and other things

01:15:48.960 --> 01:15:53.440
like that so decently sized models maybe

01:15:52.080 --> 01:15:54.840
up to the size that you would need to

01:15:53.440 --> 01:15:57.840
run for assignment one or even

01:15:54.840 --> 01:16:00.880
assignment two might uh just run on your

01:15:57.840 --> 01:16:03.639
uh laptop computer um if you don't have

01:16:00.880 --> 01:16:05.280
a GPU uh that you have immediately

01:16:03.639 --> 01:16:06.760
accessible to you I we're going to

01:16:05.280 --> 01:16:08.400
recommend that you use collab where you

01:16:06.760 --> 01:16:10.120
can get a GPU uh for the first

01:16:08.400 --> 01:16:12.440
assignments and then we'll have plug

01:16:10.120 --> 01:16:15.159
reddits that you can use otherwise but

01:16:12.440 --> 01:16:16.800
um GPU is usually like something that

01:16:15.159 --> 01:16:18.440
you can get on the cloud or one that you

01:16:16.800 --> 01:16:21.080
have on your Mac or one that you have on

01:16:18.440 --> 01:16:24.600
your gaming computer or something like

01:16:21.080 --> 01:16:26.040
that um there's a few speed tricks that

01:16:24.600 --> 01:16:30.000
you should know for efficient GPU

01:16:26.040 --> 01:16:32.480
operations so um one mistake that people

01:16:30.000 --> 01:16:35.880
make when creating models is they repeat

01:16:32.480 --> 01:16:38.080
operations over and over again and um

01:16:35.880 --> 01:16:40.600
you don't want to be doing this so like

01:16:38.080 --> 01:16:43.239
for example um this is multiplying a

01:16:40.600 --> 01:16:45.320
matrix by a constant multiple times and

01:16:43.239 --> 01:16:46.880
if you're just using out of thee box pie

01:16:45.320 --> 01:16:49.280
torch this would be really bad because

01:16:46.880 --> 01:16:50.400
you'd be repeating the operation uh when

01:16:49.280 --> 01:16:52.679
it's not

01:16:50.400 --> 01:16:54.480
necessary um you can also reduce the

01:16:52.679 --> 01:16:57.360
number of operations that you need to

01:16:54.480 --> 01:17:00.320
use so uh use Matrix Matrix multiplies

01:16:57.360 --> 01:17:03.080
instead of Matrix Vector

01:17:00.320 --> 01:17:07.920
multiplies and another thing is uh

01:17:03.080 --> 01:17:10.719
reducing CPU GPU data movement and um so

01:17:07.920 --> 01:17:12.360
when you do try to move memory um when

01:17:10.719 --> 01:17:17.080
you do try to move memory try to do it

01:17:12.360 --> 01:17:20.040
as early as possible and as uh and as

01:17:17.080 --> 01:17:22.199
few times as possible and the reason why

01:17:20.040 --> 01:17:24.199
you want to move things early or start

01:17:22.199 --> 01:17:25.920
operations early is many GPU operations

01:17:24.199 --> 01:17:27.159
are asynchronous so you can start the

01:17:25.920 --> 01:17:28.800
operation and it will run in the

01:17:27.159 --> 01:17:33.120
background while other things are

01:17:28.800 --> 01:17:36.080
processing so um it's a good idea to try

01:17:33.120 --> 01:17:39.840
to um to optimize and you can also use

01:17:36.080 --> 01:17:42.360
your python profiler or um envidia GPU

01:17:39.840 --> 01:17:43.679
profilers to try to optimize these

01:17:42.360 --> 01:17:46.520
things as

01:17:43.679 --> 01:17:49.840
well cool that's all I have uh we're

01:17:46.520 --> 01:17:49.840
right at time