File size: 475,140 Bytes
14422b0
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
8c9e9ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
6d6a6aa
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
6d6a6aa
0a6b1f5
 
 
 
6d6a6aa
0a6b1f5
6d6a6aa
 
0a6b1f5
 
 
 
 
6d6a6aa
 
 
0a6b1f5
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
 
0a6b1f5
 
 
 
 
 
 
6d6a6aa
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
0a6b1f5
6b48067
0a6b1f5
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
 
0a6b1f5
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
0a6b1f5
 
6d6a6aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
 
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
 
 
 
 
6d6a6aa
 
0a6b1f5
6d6a6aa
0a6b1f5
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
6d6a6aa
0a6b1f5
 
 
 
 
 
 
 
 
 
6d6a6aa
 
 
0a6b1f5
 
6d6a6aa
 
 
0a6b1f5
 
 
6d6a6aa
 
0a6b1f5
6d6a6aa
0a6b1f5
6d6a6aa
0a6b1f5
 
 
6d6a6aa
 
0a6b1f5
6d6a6aa
 
 
0a6b1f5
 
 
 
6d6a6aa
 
0a6b1f5
6d6a6aa
0a6b1f5
6d6a6aa
0a6b1f5
 
 
6d6a6aa
 
0a6b1f5
6d6a6aa
0a6b1f5
6d6a6aa
0a6b1f5
 
 
6d6a6aa
 
0a6b1f5
 
 
 
 
 
 
 
6b48067
 
0a6b1f5
 
6b48067
0a6b1f5
 
 
6b48067
0a6b1f5
 
6b48067
 
0a6b1f5
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
0a6b1f5
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
14422b0
 
6b48067
 
 
 
14422b0
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
6b48067
 
 
 
 
14422b0
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
14422b0
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
0a6b1f5
6b48067
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
6b48067
18550fb
6b48067
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
6b48067
0a6b1f5
 
 
 
6b48067
0a6b1f5
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18550fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
6b48067
ccd63d1
 
 
6b48067
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6af86f5
 
 
 
 
 
 
 
 
6b48067
6af86f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
6af86f5
 
6b48067
0a6b1f5
6b48067
6af86f5
 
 
0a6b1f5
6b48067
6af86f5
 
 
 
 
 
6b48067
 
6af86f5
 
6b48067
6af86f5
 
6b48067
 
6af86f5
 
6b48067
6af86f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
0a6b1f5
 
 
 
6b48067
ccd63d1
 
0a6b1f5
ccd63d1
 
 
0a6b1f5
ccd63d1
 
 
0a6b1f5
ccd63d1
0a6b1f5
 
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
0a6b1f5
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
0a6b1f5
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
6b48067
0a6b1f5
 
6b48067
0a6b1f5
6b48067
0a6b1f5
 
 
 
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
0a6b1f5
 
6b48067
0a6b1f5
 
 
 
 
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9e9ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
8c9e9ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9e9ed
0a6b1f5
8c9e9ed
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
 
 
 
 
 
8c9e9ed
 
0a6b1f5
 
8c9e9ed
0a6b1f5
 
8c9e9ed
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
8c9e9ed
0a6b1f5
 
8c9e9ed
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
8c9e9ed
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
8c9e9ed
 
 
0a6b1f5
8c9e9ed
0a6b1f5
 
 
 
 
 
8c9e9ed
0a6b1f5
 
 
 
 
 
 
 
8c9e9ed
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9e9ed
 
0a6b1f5
8c9e9ed
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9e9ed
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c9e9ed
 
0a6b1f5
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
0a6b1f5
ccd63d1
 
 
0a6b1f5
ccd63d1
 
 
0a6b1f5
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
ccd63d1
 
0a6b1f5
ccd63d1
0a6b1f5
 
ccd63d1
 
0a6b1f5
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
0a6b1f5
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
ccd63d1
 
 
0a6b1f5
ccd63d1
0a6b1f5
 
 
 
 
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
ccd63d1
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b48067
 
 
 
0a6b1f5
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
6b48067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
14422b0
0a6b1f5
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
8c9e9ed
 
0a6b1f5
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
14422b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
14422b0
ccd63d1
14422b0
ccd63d1
14422b0
ccd63d1
 
14422b0
ccd63d1
 
 
 
 
 
 
14422b0
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
6af86f5
 
ccd63d1
6af86f5
ccd63d1
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
6af86f5
ccd63d1
 
 
 
 
6af86f5
ccd63d1
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
6af86f5
ccd63d1
 
 
 
 
 
 
 
 
 
14422b0
 
 
 
 
 
 
 
 
 
 
 
ccd63d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a6b1f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14422b0
 
 
 
 
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
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Complete Deep Learning & Computer Vision Curriculum</title>

    <!-- Shared Design System -->
    <link rel="stylesheet" href="../shared/css/design-system.css">
    <link rel="stylesheet" href="../shared/css/components.css">

    <!-- MathJax 3.x -->
    <script>
        MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] } };
    </script>
    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            --bg: #0f1419;
            --surface: #1a1f2e;
            --text: #e4e6eb;
            --text-dim: #b0b7c3;
            --cyan: #00d4ff;
            --orange: #ff6b35;
            --green: #00ff88;
            --yellow: #ffa500;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--bg);
            color: var(--text);
            line-height: 1.6;
            overflow-x: hidden;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
        }

        header {
            text-align: center;
            margin-bottom: 40px;
            padding: 30px 0;
            border-bottom: 2px solid var(--cyan);
        }

        h1 {
            font-size: 2.5em;
            background: linear-gradient(135deg, var(--cyan), var(--orange));
            background-clip: text;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-bottom: 10px;
        }

        .subtitle {
            color: var(--text-dim);
            font-size: 1.1em;
        }

        .dashboard {
            display: none;
        }

        .dashboard.active {
            display: block;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 25px;
            margin: 40px 0;
        }

        .card {
            background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(255, 107, 53, 0.1));
            border: 2px solid var(--cyan);
            border-radius: 12px;
            padding: 30px;
            cursor: pointer;
            transition: all 0.3s ease;
            text-align: center;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 30px rgba(0, 212, 255, 0.2);
            border-color: var(--orange);
        }

        .card-icon {
            font-size: 3em;
            margin-bottom: 15px;
        }

        .card h3 {
            color: var(--cyan);
            font-size: 1.5em;
            margin-bottom: 10px;
        }

        .card p {
            color: var(--text-dim);
            font-size: 0.95em;
        }

        .category-label {
            display: inline-block;
            margin-top: 10px;
            padding: 5px 12px;
            background: rgba(0, 212, 255, 0.2);
            border-radius: 20px;
            font-size: 0.85em;
            color: var(--green);
        }

        .module {
            display: none;
        }

        .module.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        .btn-back {
            padding: 10px 20px;
            background: var(--orange);
            color: var(--bg);
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            margin-bottom: 25px;
            transition: all 0.3s ease;
        }

        .btn-back:hover {
            background: var(--cyan);
        }

        .tabs {
            display: flex;
            gap: 10px;
            margin-bottom: 30px;
            flex-wrap: wrap;
            justify-content: center;
            border-bottom: 1px solid rgba(0, 212, 255, 0.2);
            padding-bottom: 15px;
            overflow-x: auto;
        }

        .tab-btn {
            padding: 10px 20px;
            background: var(--surface);
            color: var(--text);
            border: 2px solid transparent;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.95em;
            transition: all 0.3s ease;
            font-weight: 500;
            white-space: nowrap;
        }

        .tab-btn:hover {
            background: rgba(0, 212, 255, 0.1);
            border-color: var(--cyan);
        }

        .tab-btn.active {
            background: var(--cyan);
            color: var(--bg);
            border-color: var(--cyan);
        }

        .tab {
            display: none;
        }

        .tab.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }

        .section {
            background: var(--surface);
            border: 1px solid rgba(0, 212, 255, 0.2);
            border-radius: 10px;
            padding: 30px;
            margin-bottom: 25px;
            transition: all 0.3s ease;
        }

        .section:hover {
            border-color: var(--cyan);
            box-shadow: 0 0 20px rgba(0, 212, 255, 0.1);
        }

        h2 {
            color: var(--cyan);
            font-size: 1.8em;
            margin-bottom: 15px;
        }

        h3 {
            color: var(--orange);
            font-size: 1.3em;
            margin-top: 20px;
            margin-bottom: 12px;
        }

        h4 {
            color: var(--green);
            font-size: 1.1em;
            margin-top: 15px;
            margin-bottom: 10px;
        }

        p {
            margin-bottom: 15px;
            line-height: 1.8;
        }

        ul {
            margin-left: 20px;
            margin-bottom: 15px;
        }

        ul li {
            margin-bottom: 8px;
        }

        .info-box {
            background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(255, 107, 53, 0.1));
            border: 1px solid var(--cyan);
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
        }

        .box-title {
            color: var(--orange);
            font-weight: 700;
            margin-bottom: 10px;
            font-size: 1.1em;
        }

        .box-content {
            color: var(--text-dim);
            line-height: 1.7;
        }

        .formula {
            background: rgba(0, 212, 255, 0.1);
            border: 1px solid var(--cyan);
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            font-family: 'Courier New', monospace;
            overflow-x: auto;
            line-height: 1.8;
            color: var(--cyan);
        }

        .code-block {
            background: #0d1117;
            border: 1px solid #30363d;
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            overflow-x: auto;
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 0.88em;
            line-height: 1.7;
            white-space: pre-wrap;
            color: #e6edf3;
        }

        .code-block .comment {
            color: #8b949e;
        }

        .code-block .keyword {
            color: #ff7b72;
        }

        .code-block .string {
            color: #a5d6ff;
        }

        .code-block .function {
            color: #d2a8ff;
        }

        .code-block .number {
            color: #79c0ff;
        }

        .code-block .class-name {
            color: #ffa657;
        }

        .code-block .builtin {
            color: #79c0ff;
        }

        .code-title {
            display: block;
            background: #161b22;
            color: #8b949e;
            padding: 8px 16px;
            border-radius: 8px 8px 0 0;
            border: 1px solid #30363d;
            border-bottom: none;
            font-size: 0.85em;
            font-family: 'Fira Code', monospace;
            margin-top: 20px;
        }

        .code-title+.code-block {
            margin-top: 0;
            border-radius: 0 0 8px 8px;
        }

        .callout {
            border-left: 4px solid;
            padding: 15px;
            margin: 20px 0;
            border-radius: 6px;
        }

        .callout.tip {
            border-left-color: var(--green);
            background: rgba(0, 255, 136, 0.05);
        }

        .callout.warning {
            border-left-color: var(--yellow);
            background: rgba(255, 165, 0, 0.05);
        }

        .callout.insight {
            border-left-color: var(--cyan);
            background: rgba(0, 212, 255, 0.05);
        }

        .callout-title {
            font-weight: 700;
            margin-bottom: 8px;
        }

        .list-item {
            display: flex;
            gap: 12px;
            margin: 12px 0;
            padding: 12px;
            background: rgba(0, 212, 255, 0.05);
            border-left: 3px solid var(--cyan);
            border-radius: 4px;
        }

        .list-num {
            color: var(--orange);
            font-weight: 700;
            min-width: 30px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }

        th,
        td {
            padding: 12px;
            text-align: left;
            border: 1px solid rgba(0, 212, 255, 0.2);
        }

        th {
            background: rgba(0, 212, 255, 0.1);
            color: var(--cyan);
            font-weight: 700;
        }

        .viz-container {
            background: rgba(0, 212, 255, 0.02);
            border: 1px solid rgba(0, 212, 255, 0.2);
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            display: flex;
            justify-content: center;
            overflow-x: auto;
        }

        .viz-controls {
            display: flex;
            gap: 10px;
            margin-top: 20px;
            justify-content: center;
            flex-wrap: wrap;
        }

        .btn-viz {
            padding: 10px 20px;
            background: var(--cyan);
            color: var(--bg);
            border: none;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            font-size: 0.95em;
            transition: all 0.3s ease;
        }

        .btn-viz:hover {
            background: var(--orange);
            transform: scale(1.05);
        }

        canvas {
            max-width: 100%;
            height: auto;
        }

        @media (max-width: 768px) {
            h1 {
                font-size: 1.8em;
            }

            .tabs {
                flex-direction: column;
            }

            .tab-btn {
                width: 100%;
            }

            .grid {
                grid-template-columns: 1fr;
            }

            canvas {
                width: 100% !important;
                height: auto !important;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- MAIN DASHBOARD -->
        <div id="dashboard" class="dashboard active">
            <header>
                <h1>๐Ÿง  Complete Deep Learning & Computer Vision</h1>
                <p class="subtitle">Comprehensive Curriculum | Foundations to Advanced Applications</p>
            </header>

            <div style="text-align: center; margin-bottom: 40px;">
                <p style="color: var(--text-dim); font-size: 1.1em;">
                    Master all aspects of deep learning and computer vision. 25+ modules covering neural networks, CNNs,
                    object detection, GANs, and more.
                </p>
            </div>

            <div class="grid" id="modulesGrid"></div>
        </div>

        <!-- MODULES CONTAINER -->
        <div id="modulesContainer"></div>
    </div>

    <script>
        const modules = [
            // Module 1: Deep Learning Foundations
            {
                id: "nn-basics",
                title: "Introduction to Neural Networks",
                icon: "๐Ÿงฌ",
                category: "Foundations",
                color: "#0088ff",
                description: "Biological vs. Artificial neurons and network architecture"
            },
            {
                id: "perceptron",
                title: "The Perceptron",
                icon: "โš™๏ธ",
                category: "Foundations",
                color: "#0088ff",
                description: "Single layer networks and their limitations"
            },
            {
                id: "mlp",
                title: "Multi-Layer Perceptron (MLP)",
                icon: "๐Ÿ—๏ธ",
                category: "Foundations",
                color: "#0088ff",
                description: "Hidden layers and deep architectures"
            },
            {
                id: "activation",
                title: "Activation Functions",
                icon: "โšก",
                category: "Foundations",
                color: "#0088ff",
                description: "Sigmoid, ReLU, Tanh, Leaky ReLU, ELU, Softmax"
            },
            {
                id: "weight-init",
                title: "Weight Initialization",
                icon: "๐ŸŽฏ",
                category: "Foundations",
                color: "#0088ff",
                description: "Xavier, He, Random initialization strategies"
            },
            {
                id: "loss",
                title: "Loss Functions",
                icon: "๐Ÿ“‰",
                category: "Foundations",
                color: "#0088ff",
                description: "MSE, Binary Cross-Entropy, Categorical Cross-Entropy"
            },
            {
                id: "optimizers",
                title: "Optimizers",
                icon: "๐ŸŽฏ",
                category: "Training",
                color: "#00ff00",
                description: "SGD, Momentum, Adam, Adagrad, RMSprop"
            },
            {
                id: "backprop",
                title: "Forward & Backpropagation",
                icon: "โฌ…๏ธ",
                category: "Training",
                color: "#00ff00",
                description: "Chain rule and gradient computation"
            },
            {
                id: "regularization",
                title: "Regularization",
                icon: "๐Ÿ›ก๏ธ",
                category: "Training",
                color: "#00ff00",
                description: "L1/L2, Dropout, Early Stopping, Batch Norm"
            },
            {
                id: "batch-norm",
                title: "Batch Normalization",
                icon: "โš™๏ธ",
                category: "Training",
                color: "#00ff00",
                description: "Stabilizing and speeding up training"
            },
            // Module 2: Computer Vision Fundamentals
            {
                id: "cv-intro",
                title: "CV Fundamentals",
                icon: "๐Ÿ‘๏ธ",
                category: "Computer Vision",
                color: "#ff6b35",
                description: "Why ANNs fail with images, parameter explosion"
            },
            {
                id: "conv-layer",
                title: "Convolutional Layers",
                icon: "๐Ÿ–ผ๏ธ",
                category: "Computer Vision",
                color: "#ff6b35",
                description: "Kernels, filters, feature maps, stride, padding"
            },
            {
                id: "pooling",
                title: "Pooling Layers",
                icon: "๐Ÿ“ฆ",
                category: "Computer Vision",
                color: "#ff6b35",
                description: "Max pooling, average pooling, spatial reduction"
            },
            {
                id: "cnn-basics",
                title: "CNN Architecture",
                icon: "๐Ÿ—๏ธ",
                category: "Computer Vision",
                color: "#ff6b35",
                description: "Combining conv, pooling, and fully connected layers"
            },
            {
                id: "viz-filters",
                title: "Visualizing CNNs",
                icon: "๐Ÿ”",
                category: "Computer Vision",
                color: "#ff6b35",
                description: "What filters learn: edges โ†’ shapes โ†’ objects"
            },
            // Module 3: Advanced CNN Architectures
            {
                id: "lenet",
                title: "LeNet-5",
                icon: "๐Ÿ”ข",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "Classic digit recognizer (MNIST)"
            },
            {
                id: "alexnet",
                title: "AlexNet",
                icon: "๐ŸŒŸ",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "The breakthrough in deep computer vision (2012)"
            },
            {
                id: "vgg",
                title: "VGGNet",
                icon: "๐Ÿ“Š",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "VGG-16/19: Deep networks with small filters"
            },
            {
                id: "resnet",
                title: "ResNet",
                icon: "๐ŸŒ‰",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "Skip connections, solving vanishing gradients"
            },
            {
                id: "inception",
                title: "InceptionNet (GoogLeNet)",
                icon: "๐ŸŽฏ",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "1x1 convolutions, multi-scale feature extraction"
            },
            {
                id: "mobilenet",
                title: "MobileNet",
                icon: "๐Ÿ“ฑ",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "Depth-wise separable convolutions for efficiency"
            },
            {
                id: "transfer-learning",
                title: "Transfer Learning",
                icon: "๐Ÿ”„",
                category: "CNN Architectures",
                color: "#ff00ff",
                description: "Fine-tuning and leveraging pre-trained models"
            },
            // Module 4: Object Detection & Segmentation
            {
                id: "localization",
                title: "Object Localization",
                icon: "๐Ÿ“",
                category: "Detection",
                color: "#00ff00",
                description: "Bounding boxes and classification together"
            },
            {
                id: "rcnn",
                title: "R-CNN Family",
                icon: "๐ŸŽฏ",
                category: "Detection",
                color: "#00ff00",
                description: "R-CNN, Fast R-CNN, Faster R-CNN"
            },
            {
                id: "yolo",
                title: "YOLO",
                icon: "โšก",
                category: "Detection",
                color: "#00ff00",
                description: "Real-time object detection (v3, v5, v8)"
            },
            {
                id: "ssd",
                title: "SSD",
                icon: "๐Ÿš€",
                category: "Detection",
                color: "#00ff00",
                description: "Single Shot MultiBox Detector"
            },
            {
                id: "semantic-seg",
                title: "Semantic Segmentation",
                icon: "๐Ÿ–Œ๏ธ",
                category: "Segmentation",
                color: "#00ff00",
                description: "Pixel-level classification (U-Net)"
            },
            {
                id: "instance-seg",
                title: "Instance Segmentation",
                icon: "๐Ÿ‘ฅ",
                category: "Segmentation",
                color: "#00ff00",
                description: "Mask R-CNN and separate object instances"
            },
            {
                id: "face-recog",
                title: "Face Recognition",
                icon: "๐Ÿ‘ค",
                category: "Segmentation",
                color: "#00ff00",
                description: "Siamese networks and triplet loss"
            },
            // Module 5: Generative Models
            {
                id: "autoencoders",
                title: "Autoencoders",
                icon: "๐Ÿ”€",
                category: "Generative",
                color: "#ffaa00",
                description: "Encoder-decoder, latent space, denoising"
            },
            {
                id: "gans",
                title: "GANs (Generative Adversarial Networks)",
                icon: "๐ŸŽฎ",
                category: "Generative",
                color: "#ffaa00",
                description: "Generator vs. Discriminator, DCGAN"
            },
            {
                id: "diffusion",
                title: "Diffusion Models",
                icon: "๐ŸŒŠ",
                category: "Generative",
                color: "#ffaa00",
                description: "Foundation of Stable Diffusion and DALL-E"
            },
            // Additional Advanced Topics
            {
                id: "rnn",
                title: "RNNs & LSTMs",
                icon: "๐Ÿ”„",
                category: "Sequence",
                color: "#ff6b35",
                description: "Recurrent networks for sequential data"
            },
            {
                id: "transformers",
                title: "Transformers",
                icon: "๐Ÿ”—",
                category: "Sequence",
                color: "#ff6b35",
                description: "\"Attention Is All You Need\" - Complete paper breakdown with math"
            },
            {
                id: "bert",
                title: "BERT & NLP Transformers",
                icon: "๐Ÿ“š",
                category: "NLP",
                color: "#ff6b35",
                description: "Bidirectional transformers for language"
            },
            {
                id: "gpt",
                title: "GPT & Language Models",
                icon: "๐Ÿ’ฌ",
                category: "NLP",
                color: "#ff6b35",
                description: "Autoregressive models and text generation"
            },
            {
                id: "vit",
                title: "Vision Transformers (ViT)",
                icon: "๐ŸŽจ",
                category: "Vision",
                color: "#ff6b35",
                description: "Transformers applied to image data"
            },
            {
                id: "gnn",
                title: "Graph Neural Networks",
                icon: "๐Ÿ•ธ๏ธ",
                category: "Advanced",
                color: "#9900ff",
                description: "Deep learning on non-Euclidean graph data"
            },
            {
                id: "seq2seq",
                title: "Seq2Seq & Attention",
                icon: "โžก๏ธ",
                category: "NLP",
                color: "#ff6b35",
                description: "Encoder-Decoder models and Attention mechanics"
            },
            {
                id: "research-papers",
                title: "Research Library",
                icon: "๐ŸŽ“",
                category: "Advanced",
                color: "#9900ff",
                description: "Curated collection of seminal deep learning papers"
            },
            // Module 7: GenAI & LLM Engineering
            {
                id: "vector-db",
                title: "Vector Databases",
                icon: "๐Ÿงฒ",
                category: "GenAI",
                color: "#00c9a7",
                description: "Embeddings, similarity search, FAISS, Pinecone, ChromaDB"
            },
            {
                id: "rag",
                title: "RAG Pipelines",
                icon: "๐Ÿ”—",
                category: "GenAI",
                color: "#00c9a7",
                description: "Retrieval-Augmented Generation for grounded AI"
            },
            {
                id: "advanced-llm",
                title: "Fine-Tuning & Quantization",
                icon: "โš™๏ธ",
                category: "GenAI",
                color: "#00c9a7",
                description: "LoRA, QLoRA, PEFT, GGUF, and deployment strategies"
            }
        ];

        // Comprehensive content for all modules
        const MODULE_CONTENT = {
            "nn-basics": {
                overview: `
                <p>A neural network is a computing system <strong>inspired by biological brains</strong> โ€” but it's not a brain simulation. It's a mathematical function that learns patterns from data by adjusting millions of numbers called <strong>weights</strong>.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿง  The Core Intuition</div>
                    Think of a neural network like a factory assembly line. Raw materials (data) enter one end. At each station (layer), workers (neurons) examine the material, make a small decision, and pass the result forward. By the end, the factory produces a finished product (prediction). During training, a quality inspector (loss function) checks the output and sends feedback backward through the line so each worker can improve.
                </div>

                <h3>How Does a Single Neuron Work?</h3>
                <p>A neuron does three things:</p>
                <div class="list-item">
                    <div class="list-num">1</div>
                    <div><strong>Weighted Sum:</strong> Multiply each input by a weight and add them up: $$z = w_1 x_1 + w_2 x_2 + ... + w_n x_n + b$$</div>
                </div>
                <div class="list-item">
                    <div class="list-num">2</div>
                    <div><strong>Bias:</strong> Add a bias term $b$ โ€” this shifts the decision boundary (like the y-intercept in y = mx + b)</div>
                </div>
                <div class="list-item">
                    <div class="list-num">3</div>
                    <div><strong>Activation:</strong> Pass the result through a non-linear function: $$a = \\sigma(z)$$</div>
                </div>

                <h3>The Training Process</h3>
                <p>Training a neural network follows a simple loop repeated thousands of times:</p>
                <div class="info-box">
                    <div class="box-title">๐Ÿ”„ The Training Loop</div>
                    <div class="box-content">
                        <strong>1. Forward Pass:</strong> Feed data through the network, get a prediction<br>
                        <strong>2. Compute Loss:</strong> Measure how wrong the prediction is (e.g., MSE, Cross-Entropy)<br>
                        <strong>3. Backward Pass:</strong> Calculate how each weight contributed to the error (gradients via chain rule)<br>
                        <strong>4. Update Weights:</strong> Nudge each weight slightly to reduce the error: $$w_{new} = w_{old} - \\eta \\cdot \\frac{\\partial L}{\\partial w}$$
                        <strong>5. Repeat</strong> until the loss is small enough
                    </div>
                </div>

                <h3>Types of Layers</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Layer Type</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Purpose</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Example</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Dense/Linear</td><td>Every neuron connects to every input</td><td>nn.Linear(784, 128)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Convolutional</td><td>Detect spatial patterns (edges, textures)</td><td>nn.Conv2d(3, 32, 3)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Recurrent (LSTM/GRU)</td><td>Process sequences (text, time series)</td><td>nn.LSTM(128, 256)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Attention</td><td>Focus on relevant parts of input</td><td>nn.MultiheadAttention()</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Dropout</td><td>Regularization (randomly zero neurons)</td><td>nn.Dropout(0.5)</td></tr>
                    <tr><td style="padding: 8px;">BatchNorm</td><td>Stabilize and speed up training</td><td>nn.BatchNorm1d(128)</td></tr>
                </table>
`,
                concepts: `
                    <h3>Core Components</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Neurons (Nodes):</strong> Basic computational units that receive inputs, apply weights, add bias, and apply activation function</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Layers:</strong> Input layer (receives data), Hidden layers (feature extraction), Output layer (predictions)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Weights:</strong> Parameters learned during training that determine connection strength</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Bias:</strong> Allows shifting the activation function for better fitting</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Activation Function:</strong> Introduces non-linearity (ReLU, Sigmoid, Tanh)</div>
                    </div>
                `,
                applications: `
                    <h3>Real-World Applications</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Healthcare</div>
                        <div class="box-content">Disease diagnosis, medical image analysis, drug discovery, patient risk prediction</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ฐ Finance</div>
                        <div class="box-content">Fraud detection, algorithmic trading, credit scoring, portfolio optimization</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ›’ E-commerce</div>
                        <div class="box-content">Recommendation systems, demand forecasting, customer segmentation, price optimization</div>
                    </div>
                `,
                math: `
                    <h3>The Fundamental Equations of a Neuron</h3>
                    <p>A single neuron performs a weighted sum followed by an activation function. This is the atomic building block of all neural networks.</p>
                    
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>z = ฮฃ(wแตขxแตข) + b = wโ‚xโ‚ + wโ‚‚xโ‚‚ + ... + wโ‚™xโ‚™ + b</strong><br>
                        <strong>a = ฯƒ(z)</strong>
                    </div>
                    
                    <h4>Step-by-Step: Single Neuron Forward Pass</h4>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div>
                            <strong>Weighted Sum (Linear):</strong><br>
                            z = wแต€x + b = ฮฃแตข wแตขxแตข + b<br>
                            <span class="formula-caption">This is a dot product plus bias - pure linear algebra</span>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div>
                            <strong>Activation (Non-Linear):</strong><br>
                            a = ฯƒ(z) where ฯƒ can be ReLU, Sigmoid, Tanh, etc.<br>
                            <span class="formula-caption">This introduces non-linearity, enabling complex functions</span>
                        </div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Manual Forward Pass</div>
                        <strong>Inputs:</strong> x = [2, 3], <strong>Weights:</strong> w = [0.5, -0.3], <strong>Bias:</strong> b = 0.1<br><br>
                        <strong>Step 1 - Weighted Sum:</strong><br>
                        z = (0.5 ร— 2) + (-0.3 ร— 3) + 0.1<br>
                        z = 1.0 - 0.9 + 0.1 = <strong>0.2</strong><br><br>
                        <strong>Step 2 - ReLU Activation:</strong><br>
                        a = max(0, 0.2) = <strong>0.2</strong><br><br>
                        <strong>Step 2 (alt) - Sigmoid Activation:</strong><br>
                        a = 1 / (1 + eโปโฐยทยฒ) = 1 / 1.819 โ‰ˆ <strong>0.55</strong>
                    </div>
                    
                    <h3>Network Layer in Matrix Form</h3>
                    <p>For a layer with n inputs and m neurons, we use matrices for efficiency:</p>
                    
                    <div class="formula">
                        <strong>Z = WX + b</strong><br>
                        <strong>A = ฯƒ(Z)</strong><br><br>
                        Where:<br>
                        โ€ข W โˆˆ โ„แตหฃโฟ (weight matrix: m neurons, n inputs)<br>
                        โ€ข X โˆˆ โ„โฟหฃยน (input vector)<br>
                        โ€ข b โˆˆ โ„แตหฃยน (bias vector)<br>
                        โ€ข Z โˆˆ โ„แตหฃยน (pre-activation)<br>
                        โ€ข A โˆˆ โ„แตหฃยน (activation output)
                    </div>
                    
                    <h3>Parameter Count Formula</h3>
                    <div class="formula">
                        For a layer: n_in โ†’ n_out<br>
                        <strong>Parameters = n_in ร— n_out + n_out</strong><br>
                        (weights) + (biases)<br><br>
                        Example: Layer 784 โ†’ 128<br>
                        Params = 784 ร— 128 + 128 = 100,480
                    </div>
                `,
                code: `
                    <h3>Build a Neuron from Scratch (NumPy)</h3>
                    <p>Let's implement the fundamental unit of a neural network โ€” a single neuron โ€” using only NumPy. This helps you understand what happens <strong>under the hood</strong> before using frameworks like PyTorch.</p>
                    <span class="code-title">๐Ÿ“„ neuron_numpy.py</span><div class="code-block"><span class="keyword">import</span> numpy <span class="keyword">as</span> np

<span class="comment"># --- A Single Neuron from Scratch ---</span>
<span class="keyword">def</span> <span class="function">sigmoid</span>(z):
    <span class="string">"""Activation function: squashes output to (0, 1)"""</span>
    <span class="keyword">return</span> <span class="number">1</span> / (<span class="number">1</span> + np.exp(-z))

<span class="comment"># Input features (e.g., hours studied, hours slept)</span>
X = np.array([<span class="number">6.0</span>, <span class="number">8.0</span>])

<span class="comment"># Learnable parameters</span>
weights = np.array([<span class="number">0.5</span>, <span class="number">-0.3</span>])
bias = <span class="number">0.1</span>

<span class="comment"># Forward pass: z = wยทx + b</span>
z = np.dot(weights, X) + bias   <span class="comment"># 0.5*6 + (-0.3)*8 + 0.1 = 0.7</span>
output = sigmoid(z)              <span class="comment"># ฯƒ(0.7) โ‰ˆ 0.668</span>

<span class="keyword">print</span>(f<span class="string">"Linear output z = {z:.3f}"</span>)
<span class="keyword">print</span>(f<span class="string">"Activated output a = {output:.3f}"</span>)</div>
                    <h3>The Same Neuron in PyTorch</h3>
                    <p>PyTorch wraps this into <code>nn.Linear</code>. One line replaces all the manual math above โ€” but the computation is identical.</p>
                    <span class="code-title">๐Ÿ“„ neuron_pytorch.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="comment"># A single neuron: 2 inputs โ†’ 1 output</span>
neuron = nn.Linear(in_features=<span class="number">2</span>, out_features=<span class="number">1</span>)

<span class="comment"># Input tensor</span>
X = torch.tensor([[<span class="number">6.0</span>, <span class="number">8.0</span>]])

<span class="comment"># Forward pass</span>
z = neuron(X)                    <span class="comment"># Linear: z = Wx + b</span>
a = torch.sigmoid(z)             <span class="comment"># Activation</span>
<span class="keyword">print</span>(f<span class="string">"Output: {a.item():.4f}"</span>)

<span class="comment"># Check learnable parameters</span>
<span class="keyword">print</span>(f<span class="string">"Weights: {neuron.weight.data}"</span>)
<span class="keyword">print</span>(f<span class="string">"Bias: {neuron.bias.data}"</span>)
<span class="keyword">print</span>(f<span class="string">"Total params: {sum(p.numel() for p in neuron.parameters())}"</span>)  <span class="comment"># 3</span></div>
                    <h3>Build a Simple Neural Network</h3>
                    <span class="code-title">๐Ÿ“„ simple_network.py</span><div class="code-block"><span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="comment"># 3-layer network: 784 โ†’ 128 โ†’ 64 โ†’ 10</span>
model = nn.Sequential(
    nn.Linear(<span class="number">784</span>, <span class="number">128</span>),   <span class="comment"># Hidden layer 1</span>
    nn.ReLU(),
    nn.Linear(<span class="number">128</span>, <span class="number">64</span>),    <span class="comment"># Hidden layer 2</span>
    nn.ReLU(),
    nn.Linear(<span class="number">64</span>, <span class="number">10</span>),     <span class="comment"># Output layer (10 classes)</span>
)

<span class="comment"># Count parameters</span>
total = <span class="builtin">sum</span>(p.numel() <span class="keyword">for</span> p <span class="keyword">in</span> model.parameters())
<span class="keyword">print</span>(f<span class="string">"Total parameters: {total:,}"</span>)  <span class="comment"># 109,386</span>

<span class="comment"># Forward pass with random MNIST-like input</span>
X = torch.randn(<span class="number">1</span>, <span class="number">784</span>)
output = model(X)
<span class="keyword">print</span>(f<span class="string">"Output shape: {output.shape}"</span>)  <span class="comment"># [1, 10]</span></div>
                `
            },
            "activation": {
                overview: `
                <p>Activation functions are the <strong>secret sauce</strong> that gives neural networks their power. Without them, a neural network โ€” no matter how many layers โ€” would just be a fancy linear regression. They introduce <strong>non-linearity</strong>, which is what allows networks to learn complex patterns like recognizing faces, understanding language, or playing games.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿง  The Big Idea</div>
                    Imagine trying to separate red and blue dots on a page using only straight lines. Without activation functions, that's all a neural network can do โ€” draw straight lines. With activation functions, the network can bend, curve, and twist those lines into any shape needed to perfectly separate the dots.
                </div>

                <h3>Why Do We Need Activation Functions?</h3>
                <p>Consider stacking two linear layers:</p>
                <div class="formula">
                    Layer 1: $$z_1 = W_1 x + b_1$$
                    Layer 2: $$z_2 = W_2 z_1 + b_2 = W_2(W_1 x + b_1) + b_2 = (W_2 W_1)x + (W_2 b_1 + b_2)$$
                </div>
                <p>The result is still just <strong>one linear transformation</strong>! Adding 100 more layers changes nothing โ€” it collapses into a single matrix multiplication. Activation functions break this linearity.</p>

                <div class="info-box">
                    <div class="box-title">Learning Objectives</div>
                    <div class="box-content">
                        โœ“ Understand <strong>why</strong> non-linearity is essential for deep learning<br>
                        โœ“ Master 7 activation functions: Sigmoid, Tanh, ReLU, Leaky ReLU, ELU, Softmax, GELU<br>
                        โœ“ Know the <strong>vanishing gradient problem</strong> and which activations solve it<br>
                        โœ“ Learn when to use which activation (hidden layers vs. output layers)<br>
                        โœ“ Implement all activations in PyTorch
                    </div>
                </div>

                <h3>Quick Comparison Table</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Function</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Range</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Best For</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Issue</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
                        <td style="padding: 8px;">Sigmoid</td><td>(0, 1)</td><td>Binary output</td><td>Vanishing gradient</td>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
                        <td style="padding: 8px;">Tanh</td><td>(-1, 1)</td><td>Hidden layers (older models)</td><td>Vanishing gradient</td>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
                        <td style="padding: 8px;">ReLU</td><td>[0, โˆž)</td><td>Default for hidden layers</td><td>Dying neurons</td>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
                        <td style="padding: 8px;">Leaky ReLU</td><td>(-โˆž, โˆž)</td><td>When ReLU neurons die</td><td>Extra hyperparameter</td>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
                        <td style="padding: 8px;">GELU</td><td>โ‰ˆ(-0.17, โˆž)</td><td>Transformers (BERT, GPT)</td><td>Slightly slower</td>
                    </tr>
                    <tr>
                        <td style="padding: 8px;">Softmax</td><td>(0, 1) sums to 1</td><td>Multi-class output</td><td>Only for output layer</td>
                    </tr>
                </table>
`,
                concepts: `
                <h3>1. Sigmoid โ€” The Classic Gate</h3>
                <p>Sigmoid squashes any input into the range (0, 1). Think of it as a <strong>confidence score</strong> โ€” how sure is the network that something is true?</p>
                <div class="formula" style="text-align:center;">$$\\sigma(z) = \\frac{1}{1 + e^{-z}}$$</div>
                <div class="callout tip">
                    <div class="callout-title">๐Ÿ“Œ When to Use</div>
                    <strong>Only</strong> for the output layer of binary classification (yes/no, spam/not-spam). <strong>Never</strong> use in hidden layers โ€” it causes the vanishing gradient problem.
                </div>
                <p><strong>Why it vanishes:</strong> The maximum derivative of sigmoid is just 0.25 (at z=0). When you multiply gradients across 10 layers: 0.25ยนโฐ โ‰ˆ 0.00000095. The gradient essentially disappears, and the network stops learning.</p>

                <h3>2. Tanh โ€” Centered Sigmoid</h3>
                <p>Tanh is sigmoid's improvement โ€” it outputs values between (-1, 1), which means it's <strong>zero-centered</strong>. This helps with optimization because gradients don't all push in the same direction.</p>
                <div class="formula" style="text-align:center;">$$\\tanh(z) = \\frac{e^z - e^{-z}}{e^z + e^{-z}} = 2\\sigma(2z) - 1$$</div>
                <p>Fun fact: Tanh is just a rescaled sigmoid! It's better for hidden layers than sigmoid, but still vanishes for large |z|.</p>

                <h3>3. ReLU โ€” The Game Changer</h3>
                <p>ReLU (Rectified Linear Unit) is beautifully simple: output the input if positive, else output zero. This simplicity made deep learning practical.</p>
                <div class="formula" style="text-align:center;">$$\\text{ReLU}(z) = \\max(0, z)$$</div>
                <div class="callout insight">
                    <div class="callout-title">๐ŸŽฏ Why ReLU Changed Everything</div>
                    <strong>1. No vanishing gradient:</strong> Gradient is exactly 1 for positive inputs โ€” constant, never shrinking.<br>
                    <strong>2. Sparse activation:</strong> ~50% of neurons output 0. This sparsity makes networks efficient.<br>
                    <strong>3. Computationally cheap:</strong> Just a comparison โ€” no exponentials like sigmoid/tanh.<br>
                    <strong>4. Biologically plausible:</strong> Real neurons either fire or don't (all-or-nothing).
                </div>
                <p><strong>The Dying ReLU Problem:</strong> If a neuron's input is always negative (e.g., after a bad weight update), its gradient is permanently 0. That neuron is "dead" โ€” it will never activate again. Solution โ†’ Leaky ReLU.</p>

                <h3>4. Leaky ReLU & Parametric ReLU</h3>
                <p>Instead of outputting 0 for negative inputs, Leaky ReLU allows a small slope (typically ฮฑ=0.01):</p>
                <div class="formula" style="text-align:center;">$$\\text{LeakyReLU}(z) = \\begin{cases} z & z > 0 \\\\ \\alpha z & z \\leq 0 \\end{cases}$$</div>
                <p><strong>Parametric ReLU (PReLU)</strong> makes ฮฑ a <em>learnable parameter</em> โ€” the network decides the optimal slope for negative values.</p>

                <h3>5. GELU โ€” The Transformer's Choice</h3>
                <p>GELU (Gaussian Error Linear Unit) is used in GPT, BERT, and almost all modern transformers. Unlike ReLU's hard cutoff at 0, GELU provides a <strong>smooth curve</strong>:</p>
                <div class="formula" style="text-align:center;">$$\\text{GELU}(z) = z \\cdot \\Phi(z) \\approx 0.5z\\left(1 + \\tanh\\left[\\sqrt{\\frac{2}{\\pi}}(z + 0.044715z^3)\\right]\\right)$$</div>
                <p>Where ฮฆ(z) is the cumulative distribution function of the standard normal. It "softly gates" the input based on how likely it is to be positive statistically.</p>

                <h3>6. Swish / SiLU</h3>
                <p>Discovered by Google through automated search. It's simply x times sigmoid(x):</p>
                <div class="formula" style="text-align:center;">$$\\text{Swish}(z) = z \\cdot \\sigma(z) = \\frac{z}{1 + e^{-z}}$$</div>
                <p>Swish is smooth, non-monotonic, and consistently outperforms ReLU in deep networks (>40 layers). Used in EfficientNet.</p>

                <h3>7. Softmax โ€” Probability Distribution</h3>
                <p>Softmax converts a vector of raw scores (logits) into a <strong>probability distribution</strong>. All outputs sum to 1.</p>
                <div class="formula" style="text-align:center;">$$\\text{Softmax}(z_i) = \\frac{e^{z_i}}{\\sum_{j=1}^{K} e^{z_j}}$$</div>
                <p><strong>Example:</strong> Logits [2.0, 1.0, 0.1] โ†’ Softmax [0.659, 0.242, 0.099]. The network is 65.9% confident in class 0.</p>

                <div class="callout warning">
                    <div class="callout-title">โš ๏ธ Common Mistakes</div>
                    1. Using Softmax in hidden layers (it's for the final output layer only)<br>
                    2. Using Sigmoid for multi-class (use Softmax instead)<br>
                    3. Applying Softmax manually before CrossEntropyLoss in PyTorch (it already includes softmax!)
                </div>

                <h3>Decision Guide: Which Activation to Use?</h3>
                <div class="info-box">
                    <div class="box-title">๐ŸŽฏ The Simple Rules</div>
                    <div class="box-content">
                        <strong>Hidden layers:</strong> Start with ReLU. If you see dying neurons, try Leaky ReLU. For Transformers, use GELU.<br><br>
                        <strong>Output layer โ€” Binary classification:</strong> Sigmoid (one neuron, output = probability)<br>
                        <strong>Output layer โ€” Multi-class:</strong> Softmax (K neurons, outputs = probabilities summing to 1)<br>
                        <strong>Output layer โ€” Regression:</strong> No activation (or Linear) โ€” let the output be any real number
                    </div>
                </div>
`,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿง  Neural Network Design</div>
                        <div class="box-content">
                            Critical choice for every neural network - affects training speed, convergence, and final accuracy
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Task-Specific Selection</div>
                        <div class="box-content">
                            Different tasks need different outputs: Sigmoid for binary, Softmax for multi-class, Linear for regression
                        </div>
                    </div>

                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽค Probable Interview Questions</div>
                        1. Why do we need activation functions?<br>
                        2. What is vanishing gradient?<br>
                        3. Why is ReLU preferred over sigmoid?<br>
                        4. What are dead neurons?<br>
                        5. Difference between ReLU and Leaky ReLU?<br>
                        6. Why softmax instead of sigmoid for multiclass?<br>
                        7. Why linear activation for regression output?<br>
                        8. Why GELU is used in transformers?<br>
                        9. Can activation function affect convergence speed?<br>
                        10. What happens if we remove activation functions?
                    </div>
                `,
                math: `
                    <h3>Derivatives: The Backprop Fuel</h3>
                    <p>Activation functions must be differentiable for backpropagation to work. Here are the key formulas rendered with proper math notation:</p>

                    <div class="formula" style="text-align:center;">
                        <strong>Sigmoid:</strong> $$\\sigma(z) = \\frac{1}{1 + e^{-z}}, \\quad \\sigma'(z) = \\sigma(z)(1 - \\sigma(z))$$
                        <strong>Tanh:</strong> $$\\tanh(z) = \\frac{e^z - e^{-z}}{e^z + e^{-z}}, \\quad \\tanh'(z) = 1 - \\tanh^2(z)$$
                        <strong>ReLU:</strong> $$\\text{ReLU}(z) = \\max(0, z), \\quad \\text{ReLU}'(z) = \\begin{cases} 1 & z > 0 \\ 0 & z \\leq 0 \\end{cases}$$
                        <strong>Leaky ReLU:</strong> $$\\text{LeakyReLU}(z) = \\begin{cases} z & z > 0 \\ \\alpha z & z \\leq 0 \\end{cases}, \\quad \\alpha = 0.01$$
                        <strong>Softmax:</strong> $$\\text{Softmax}(z_i) = \\frac{e^{z_i}}{\\sum_{j=1}^{K} e^{z_j}}$$
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ The Vanishing Gradient Problem (Proof)</div>
                        Each layer multiplies the gradient by $\\sigma'(z)$. For Sigmoid, $\\max(\\sigma') = 0.25$.<br>
                        For 10 Sigmoid layers: $$\\text{Total gradient} \\approx (0.25)^{10} \\approx 0.00000095$$
                        This is why <strong>ReLU</strong> ($\\text{gradient} = 1$) solved deep learning!
                    </div>

                    <h3>Python: Activation Functions</h3>
                    <span class="code-title">๐Ÿ“„ activations.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn.functional <span class="keyword">as</span> F

x = torch.linspace(-<span class="number">5</span>, <span class="number">5</span>, <span class="number">100</span>)

<span class="comment"># All common activations</span>
relu    = F.relu(x)
sigmoid = torch.sigmoid(x)
tanh    = torch.tanh(x)
leaky   = F.leaky_relu(x, negative_slope=<span class="number">0.01</span>)
gelu    = F.gelu(x)
swish   = x * torch.sigmoid(x)   <span class="comment"># Swish = x * ฯƒ(x)</span>

<span class="comment"># Softmax (on logits)</span>
logits = torch.tensor([<span class="number">2.0</span>, <span class="number">1.0</span>, <span class="number">0.1</span>])
probs = F.softmax(logits, dim=<span class="number">0</span>)
<span class="keyword">print</span>(f<span class="string">"Softmax: {probs}"</span>)  <span class="comment"># [0.659, 0.242, 0.099] โ†’ sums to 1</span>

<span class="comment"># Custom activation in a model</span>
model = torch.nn.Sequential(
    torch.nn.Linear(<span class="number">784</span>, <span class="number">256</span>),
    torch.nn.GELU(),            <span class="comment"># Used in Transformers</span>
    torch.nn.Linear(<span class="number">256</span>, <span class="number">10</span>),
)</div>
                `,
                code: `
                    <h3>All Activation Functions in Python</h3>
                    <p>Let's implement every activation function from scratch using NumPy, then see the PyTorch equivalents.</p>
                    <span class="code-title">๐Ÿ“„ activations_numpy.py</span><div class="code-block"><span class="keyword">import</span> numpy <span class="keyword">as</span> np

<span class="comment"># --- Activation Functions from Scratch ---</span>

<span class="keyword">def</span> <span class="function">sigmoid</span>(z):
    <span class="string">"""Squashes input to (0, 1). Used for binary output."""</span>
    <span class="keyword">return</span> <span class="number">1</span> / (<span class="number">1</span> + np.exp(-z))

<span class="keyword">def</span> <span class="function">sigmoid_derivative</span>(z):
    s = sigmoid(z)
    <span class="keyword">return</span> s * (<span class="number">1</span> - s)  <span class="comment"># Max = 0.25 at z=0</span>

<span class="keyword">def</span> <span class="function">tanh_fn</span>(z):
    <span class="string">"""Squashes input to (-1, 1). Zero-centered."""</span>
    <span class="keyword">return</span> np.tanh(z)

<span class="keyword">def</span> <span class="function">relu</span>(z):
    <span class="string">"""Max(0, z). Default for hidden layers."""</span>
    <span class="keyword">return</span> np.maximum(<span class="number">0</span>, z)

<span class="keyword">def</span> <span class="function">leaky_relu</span>(z, alpha=<span class="number">0.01</span>):
    <span class="string">"""Small gradient when z < 0. Fixes dying ReLU."""</span>
    <span class="keyword">return</span> np.where(z > <span class="number">0</span>, z, alpha * z)

<span class="keyword">def</span> <span class="function">gelu</span>(z):
    <span class="string">"""Used in BERT/GPT. Smooth approximation."""</span>
    <span class="keyword">return</span> <span class="number">0.5</span> * z * (<span class="number">1</span> + np.tanh(np.sqrt(<span class="number">2</span>/np.pi) * (z + <span class="number">0.044715</span> * z**<span class="number">3</span>)))

<span class="keyword">def</span> <span class="function">swish</span>(z):
    <span class="string">"""z * sigmoid(z). Self-gated. Used in EfficientNet."""</span>
    <span class="keyword">return</span> z * sigmoid(z)

<span class="keyword">def</span> <span class="function">softmax</span>(z):
    <span class="string">"""Converts logits to probabilities summing to 1."""</span>
    exp_z = np.exp(z - np.max(z))  <span class="comment"># Numerical stability</span>
    <span class="keyword">return</span> exp_z / exp_z.sum()

<span class="comment"># --- Demo ---</span>
z = np.linspace(-<span class="number">5</span>, <span class="number">5</span>, <span class="number">100</span>)
<span class="keyword">print</span>(<span class="string">"Sigmoid(0) ="</span>, sigmoid(<span class="number">0</span>))          <span class="comment"># 0.5</span>
<span class="keyword">print</span>(<span class="string">"ReLU(-3) ="</span>, relu(-<span class="number">3</span>))              <span class="comment"># 0</span>
<span class="keyword">print</span>(<span class="string">"Leaky ReLU(-3) ="</span>, leaky_relu(-<span class="number">3</span>))  <span class="comment"># -0.03</span>
<span class="keyword">print</span>(<span class="string">"Softmax([2,1,0.1]) ="</span>, softmax(np.array([<span class="number">2</span>, <span class="number">1</span>, <span class="number">0.1</span>])))
</div>

                    <h3>PyTorch Equivalents</h3>
                    <span class="code-title">๐Ÿ“„ activations_pytorch.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> torch.nn.functional <span class="keyword">as</span> F

x = torch.randn(<span class="number">5</span>)

<span class="comment"># Functional API</span>
<span class="keyword">print</span>(<span class="string">"Sigmoid:"</span>, torch.sigmoid(x))
<span class="keyword">print</span>(<span class="string">"ReLU:"</span>, F.relu(x))
<span class="keyword">print</span>(<span class="string">"GELU:"</span>, F.gelu(x))
<span class="keyword">print</span>(<span class="string">"Softmax:"</span>, F.softmax(x, dim=<span class="number">0</span>))

<span class="comment"># In a model (Module API)</span>
model = nn.Sequential(
    nn.Linear(<span class="number">784</span>, <span class="number">256</span>),
    nn.ReLU(),          <span class="comment"># Default for hidden layers</span>
    nn.Linear(<span class="number">256</span>, <span class="number">128</span>),
    nn.GELU(),          <span class="comment"># Used in Transformers</span>
    nn.Linear(<span class="number">128</span>, <span class="number">10</span>),  <span class="comment"># No activation โ€” CrossEntropyLoss includes Softmax</span>
)
</div>
                `
            },
            "conv-layer": {
                overview: `
                <p>Convolution is the <strong>fundamental operation</strong> that makes CNNs work. Instead of connecting every input pixel to every neuron (which would be billions of parameters for an image), a small filter (kernel) <strong>slides across the image</strong>, detecting local patterns like edges, corners, and textures.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ” The Flashlight Analogy</div>
                    Imagine examining a large painting with a small flashlight in a dark room. You can only see a small patch at a time (the receptive field). As you move the flashlight across the painting (the sliding window), you notice patterns โ€” edges, curves, colors. A convolutional layer does exactly this, but with <strong>many flashlights simultaneously</strong>, each looking for a different pattern.
                </div>

                <h3>Key Concepts</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Kernel/Filter:</strong> A small matrix (typically 3ร—3 or 5ร—5) of learnable weights. Each filter detects one type of pattern.</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Stride:</strong> How many pixels the filter moves at each step. Stride=1 means move 1 pixel, stride=2 means skip every other position (halves output size).</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Padding:</strong> Adding zeros around the border so the output has the same spatial size as the input. 'same' padding with 3ร—3 kernel means pad=1.</div></div>
                <div class="list-item"><div class="list-num">4</div><div><strong>Feature Map:</strong> The output of applying one filter to the entire input. 32 filters = 32 feature maps = 32 channels in the output.</div></div>

                <h3>Output Size Formula</h3>
                <div class="formula" style="text-align:center;">
                    $$W_{out} = \\left\\lfloor \\frac{W_{in} + 2p - k}{s} \\right\\rfloor + 1$$
                    Where: $W_{in}$ = input size, $p$ = padding, $k$ = kernel size, $s$ = stride
                </div>
                <p><strong>Example:</strong> Input 32ร—32, kernel 3ร—3, stride 1, padding 1: Output = (32 + 2 - 3)/1 + 1 = <strong>32ร—32</strong> (same size!)</p>

                <h3>Parameter Efficiency: Why CNNs Beat Dense Layers</h3>
                <div class="info-box">
                    <div class="box-title">๐Ÿ“Š Parameter Comparison (32ร—32 RGB Image โ†’ 64 outputs)</div>
                    <div class="box-content">
                        <strong>Dense Layer:</strong> 32 ร— 32 ร— 3 ร— 64 = <span style="color:#ff6b35">196,608 parameters</span><br>
                        <strong>Conv Layer (3ร—3):</strong> 3 ร— 3 ร— 3 ร— 64 + 64 = <span style="color:#00ff88">1,792 parameters</span><br>
                        <strong>Savings: 110x fewer parameters!</strong> This is thanks to weight sharing and local connectivity.
                    </div>
                </div>
`,
                concepts: `
                    <h3>Key Hyperparameters</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Kernel/Filter Size:</strong> Typically 3ร—3 or 5ร—5. Smaller = more layers needed, larger = more parameters</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Stride:</strong> Step size when sliding filter. Stride=1 (preserves size), Stride=2 (downsamples by 2ร—)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Padding:</strong> Add zeros around borders. 'SAME' keeps size, 'VALID' shrinks output</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Number of Filters:</strong> Each filter learns different features. More filters = more capacity but slower</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Dilation:</strong> Spacing between kernel elements. Increases receptive field without adding parameters</div>
                    </div>

                    <div class="formula">
                        Output Size Formula:<br>
                        W_out = floor((W_in + 2ร—padding - kernel_size) / stride) + 1<br>
                        H_out = floor((H_in + 2ร—padding - kernel_size) / stride) + 1
                    </div>
                `,
                math: `
                    <h3>The Mathematical Operation: Cross-Correlation</h3>
                    <p>In deep learning, what we call "convolution" is mathematically "cross-correlation". It is a local dot product of the kernel and image patch.</p>
                    
                    <div class="formula">
                        S(i, j) = (I * K)(i, j) = ฮฃ_m ฮฃ_n I(i+m, j+n) K(m, n)
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Manual Convolution</div>
                        **Input (3x3):**<br>
                        [1 2 0]<br>
                        [0 1 1]<br>
                        [1 0 2]<br>
                        <br>
                        **Kernel (2x2):**<br>
                        [1 0]<br>
                        [0 1]<br>
                        <br>
                        **Calculation:**<br>
                        Step 1 (Top-Left): (1x1) + (2x0) + (0x0) + (1x1) = <strong>2</strong><br>
                        Step 2 (Top-Right): (2x1) + (0x0) + (1x0) + (1x1) = <strong>3</strong><br>
                        ... Output is a 2x2 matrix.
                    </div>

                    <h3>Backprop through Conv</h3>
                    <p>Calculated using the same formula but with the kernel flipped vertically and horizontally (true convolution)!</p>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Feature Extraction</div>
                        <div class="box-content">
                            Early layers learn edges (Gabor-like filters), middle layers learn textures, deep layers learn specific object parts (eyes, wheels).
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽจ Image Processing</div>
                        <div class="box-content">
                            Blurring, sharpening, and edge detection in Photoshop/GIMP are all done with 2D convolutions using fixed kernels.
                        </div>
                    </div>
                `,
                code: `
                    <h3>Convolution Math</h3>
                    <div class="formula" style="text-align:center;">
                        <strong>Output Size:</strong> $$W_{out} = \\left\\lfloor \\frac{W_{in} + 2p - k}{s} \\right\\rfloor + 1$$
                        Where $p$ = padding, $k$ = kernel size, $s$ = stride.
                    </div>
                    <h3>Complete CNN Classifier (CIFAR-10)</h3>
<span class="code-title">๐Ÿ“„ cnn_cifar10.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> torchvision
<span class="keyword">import</span> torchvision.transforms <span class="keyword">as</span> T

<span class="comment"># --- Data Loading ---</span>
transform = T.Compose([T.ToTensor(), T.Normalize((<span class="number">0.5</span>,<span class="number">0.5</span>,<span class="number">0.5</span>), (<span class="number">0.5</span>,<span class="number">0.5</span>,<span class="number">0.5</span>))])
trainset = torchvision.datasets.CIFAR10(root=<span class="string">"./data"</span>, train=<span class="keyword">True</span>, download=<span class="keyword">True</span>, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=<span class="number">64</span>, shuffle=<span class="keyword">True</span>)

<span class="comment"># --- CNN Model ---</span>
<span class="keyword">class</span> <span class="class-name">CNN</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self):
        <span class="builtin">super</span>().__init__()
        self.features = nn.Sequential(
            nn.Conv2d(<span class="number">3</span>, <span class="number">32</span>, <span class="number">3</span>, padding=<span class="number">1</span>),   <span class="comment"># 32x32 โ†’ 32x32</span>
            nn.BatchNorm2d(<span class="number">32</span>), nn.ReLU(),
            nn.MaxPool2d(<span class="number">2</span>),                    <span class="comment"># โ†’ 16x16</span>
            nn.Conv2d(<span class="number">32</span>, <span class="number">64</span>, <span class="number">3</span>, padding=<span class="number">1</span>),  <span class="comment"># โ†’ 16x16</span>
            nn.BatchNorm2d(<span class="number">64</span>), nn.ReLU(),
            nn.MaxPool2d(<span class="number">2</span>),                    <span class="comment"># โ†’ 8x8</span>
            nn.Conv2d(<span class="number">64</span>, <span class="number">128</span>, <span class="number">3</span>, padding=<span class="number">1</span>), <span class="comment"># โ†’ 8x8</span>
            nn.BatchNorm2d(<span class="number">128</span>), nn.ReLU(),
            nn.AdaptiveAvgPool2d(<span class="number">1</span>),             <span class="comment"># โ†’ 1x1</span>
        )
        self.classifier = nn.Linear(<span class="number">128</span>, <span class="number">10</span>)
    
    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        x = self.features(x)
        x = x.view(x.size(<span class="number">0</span>), -<span class="number">1</span>)
        <span class="keyword">return</span> self.classifier(x)

model = CNN()
<span class="keyword">print</span>(f<span class="string">"Parameters: {sum(p.numel() for p in model.parameters()):,}"</span>)</div>
                `
            },
            "yolo": {
                overview: `
                    <h3>What is YOLO?</h3>
                    <p>YOLO (You Only Look Once) treats object detection as a single regression problem, going directly from image pixels to bounding box coordinates and class probabilities in one forward pass.</p>
                    
                    <h3>Why YOLO Over R-CNN?</h3>
                    <ul>
                        <li><strong>Speed:</strong> 45+ FPS (real-time) vs R-CNN's ~0.05 FPS</li>
                        <li><strong>Global Context:</strong> Sees entire image during training (fewer background errors)</li>
                        <li><strong>One Network:</strong> Unlike R-CNN's multi-stage pipeline</li>
                        <li><strong>End-to-End Training:</strong> Optimize detection directly</li>
                    </ul>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… Advantages</div>
                        โ€ข <strong>Lightning Fast:</strong> Real-time inference (YOLOv8 at 100+ FPS)<br>
                        โ€ข <strong>Simple Architecture:</strong> Single network, easy to train<br>
                        โ€ข <strong>Generalizes Well:</strong> Works on natural images and artwork<br>
                        โ€ข <strong>Small Model Size:</strong> Can run on edge devices (mobile, IoT)
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Disadvantages</div>
                        โ€ข <strong>Struggles with Small Objects:</strong> Grid limitation affects tiny items<br>
                        โ€ข <strong>Localization Errors:</strong> Less precise than two-stage detectors<br>
                        โ€ข <strong>Limited Objects per Cell:</strong> Can't detect many close objects<br>
                        โ€ข <strong>Aspect Ratio Issues:</strong> Struggles with unusual object shapes
                    </div>
                    
                    <h3>YOLO Evolution</h3>
                    <table>
                        <tr>
                            <th>Version</th>
                            <th>Year</th>
                            <th>Key Innovation</th>
                            <th>mAP</th>
                        </tr>
                        <tr>
                            <td>YOLOv1</td>
                            <td>2015</td>
                            <td>Original single-shot detector</td>
                            <td>63.4%</td>
                        </tr>
                        <tr>
                            <td>YOLOv3</td>
                            <td>2018</td>
                            <td>Multi-scale predictions</td>
                            <td>57.9% (faster)</td>
                        </tr>
                        <tr>
                            <td>YOLOv5</td>
                            <td>2020</td>
                            <td>PyTorch, Auto-augment</td>
                            <td>~50% (optimized)</td>
                        </tr>
                        <tr>
                            <td>YOLOv8</td>
                            <td>2023</td>
                            <td>Anchor-free, SOTA speed</td>
                            <td>53.9% (real-time)</td>
                        </tr>
                    </table>
                `,
                concepts: `
                    <h3>How YOLO Works (3 Steps)</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Grid Division:</strong> Divide image into Sร—S grid (e.g., 7ร—7). Each cell predicts B bounding boxes</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Predictions Per Cell:</strong> Each box predicts (x, y, w, h, confidence) + class probabilities</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Non-Max Suppression:</strong> Remove duplicate detections, keep highest confidence boxes</div>
                    </div>
                    
                    <div class="formula">
                        Output Tensor Shape (YOLOv1):<br>
                        S ร— S ร— (B ร— 5 + C)<br>
                        Example: 7 ร— 7 ร— (2 ร— 5 + 20) = 7 ร— 7 ร— 30<br>
                        <br>
                        Where:<br>
                        โ€ข S = grid size (7)<br>
                        โ€ข B = boxes per cell (2)<br>
                        โ€ข 5 = (x, y, w, h, confidence)<br>
                        โ€ข C = number of classes (20 for PASCAL VOC)
                    </div>
                `,
                applications: `
                    <h3>Industry Applications</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿš— Autonomous Vehicles</div>
                        <div class="box-content">
                            Real-time detection of pedestrians, vehicles, traffic signs, and lane markings for self-driving cars
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿญ Manufacturing</div>
                        <div class="box-content">
                            Quality control, defect detection on assembly lines, robot guidance, inventory management
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ›ก๏ธ Security & Surveillance</div>
                        <div class="box-content">
                            Intrusion detection, crowd monitoring, suspicious behavior analysis, license plate recognition
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Medical Imaging</div>
                        <div class="box-content">
                            Tumor localization, cell counting, anatomical structure detection in X-rays/CT scans
                        </div>
                    </div>
                `,
                math: `
                    <h3>Intersection over Union (IoU)</h3>
                    <p>How do we measure if a predicted box is correct? We use the geometric ratio of intersection and union.</p>
                    <div class="formula">
                        IoU = Area of Overlap / Area of Union
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Manual IoU</div>
                        **Box A (GT):** [0,0,10,10] (Area=100)<br>
                        **Box B (Pred):** [5,5,15,15] (Area=100)<br>
                        1. **Intersection:** Area between [5,5] and [10,10] = 5x5 = 25<br>
                        2. **Union:** Area A + Area B - Intersection = 100 + 100 - 25 = 175<br>
                        3. **IoU:** 25 / 175 โ‰ˆ <strong>0.142</strong> (Poor match!)
                    </div>

                    <h3>YOLO Multi-Part Loss</h3>
                    <p>YOLO uses a composite loss function combining localization, confidence, and classification errors.</p>
                    <div class="formula">
                        L = ฮป_coord ฮฃ(Localization Loss) + ฮฃ(Confidence Loss) + ฮฃ(Classification Loss)
                    </div>
                `
            },
            "transformers": {
                overview: `
                <p>The Transformer architecture, introduced in the 2017 paper <strong>"Attention Is All You Need"</strong>, is the foundation of modern AI. GPT, BERT, LLaMA, DALL-E, Stable Diffusion โ€” they all use Transformers. The key innovation: <strong>self-attention</strong>, which lets every token in a sequence directly attend to every other token.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽญ The Conference Room Analogy</div>
                    Imagine a meeting where everyone can hear everyone else simultaneously (unlike RNNs where information passes person-to-person in a chain). Each person (token) decides who to pay attention to based on relevance. The CEO might focus on the CFO for budget discussions but the CTO for technical decisions. This dynamic, context-dependent attention is what Transformers do.
                </div>

                <h3>Transformer Architecture</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Input Embedding + Positional Encoding:</strong> Convert tokens to vectors and add position information (since attention has no inherent sense of order)</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Multi-Head Self-Attention:</strong> Each head learns a different type of relationship. Head 1 might learn syntactic dependencies, Head 2 might learn semantic similarity.</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Feed-Forward Network:</strong> A two-layer MLP applied independently to each position. This is where most of the model's "knowledge" is stored.</div></div>
                <div class="list-item"><div class="list-num">4</div><div><strong>Layer Normalization + Residual Connections:</strong> Applied around each sub-layer to stabilize training.</div></div>

                <h3>Self-Attention: The Heart of Transformers</h3>
                <div class="formula" style="text-align:center;">
                    $$\\text{Attention}(Q, K, V) = \\text{softmax}\\left(\\frac{QK^T}{\\sqrt{d_k}}\\right)V$$
                </div>
                <p><strong>Q (Query):</strong> "What am I looking for?"<br>
                <strong>K (Key):</strong> "What do I contain?"<br>
                <strong>V (Value):</strong> "What information do I provide?"</p>
                <p>The $\\sqrt{d_k}$ scaling prevents the dot products from becoming too large (which would make softmax saturate and kill gradients).</p>

                <h3>Why Transformers Beat RNNs</h3>
                <div class="info-box">
                    <div class="box-title">Speed & Power Comparison</div>
                    <div class="box-content">
                        <strong>Parallelization:</strong> RNNs process tokens sequentially (slow). Transformers process all tokens at once (fast). GPT-3 training would take 355 years with RNNs.<br>
                        <strong>Long-range dependencies:</strong> RNNs lose information over long sequences. Transformers can attend to any position directly.<br>
                        <strong>Scalability:</strong> Transformers scale to billions of parameters with predictable improvements (scaling laws).
                    </div>
                </div>
`,
                concepts: `
                    <h3>๐Ÿ—๏ธ Complete Architecture Overview</h3>
                    <p>The Transformer follows an <strong>Encoder-Decoder</strong> structure, but each component uses only attention mechanisms.</p>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ฆ Model Hyperparameters (Base Model)</div>
                        <div class="box-content">
                            โ€ข <strong>d_model = 512:</strong> Embedding dimension<br>
                            โ€ข <strong>d_ff = 2048:</strong> Feed-forward hidden dimension<br>
                            โ€ข <strong>h = 8:</strong> Number of attention heads<br>
                            โ€ข <strong>d_k = d_v = 64:</strong> Key/Value dimensions (d_model / h)<br>
                            โ€ข <strong>N = 6:</strong> Number of encoder AND decoder layers<br>
                            โ€ข <strong>Total Parameters:</strong> ~65 million
                        </div>
                    </div>
                    
                    <h3>Core Components</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Input Embedding:</strong> Convert tokens to d_model dimensional vectors, scaled by โˆšd_model</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Positional Encoding:</strong> Add sinusoidal position signals so attention knows token order</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Multi-Head Self-Attention:</strong> h parallel attention heads, each computing different relationships</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Add & Norm:</strong> Residual connection followed by Layer Normalization</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Feed-Forward Network:</strong> Two linear layers with ReLU: FFN(x) = max(0, xWโ‚ + bโ‚)Wโ‚‚ + bโ‚‚</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div><strong>Masked Attention (Decoder):</strong> Prevent attending to future tokens during training</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">07</div>
                        <div><strong>Encoder-Decoder Attention:</strong> Decoder attends to encoder output (cross-attention)</div>
                    </div>
                    
                    <h3>Encoder Stack (N=6 layers)</h3>
                    <div class="formula">
                        Each encoder layer:<br>
                        sublayer_1 = LayerNorm(x + MultiHeadAttention(x, x, x))<br>
                        sublayer_2 = LayerNorm(sublayer_1 + FFN(sublayer_1))<br>
                        <br>
                        The encoder processes the input sequence bidirectionally.<br>
                        All positions can attend to all positions.
                    </div>
                    
                    <h3>Decoder Stack (N=6 layers)</h3>
                    <div class="formula">
                        Each decoder layer has THREE sub-layers:<br>
                        1. Masked Self-Attention (prevent looking ahead)<br>
                        2. Encoder-Decoder Attention (attend to encoder output)<br>
                        3. Feed-Forward Network<br>
                        <br>
                        Output: LayerNorm(x + sublayer(x)) for each
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก Key Insight: Residual Connections</div>
                        Every sub-layer has a residual connection: <strong>output = x + Sublayer(x)</strong><br>
                        This is crucial for:<br>
                        1. Training very deep models (gradient highway)<br>
                        2. Preserving information across layers<br>
                        3. Enabling optional "skipping" of transformations
                    </div>
                `,
                applications: `
                    <h3>๐ŸŒ Revolutionary Applications</h3>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ฌ Large Language Models</div>
                        <div class="box-content">
                            <strong>GPT-4, Claude, Gemini:</strong> The most capable AI systems ever built<br>
                            <strong>ChatGPT:</strong> 100M+ users in 2 months (fastest product adoption ever)<br>
                            <strong>BERT:</strong> Powers Google Search for 70+ languages
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐ŸŒ Machine Translation (Original Use Case)</div>
                        <div class="box-content">
                            <strong>Google Translate:</strong> Switched to Transformers in 2017<br>
                            <strong>DeepL:</strong> Transformer-based, often beats Google<br>
                            <strong>NLLB-200:</strong> Meta's model translates 200 languages
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐ŸŽจ Multi-Modal AI</div>
                        <div class="box-content">
                            <strong>DALL-E 3, Midjourney, Stable Diffusion:</strong> Text-to-image generation<br>
                            <strong>GPT-4V, Gemini:</strong> Vision + Language understanding<br>
                            <strong>Whisper:</strong> State-of-the-art speech recognition<br>
                            <strong>Sora:</strong> Text-to-video generation
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿงฌ Scientific Breakthroughs</div>
                        <div class="box-content">
                            <strong>AlphaFold 2:</strong> Solved 50-year protein folding problem (Nobel Prize 2024)<br>
                            <strong>ESMFold:</strong> Meta's protein predictor<br>
                            <strong>Drug Discovery:</strong> Accelerating molecule design
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ป Code & Development</div>
                        <div class="box-content">
                            <strong>GitHub Copilot:</strong> AI pair programmer (used by millions of devs)<br>
                            <strong>Claude Code, Cursor:</strong> AI coding assistants<br>
                            <strong>AlphaCode:</strong> Competitive programming solver
                        </div>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ“ˆ Impact Statistics</div>
                        โ€ข Paper has 100,000+ citations (one of most cited CS papers ever)<br>
                        โ€ข Spawned multi-trillion dollar industry<br>
                        โ€ข Every major AI lab now uses Transformer variants<br>
                        โ€ข Considered the "ImageNet moment" for NLP
                    </div>
                `,
                math: `
                    <h3>๐Ÿ“ Paper & Pain: Complete Mathematical Derivation</h3>
                    <p>Let's derive every formula from the paper with step-by-step calculations.</p>
                    
                    <h3>1. Scaled Dot-Product Attention</h3>
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>Attention(Q, K, V) = softmax(QKแต€ / โˆšdโ‚–) V</strong>
                    </div>
                    
                    <h4>Step-by-Step Derivation:</h4>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div>
                            <strong>Create Q, K, V matrices:</strong><br>
                            Given input X โˆˆ โ„โฟหฃแตˆ (n tokens, d dimensions)<br>
                            Q = XWแต , K = XWแดท, V = XWโฑฝ<br>
                            where Wแต , Wแดท โˆˆ โ„แตˆหฃแตˆแต and Wโฑฝ โˆˆ โ„แตˆหฃแตˆแต›
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div>
                            <strong>Compute Attention Scores:</strong><br>
                            scores = QKแต€ โˆˆ โ„โฟหฃโฟ<br>
                            Each score[i,j] = dot product of query_i and key_j<br>
                            Measures "how much should position i attend to position j"
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div>
                            <strong>Scale by โˆšdโ‚–:</strong><br>
                            scaled_scores = QKแต€ / โˆšdโ‚–<br>
                            <em>Why scale?</em> Dot products grow with dimension. If dโ‚– = 64:<br>
                            E[qแต€k] = 0, Var[qแต€k] = dโ‚– = 64<br>
                            Without scaling, softmax saturates โ†’ vanishing gradients!
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div>
                            <strong>Apply Softmax:</strong><br>
                            attention_weights = softmax(scaled_scores) โˆˆ โ„โฟหฃโฟ<br>
                            Each row sums to 1 (probability distribution over positions)
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div>
                            <strong>Weighted Sum of Values:</strong><br>
                            output = attention_weights ร— V โˆˆ โ„โฟหฃแตˆแต›<br>
                            Each output[i] is a weighted combination of all values
                        </div>
                    </div>
                    
                    <h3>2. Multi-Head Attention</h3>
                    <div class="formula" style="background: rgba(255, 107, 53, 0.08); padding: 20px; border-radius: 8px;">
                        MultiHead(Q, K, V) = Concat(headโ‚, ..., headโ‚•)Wแดผ<br>
                        where headแตข = Attention(QWแตขแต , KWแตขแดท, VWแตขโฑฝ)<br><br>
                        
                        <strong>Paper's values:</strong><br>
                        h = 8 heads, dโ‚– = dแตฅ = d_model/h = 512/8 = 64<br>
                        Wแดผ โˆˆ โ„โฝสฐยทแตˆแต›โพหฃแตˆแตแต’แตˆแต‰หก = โ„โตยนยฒหฃโตยนยฒ
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก Why Multiple Heads?</div>
                        Each head can learn <strong>different relationships</strong>:<br>
                        โ€ข Head 1: Syntactic dependencies (subject-verb)<br>
                        โ€ข Head 2: Pronoun resolution (he โ†’ John)<br>
                        โ€ข Head 3: Semantic similarity<br>
                        โ€ข Head 4-8: Other patterns<br>
                        <br>
                        <strong>Computation:</strong> Same cost as single-head with full dโ‚–!<br>
                        8 heads ร— 64 dim = 1 head ร— 512 dim (same FLOPs)
                    </div>
                    
                    <h3>3. Positional Encoding (Sinusoidal)</h3>
                    <div class="formula" style="background: rgba(46, 204, 113, 0.08); padding: 20px; border-radius: 8px;">
                        PE(pos, 2i) = sin(pos / 10000^(2i/d_model))<br>
                        PE(pos, 2i+1) = cos(pos / 10000^(2i/d_model))<br><br>
                        
                        pos = position in sequence (0, 1, 2, ...)<br>
                        i = dimension index (0, 1, ..., d_model/2 - 1)
                    </div>
                    
                    <h4>Worked Example (d_model = 4):</h4>
                    <div class="formula" style="background: var(--surface); padding: 15px;">
                        For position pos = 0:<br>
                        PE(0, 0) = sin(0) = 0<br>
                        PE(0, 1) = cos(0) = 1<br>
                        PE(0, 2) = sin(0) = 0<br>
                        PE(0, 3) = cos(0) = 1<br>
                        โ†’ PEโ‚€ = [0, 1, 0, 1]<br><br>
                        
                        For position pos = 1:<br>
                        PE(1, 0) = sin(1/10000โฐ) = sin(1) โ‰ˆ 0.84<br>
                        PE(1, 1) = cos(1/10000โฐ) = cos(1) โ‰ˆ 0.54<br>
                        PE(1, 2) = sin(1/100) โ‰ˆ 0.01<br>
                        PE(1, 3) = cos(1/100) โ‰ˆ 1.00<br>
                        โ†’ PEโ‚ = [0.84, 0.54, 0.01, 1.00]
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">๐Ÿ”‘ Key Property: Relative Positions</div>
                        PE(pos + k) can be expressed as a <strong>linear function</strong> of PE(pos)!<br>
                        This allows the model to easily learn relative position attention.<br>
                        sin(a+b) = sin(a)cos(b) + cos(a)sin(b) โœ“
                    </div>
                    
                    <h3>4. Feed-Forward Network</h3>
                    <div class="formula">
                        FFN(x) = max(0, xWโ‚ + bโ‚)Wโ‚‚ + bโ‚‚<br><br>
                        
                        Wโ‚ โˆˆ โ„แตˆแตแต’แตˆแต‰หก หฃ แตˆแถ แถ  = โ„โตยนยฒ หฃ ยฒโฐโดโธ (expand 4ร—)<br>
                        Wโ‚‚ โˆˆ โ„แตˆแถ แถ  หฃ แตˆแตแต’แตˆแต‰หก = โ„ยฒโฐโดโธ หฃ โตยนยฒ (project back)<br><br>
                        
                        This is a 2-layer MLP with ReLU, applied to each position independently.
                    </div>
                    
                    <h3>5. Layer Normalization</h3>
                    <div class="formula">
                        LayerNorm(x) = ฮณ โŠ™ (x - ฮผ) / โˆš(ฯƒยฒ + ฮต) + ฮฒ<br><br>
                        
                        ฮผ = (1/d) ฮฃแตข xแตข (mean across features)<br>
                        ฯƒยฒ = (1/d) ฮฃแตข (xแตข - ฮผ)ยฒ (variance)<br>
                        ฮณ, ฮฒ: learnable scale and shift (per feature)
                    </div>
                    
                    <h3>6. Training Details from Paper</h3>
                    <div class="info-box">
                        <div class="box-title">โš™๏ธ Optimization Settings</div>
                        <div class="box-content">
                            <strong>Optimizer:</strong> Adam with ฮฒโ‚=0.9, ฮฒโ‚‚=0.98, ฮต=10โปโน<br>
                            <strong>Learning Rate Schedule:</strong><br>
                            lr = d_modelโปโฐยทโต ร— min(stepโปโฐยทโต, step ร— warmup_stepsโปยนยทโต)<br>
                            warmup_steps = 4000<br><br>
                            <strong>Regularization:</strong><br>
                            โ€ข Dropout = 0.1 (on sublayers and embeddings)<br>
                            โ€ข Label Smoothing = 0.1
                        </div>
                    </div>
                    
                    <h3>7. Complexity Analysis</h3>
                    <table>
                        <tr>
                            <th>Layer Type</th>
                            <th>Complexity per Layer</th>
                            <th>Sequential Ops</th>
                            <th>Max Path Length</th>
                        </tr>
                        <tr>
                            <td>Self-Attention</td>
                            <td>O(nยฒ ยท d)</td>
                            <td>O(1)</td>
                            <td>O(1)</td>
                        </tr>
                        <tr>
                            <td>Recurrent (RNN)</td>
                            <td>O(n ยท dยฒ)</td>
                            <td>O(n)</td>
                            <td>O(n)</td>
                        </tr>
                        <tr>
                            <td>Convolutional</td>
                            <td>O(k ยท n ยท dยฒ)</td>
                            <td>O(1)</td>
                            <td>O(logโ‚–(n))</td>
                        </tr>
                    </table>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽฏ Key Insight from the Paper</div>
                        Self-attention is the only architecture with <strong>O(1) path length</strong><br>
                        between any two positions! This is why it handles long-range<br>
                        dependencies so well. The tradeoff is O(nยฒ) memory.
                    </div>
                `,
                visualization: `
                    <h3>๐ŸŽจ Interactive Transformer Visualization</h3>
                    <p>Explore how attention mechanisms work in the Transformer architecture.</p>
                    
                    <div class="viz-container">
                        <canvas id="transformerViz" width="800" height="600"></canvas>
                    </div>
                    
                    <div class="viz-controls">
                        <button class="btn-viz" onclick="visualizeAttention()">Show Attention Weights</button>
                        <button class="btn-viz" onclick="visualizeMultiHead()">Multi-Head Attention</button>
                        <button class="btn-viz" onclick="visualizePositional()">Positional Encoding</button>
                        <button class="btn-viz" onclick="visualizeArchitecture()">Full Architecture</button>
                    </div>
                    
                    <h3>Code: Self-Attention in PyTorch</h3>
                    <div class="formula" style="font-family: 'Courier New', monospace; font-size: 0.9rem; background: #1e1e2e; padding: 20px; border-radius: 8px; overflow-x: auto;">
<pre style="margin: 0; color: #cdd6f4;">
<span style="color: #89b4fa;">import</span> torch
<span style="color: #89b4fa;">import</span> torch.nn <span style="color: #89b4fa;">as</span> nn
<span style="color: #89b4fa;">import</span> torch.nn.functional <span style="color: #89b4fa;">as</span> F
<span style="color: #89b4fa;">import</span> math

<span style="color: #89b4fa;">class</span> <span style="color: #f9e2af;">ScaledDotProductAttention</span>(nn.Module):
    <span style="color: #a6e3a1;">\"\"\"Attention(Q, K, V) = softmax(QK^T / sqrt(d_k)) V\"\"\"</span>
    
    <span style="color: #89b4fa;">def</span> <span style="color: #f9e2af;">forward</span>(self, Q, K, V, mask=<span style="color: #fab387;">None</span>):
        d_k = Q.size(-1)
        
        <span style="color: #6c7086;"># Step 1: Compute attention scores</span>
        scores = torch.matmul(Q, K.transpose(-2, -1))
        
        <span style="color: #6c7086;"># Step 2: Scale by sqrt(d_k)</span>
        scores = scores / math.sqrt(d_k)
        
        <span style="color: #6c7086;"># Step 3: Apply mask (for decoder)</span>
        <span style="color: #89b4fa;">if</span> mask <span style="color: #89b4fa;">is not</span> <span style="color: #fab387;">None</span>:
            scores = scores.masked_fill(mask == <span style="color: #fab387;">0</span>, <span style="color: #fab387;">-1e9</span>)
        
        <span style="color: #6c7086;"># Step 4: Apply softmax</span>
        attention_weights = F.softmax(scores, dim=-1)
        
        <span style="color: #6c7086;"># Step 5: Weighted sum of values</span>
        output = torch.matmul(attention_weights, V)
        
        <span style="color: #89b4fa;">return</span> output, attention_weights


<span style="color: #89b4fa;">class</span> <span style="color: #f9e2af;">MultiHeadAttention</span>(nn.Module):
    <span style="color: #a6e3a1;">\"\"\"Multi-Head Attention from 'Attention Is All You Need'\"\"\"</span>
    
    <span style="color: #89b4fa;">def</span> <span style="color: #f9e2af;">__init__</span>(self, d_model=<span style="color: #fab387;">512</span>, n_heads=<span style="color: #fab387;">8</span>):
        <span style="color: #89b4fa;">super</span>().__init__()
        self.d_model = d_model
        self.n_heads = n_heads
        self.d_k = d_model // n_heads  <span style="color: #6c7086;"># 64</span>
        
        <span style="color: #6c7086;"># Linear projections for Q, K, V</span>
        self.W_Q = nn.Linear(d_model, d_model)
        self.W_K = nn.Linear(d_model, d_model)
        self.W_V = nn.Linear(d_model, d_model)
        self.W_O = nn.Linear(d_model, d_model)
        
        self.attention = ScaledDotProductAttention()
    
    <span style="color: #89b4fa;">def</span> <span style="color: #f9e2af;">forward</span>(self, Q, K, V, mask=<span style="color: #fab387;">None</span>):
        batch_size = Q.size(<span style="color: #fab387;">0</span>)
        
        <span style="color: #6c7086;"># 1. Linear projection and split into h heads</span>
        Q = self.W_Q(Q).view(batch_size, -1, self.n_heads, self.d_k).transpose(1, 2)
        K = self.W_K(K).view(batch_size, -1, self.n_heads, self.d_k).transpose(1, 2)
        V = self.W_V(V).view(batch_size, -1, self.n_heads, self.d_k).transpose(1, 2)
        
        <span style="color: #6c7086;"># 2. Apply attention to all heads in parallel</span>
        x, attn = self.attention(Q, K, V, mask)
        
        <span style="color: #6c7086;"># 3. Concat and final linear projection</span>
        x = x.transpose(1, 2).contiguous().view(batch_size, -1, self.d_model)
        
        <span style="color: #89b4fa;">return</span> self.W_O(x), attn


<span style="color: #89b4fa;">class</span> <span style="color: #f9e2af;">PositionalEncoding</span>(nn.Module):
    <span style="color: #a6e3a1;">\"\"\"Sinusoidal Positional Encoding from the paper\"\"\"</span>
    
    <span style="color: #89b4fa;">def</span> <span style="color: #f9e2af;">__init__</span>(self, d_model=<span style="color: #fab387;">512</span>, max_len=<span style="color: #fab387;">5000</span>):
        <span style="color: #89b4fa;">super</span>().__init__()
        pe = torch.zeros(max_len, d_model)
        position = torch.arange(<span style="color: #fab387;">0</span>, max_len, dtype=torch.float).unsqueeze(<span style="color: #fab387;">1</span>)
        div_term = torch.exp(torch.arange(<span style="color: #fab387;">0</span>, d_model, <span style="color: #fab387;">2</span>).float() * (-math.log(<span style="color: #fab387;">10000.0</span>) / d_model))
        
        pe[:, <span style="color: #fab387;">0</span>::<span style="color: #fab387;">2</span>] = torch.sin(position * div_term)
        pe[:, <span style="color: #fab387;">1</span>::<span style="color: #fab387;">2</span>] = torch.cos(position * div_term)
        pe = pe.unsqueeze(<span style="color: #fab387;">0</span>)  <span style="color: #6c7086;"># [1, max_len, d_model]</span>
        
        self.register_buffer(<span style="color: #a6e3a1;">'pe'</span>, pe)
    
    <span style="color: #89b4fa;">def</span> <span style="color: #f9e2af;">forward</span>(self, x):
        <span style="color: #89b4fa;">return</span> x + self.pe[:, :x.size(<span style="color: #fab387;">1</span>)]


<span style="color: #6c7086;"># Example usage:</span>
batch_size, seq_len, d_model = <span style="color: #fab387;">2</span>, <span style="color: #fab387;">10</span>, <span style="color: #fab387;">512</span>
x = torch.randn(batch_size, seq_len, d_model)

mha = MultiHeadAttention(d_model=<span style="color: #fab387;">512</span>, n_heads=<span style="color: #fab387;">8</span>)
pe = PositionalEncoding(d_model=<span style="color: #fab387;">512</span>)

x = pe(x)  <span style="color: #6c7086;"># Add positional encoding</span>
output, attn_weights = mha(x, x, x)  <span style="color: #6c7086;"># Self-attention</span>

<span style="color: #89b4fa;">print</span>(f<span style="color: #a6e3a1;">"Output shape: {output.shape}"</span>)  <span style="color: #6c7086;"># [2, 10, 512]</span>
<span style="color: #89b4fa;">print</span>(f<span style="color: #a6e3a1;">"Attention shape: {attn_weights.shape}"</span>)  <span style="color: #6c7086;"># [2, 8, 10, 10]</span>
</pre>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽ“ Run This Code!</div>
                        Copy the code above and run it in a Jupyter notebook or Google Colab.<br>
                        Experiment with different d_model, n_heads, and seq_len values!
                    </div>
                `,
                code: `
                    <h3>Self-Attention (Scaled Dot-Product)</h3>
                    <div class="formula" style="text-align:center;">
                        $$\\text{Attention}(Q, K, V) = \\text{softmax}\\left(\\frac{QK^T}{\\sqrt{d_k}}\\right)V$$
                        Where $Q = XW^Q$, $K = XW^K$, $V = XW^V$
                    </div>
                    <div class="formula" style="text-align:center;">
                        <strong>Multi-Head:</strong> $$\\text{MultiHead}(Q,K,V) = \\text{Concat}(head_1, ..., head_h)W^O$$
                        <strong>Positional Encoding:</strong> $$PE_{(pos, 2i)} = \\sin(pos / 10000^{2i/d}), \\quad PE_{(pos, 2i+1)} = \\cos(pos / 10000^{2i/d})$$
                    </div>
<span class="code-title">๐Ÿ“„ transformer_from_scratch.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> math

<span class="keyword">class</span> <span class="class-name">SelfAttention</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self, d_model, n_heads):
        <span class="builtin">super</span>().__init__()
        self.d_k = d_model // n_heads
        self.n_heads = n_heads
        self.W_q = nn.Linear(d_model, d_model)
        self.W_k = nn.Linear(d_model, d_model)
        self.W_v = nn.Linear(d_model, d_model)
        self.W_o = nn.Linear(d_model, d_model)
    
    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        B, T, C = x.shape
        Q = self.W_q(x).view(B, T, self.n_heads, self.d_k).transpose(<span class="number">1</span>,<span class="number">2</span>)
        K = self.W_k(x).view(B, T, self.n_heads, self.d_k).transpose(<span class="number">1</span>,<span class="number">2</span>)
        V = self.W_v(x).view(B, T, self.n_heads, self.d_k).transpose(<span class="number">1</span>,<span class="number">2</span>)
        
        <span class="comment"># Scaled Dot-Product Attention</span>
        scores = (Q @ K.transpose(-<span class="number">2</span>,-<span class="number">1</span>)) / math.sqrt(self.d_k)
        attn = torch.softmax(scores, dim=-<span class="number">1</span>)
        out = (attn @ V).transpose(<span class="number">1</span>,<span class="number">2</span>).reshape(B, T, C)
        <span class="keyword">return</span> self.W_o(out)

<span class="comment"># Test</span>
attn = SelfAttention(d_model=<span class="number">512</span>, n_heads=<span class="number">8</span>)
x = torch.randn(<span class="number">2</span>, <span class="number">10</span>, <span class="number">512</span>)  <span class="comment"># (batch, seq_len, d_model)</span>
<span class="keyword">print</span>(attn(x).shape)  <span class="comment"># (2, 10, 512)</span></div>
                `
            },
            "perceptron": {
                overview: `
                    <h3>What is a Perceptron?</h3>
                    <p>The perceptron is the simplest neural network, invented in 1958. It's a binary linear classifier that makes predictions based on weighted inputs.</p>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… Advantages</div>
                        โ€ข Simple and fast<br>
                        โ€ข Guaranteed convergence for linearly separable data<br>
                        โ€ข Interpretable weights
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Key Limitation</div>
                        <strong>Cannot solve XOR:</strong> Limited to linear decision boundaries only
                    </div>
                `,
                concepts: `
                    <h3>How Perceptron Works</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Weighted Sum:</strong> z = wโ‚xโ‚ + wโ‚‚xโ‚‚ + ... + b</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Step Function:</strong> Output = 1 if z โ‰ฅ 0, else 0</div>
                    </div>
                    <div class="formula">
                        Learning Rule: w_new = w_old + ฮฑ(y_true - y_pred)x
                    </div>
                `,
                math: `
                    <h3>Perceptron Learning Algorithm</h3>
                    <p>The perceptron update rule is the simplest form of gradient descent.</p>
                    
                    <div class="formula">
                        For each misclassified sample (x, y):<br>
                        w โ† w + ฮฑ ร— y ร— x<br>
                        b โ† b + ฮฑ ร— y
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Manual Training</div>
                        <strong>Data:</strong> xโ‚ = [1, 1], yโ‚ = 1 | xโ‚‚ = [0, 0], yโ‚‚ = 0<br>
                        <strong>Initial:</strong> w = [0, 0], b = 0, ฮฑ = 1<br>
                        <br>
                        <strong>Iteration 1 (xโ‚):</strong><br>
                        z = 0ร—1 + 0ร—1 + 0 = 0 โ†’ ลท = 1 โœ“ (correct!)<br>
                        <br>
                        <strong>Iteration 2 (xโ‚‚):</strong><br>
                        z = 0ร—0 + 0ร—0 + 0 = 0 โ†’ ลท = 1 โœ— (wrong! y=0)<br>
                        Update: w = [0,0] + 1ร—(0-1)ร—[0,0] = [0,0], b = 0 + 1ร—(0-1) = -1<br>
                        <br>
                        Now z(xโ‚‚) = 0 + 0 - 1 = -1 โ†’ ลท = 0 โœ“
                    </div>
                    
                    <h3>Convergence Theorem</h3>
                    <div class="formula">
                        If data is linearly separable with margin ฮณ and ||x|| โ‰ค R,<br>
                        perceptron converges in at most (R/ฮณ)ยฒ updates.
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“š Educational</div>
                        <div class="box-content">
                            Historical importance - first trainable neural model. Perfect for teaching ML fundamentals
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ”ฌ Simple Classification</div>
                        <div class="box-content">
                            Linearly separable problems: basic pattern recognition, simple binary decisions
                        </div>
                    </div>
                `
            },
            "mlp": {
                overview: `
                    <h3>Multi-Layer Perceptron (MLP)</h3>
                    <p>MLP adds hidden layers between input and output, enabling non-linear decision boundaries and solving the XOR problem that single perceptrons cannot.</p>
                    
                    <h3>Why MLPs?</h3>
                    <ul>
                        <li><strong>Universal Approximation:</strong> Can approximate any continuous function</li>
                        <li><strong>Non-Linear Learning:</strong> Solves complex problems</li>
                        <li><strong>Feature Extraction:</strong> Hidden layers learn hierarchical features</li>
                    </ul>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก The XOR Breakthrough</div>
                        Single perceptron: Cannot solve XOR<br>
                        MLP with 1 hidden layer (2 neurons): Solves XOR!<br>
                        This proves the power of depth.
                    </div>
                `,
                concepts: `
                    <h3>Architecture Components</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Input Layer:</strong> Raw features (no computation)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Hidden Layers:</strong> Extract progressively abstract features</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Output Layer:</strong> Final predictions</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“Š Tabular Data</div>
                        <div class="box-content">Credit scoring, fraud detection, customer churn, sales forecasting</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿญ Manufacturing</div>
                        <div class="box-content">Quality control, predictive maintenance, demand forecasting</div>
                    </div>
                `,
                math: `
                    <h3>Neural Network Forward Pass (Matrix Form)</h3>
                    <p>Vectorization is key to modern deep learning. We process entire layers as matrix multiplications.</p>
                    
                    <div class="formula">
                        Layer 1: zโฝยนโพ = Wโฝยนโพx + bโฝยนโพ | aโฝยนโพ = ฯƒ(zโฝยนโพ)<br>
                        Layer 2: zโฝยฒโพ = Wโฝยฒโพaโฝยนโพ + bโฝยฒโพ | aโฝยฒโพ = ฯƒ(zโฝยฒโพ)<br>
                        ...<br>
                        Layer L: ลท = Softmax(Wโฝแดธโพaโฝแดธโปยนโพ + bโฝแดธโพ)
                    </div>

                    <h3>Paper & Pain: Dimensionality Audit</h3>
                    <p>Understanding tensor shapes is the #1 skill for debugging neural networks.</p>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Input x:</strong> [n_features, 1]</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Weights Wโฝยนโพ:</strong> [n_hidden, n_features]</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Bias bโฝยนโพ:</strong> [n_hidden, 1]</div>
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Solving XOR</div>
                        Input: [0,1], Target: 1<br>
                        Layer 1 (2 neurons):<br>
                        zโ‚ = 10xโ‚ + 10xโ‚‚ - 5 &nbsp; | &nbsp; aโ‚ = ฯƒ(zโ‚)<br>
                        zโ‚‚ = 10xโ‚ + 10xโ‚‚ - 15 | &nbsp; aโ‚‚ = ฯƒ(zโ‚‚)<br>
                        Layer 2 (1 neuron):<br>
                        y = ฯƒ(20aโ‚ - 20aโ‚‚ - 10)<br>
                        <strong>Try it on paper!</strong> This specific configuration correctly outputs XOR values.
                    </div>
                `
            },
            "weight-init": {
                overview: `
                    <h3>Weight Initialization Strategies</h3>
                    <table>
                        <tr>
                            <th>Method</th>
                            <th>Best For</th>
                            <th>Formula</th>
                        </tr>
                        <tr>
                            <td>Xavier/Glorot</td>
                            <td>Sigmoid, Tanh</td>
                            <td>N(0, โˆš(2/(n_in+n_out)))</td>
                        </tr>
                        <tr>
                            <td>He/Kaiming</td>
                            <td>ReLU</td>
                            <td>N(0, โˆš(2/n_in))</td>
                        </tr>
                    </table>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Never Initialize to Zero!</div>
                        All neurons learn identical features (symmetry problem)
                    </div>
                `,
                concepts: `
                    <h3>Key Principles</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Variance Preservation:</strong> Keep activation variance similar across layers</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Symmetry Breaking:</strong> Different weights force different features</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Critical for Deep Networks</div>
                        <div class="box-content">
                            Proper initialization is essential for training networks >10 layers. Wrong init = training failure
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">โšก Faster Convergence</div>
                        <div class="box-content">
                            Good initialization reduces training time by 2-10ร—, especially with modern optimizers
                        </div>
                    </div>
                `,
                math: `
                    <h3>The Variance Preservation Principle</h3>
                    <p>To prevent gradients from vanishing or exploding, we want the variance of the activations to remain constant across layers.</p>
                    
                    <div class="formula">
                        For a linear layer: y = ฮฃ wแตขxแตข<br>
                        Var(y) = Var(ฮฃ wแตขxแตข) = ฮฃ Var(wแตขxแตข)<br>
                        Assuming w and x are independent with mean 0:<br>
                        Var(wแตขxแตข) = E[wแตขยฒ]E[xแตขยฒ] - E[wแตข]ยฒE[xแตข]ยฒ = Var(wแตข)Var(xแตข)<br>
                        So, Var(y) = n_in ร— Var(w) ร— Var(x)
                    </div>

                    <h3>1. Xavier (Glorot) Initialization</h3>
                    <p>Goal: Var(y) = Var(x) and Var(grad_out) = Var(grad_in)</p>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Forward Pass:</strong> n_in ร— Var(w) = 1  โ‡’ Var(w) = 1/n_in</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Backward Pass:</strong> n_out ร— Var(w) = 1 โ‡’ Var(w) = 1/n_out</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Compromise:</strong> Var(w) = 2 / (n_in + n_out)</div>
                    </div>

                    <h3>2. He (Kaiming) Initialization</h3>
                    <p>For ReLU activation, half the neurons are inactive (output 0), which halves the variance. We must compensate.</p>
                    <div class="formula">
                        Var(ReLU(y)) = 1/2 ร— Var(y)<br>
                        To keep Var(ReLU(y)) = Var(x):<br>
                        1/2 ร— n_in ร— Var(w) = 1<br>
                        <strong>Var(w) = 2 / n_in</strong>
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain Calculation</div>
                        If n_in = 256 and you use ReLU:<br>
                        Weight Std Dev = โˆš(2/256) = โˆš(1/128) โ‰ˆ <strong>0.088</strong><br>
                        Initializing with std=1.0 or std=0.01 would cause immediate failure in a deep net!
                    </div>
                `
            },
            "loss": {
                overview: `
                <p>The loss function is the <strong>judge</strong> of your neural network. It measures how wrong the network's predictions are compared to the true answers. The entire goal of training is to <strong>minimize this number</strong>.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽฏ Why Loss Functions Matter</div>
                    The choice of loss function determines <em>what</em> the network optimizes for. Use the wrong loss and you'll get a network that's great at the wrong thing. For example, using MSE for classification gives equal penalty to being "slightly wrong" and "completely wrong" โ€” which isn't what you want.
                </div>

                <h3>Matching Loss to Task</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Task</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Loss Function</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">Output Activation</th>
                        <th style="padding: 10px; text-align: left; color: var(--cyan);">PyTorch</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Regression</td><td>MSE / MAE / Huber</td><td>None (Linear)</td><td>nn.MSELoss()</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Binary Classification</td><td>Binary Cross-Entropy</td><td>Sigmoid</td><td>nn.BCEWithLogitsLoss()</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Multi-class</td><td>Categorical Cross-Entropy</td><td>Softmax (built-in)</td><td>nn.CrossEntropyLoss()</td></tr>
                    <tr><td style="padding: 8px;">Object Detection</td><td>Focal Loss + IoU Loss</td><td>Varies</td><td>Custom</td></tr>
                </table>
`,
                concepts: `
                    <h3>Common Loss Functions</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>MSE:</strong> (1/n)ฮฃ(y - ลท)ยฒ - Penalizes large errors, sensitive to outliers</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>MAE:</strong> (1/n)ฮฃ|y - ลท| - Robust to outliers, constant gradient, slower convergence</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Huber Loss:</strong> MSE when |error| โ‰ค ฮด, MAE otherwise. Best of both โ€” smooth + robust to outliers</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>BCE (Binary Cross-Entropy):</strong> -[yยทlog(ลท) + (1-y)ยทlog(1-ลท)] - Used with Sigmoid</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>CCE (Categorical Cross-Entropy):</strong> -ฮฃ yยทlog(ลท) - Used with Softmax for multi-class</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div><strong>Hinge Loss:</strong> max(0, 1 - yยทลท) where y โˆˆ {-1, +1} - Margin-based, SVM-style</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Task-Dependent Selection</div>
                        <div class="box-content">
                            Every ML task needs appropriate loss: classification (cross-entropy), regression (MSE/MAE), ranking (triplet loss)
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“Š Custom Losses</div>
                        <div class="box-content">
                            Business-specific objectives: Focal Loss (imbalanced data), Dice Loss (segmentation), Contrastive Loss (similarity learning)
                        </div>
                    </div>

                    <h3>Loss Function Comparison</h3>
                    <table>
                        <tr><th>Loss</th><th>Type</th><th>Outlier Sensitivity</th><th>Key Property</th></tr>
                        <tr><td>MSE</td><td>Regression</td><td>High</td><td>Penalizes large errors heavily</td></tr>
                        <tr><td>MAE</td><td>Regression</td><td>Low</td><td>Robust, constant gradient</td></tr>
                        <tr><td>Huber</td><td>Regression</td><td>Medium</td><td>Smooth + robust (MSE+MAE combo)</td></tr>
                        <tr><td>BCE</td><td>Binary Class.</td><td>High</td><td>Strong gradients for wrong predictions</td></tr>
                        <tr><td>CCE</td><td>Multi-class</td><td>High</td><td>Outputs probabilities via Softmax</td></tr>
                        <tr><td>Hinge</td><td>Binary Class.</td><td>Medium</td><td>Margin-based, less probabilistic</td></tr>
                    </table>

                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽค Probable Interview Questions</div>
                        1. Difference between MSE and MAE?<br>
                        2. Why Huber loss is preferred sometimes?<br>
                        3. Why BCE with sigmoid?<br>
                        4. Why softmax with CCE?<br>
                        5. Why can't we use MSE for classification?<br>
                        6. What is Hinge loss and where is it used?<br>
                        7. Difference between loss function and evaluation metric?<br>
                        8. How does loss choice affect gradients?<br>
                        9. What is Focal Loss and when to use it?<br>
                        10. Can we design custom loss functions?
                    </div>
                `,
                math: `
                    <h3>Binary Cross-Entropy (BCE) Derivation</h3>
                    <p>Why do we use logs? BCE is derived from Maximum Likelihood Estimation (MLE) assuming a Bernoulli distribution.</p>
                    
                    <div class="formula">
                        L(ลท, y) = -(y log(ลท) + (1-y) log(1-ลท))
                    </div>

                    <h3>Huber Loss (Smooth MAE)</h3>
                    <p>Combines MSE for small errors and MAE for large errors using threshold ฮด:</p>
                    <div class="formula">
                        L = ยฝ(y - ลท)ยฒ &nbsp;&nbsp;&nbsp; when |y - ลท| โ‰ค ฮด<br>
                        L = ฮด|y - ลท| - ยฝฮดยฒ &nbsp;&nbsp; otherwise
                    </div>
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Huber Intuition</div>
                        <strong>Small error (|error| โ‰ค ฮด):</strong> Behaves like MSE โ€” smooth, differentiable<br>
                        <strong>Large error (|error| > ฮด):</strong> Behaves like MAE โ€” doesn't blow up for outliers<br><br>
                        Best of both worlds! Used when data contains mild outliers.
                    </div>

                    <h3>Hinge Loss (SVM-style)</h3>
                    <div class="formula">
                        L = (1/n) ฮฃ max(0, 1 - yยทลท) &nbsp;&nbsp; where y โˆˆ {-1, +1}
                    </div>
                    <p>Margin-based loss: only penalizes predictions within the margin boundary. Used in SVMs and some neural network classifiers.</p>

                    <h3>Paper & Pain: Why not MSE for Classification?</h3>
                    <p>If we use MSE for sigmoid output, the gradient is:</p>
                    <div class="formula">
                        โˆ‚L/โˆ‚w = (ลท - y) <strong>ฯƒ'(z)</strong> x
                    </div>
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ The Saturation Problem</div>
                        If the model is very wrong (e.g., target 1, output 0.001), ฯƒ'(z) is near 0. <br>
                        The gradient vanishes, and the model <strong>stops learning!</strong>.
                    </div>

                    <h3>The BCE Advantage</h3>
                    <p>When using BCE, the ฯƒ'(z) term cancels out! The gradient becomes:</p>
                    <div class="formula" style="font-size: 1.2rem; color: #00d4ff;">
                        โˆ‚L/โˆ‚w = (ลท - y) x
                    </div>
                    <div class="list-item">
                        <div class="list-num">๐Ÿ’ก</div>
                        <div>This is beautiful: the gradient depends <strong>only on the error</strong> (ลท-y), not on how saturated the neuron is. This enables much faster training.</div>
                    </div>
                `,
                code: `
                    <h3>Loss Functions (MathJax)</h3>
                    <div class="formula" style="text-align:center;">
                        <strong>MSE (Regression):</strong> $$L = \\frac{1}{n}\\sum_{i=1}^{n}(y_i - \\hat{y}_i)^2$$
                        <strong>Binary Cross-Entropy:</strong> $$L = -\\frac{1}{n}\\sum[y\\log(\\hat{y}) + (1-y)\\log(1-\\hat{y})]$$
                        <strong>Categorical Cross-Entropy:</strong> $$L = -\\sum_{c=1}^{C} y_c \\log(\\hat{y}_c)$$
                    </div>
<span class="code-title">๐Ÿ“„ loss_functions.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="comment"># --- MSE Loss (Regression) ---</span>
mse = nn.MSELoss()
pred = torch.tensor([<span class="number">2.5</span>, <span class="number">0.0</span>, <span class="number">2.1</span>])
target = torch.tensor([<span class="number">3.0</span>, <span class="number">-0.5</span>, <span class="number">2.0</span>])
<span class="keyword">print</span>(f<span class="string">"MSE: {mse(pred, target).item():.4f}"</span>)

<span class="comment"># --- Binary Cross-Entropy (Binary Classification) ---</span>
bce = nn.BCEWithLogitsLoss()  <span class="comment"># includes sigmoid</span>
logits = torch.tensor([<span class="number">1.5</span>, <span class="number">-0.5</span>, <span class="number">2.0</span>])
labels = torch.tensor([<span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>])
<span class="keyword">print</span>(f<span class="string">"BCE: {bce(logits, labels).item():.4f}"</span>)

<span class="comment"># --- Cross-Entropy (Multi-class) ---</span>
ce = nn.CrossEntropyLoss()  <span class="comment"># includes softmax internally</span>
logits = torch.tensor([[<span class="number">2.0</span>, <span class="number">1.0</span>, <span class="number">0.1</span>]])
target = torch.tensor([<span class="number">0</span>])  <span class="comment"># class index</span>
<span class="keyword">print</span>(f<span class="string">"CE: {ce(logits, target).item():.4f}"</span>)</div>
                `
            },
            "optimizers": {
                overview: `
                <p>Optimizers are the <strong>algorithms that actually update the weights</strong> during training. Think of training as hiking down a foggy mountain โ€” you can't see the bottom (global minimum), but you can feel the slope beneath your feet (gradient). The optimizer decides <strong>how big a step to take</strong> and <strong>in which direction</strong>.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ”๏ธ The Mountain Analogy</div>
                    <strong>SGD</strong> = Walking downhill with fixed-size steps. Simple but slow.<br>
                    <strong>Momentum</strong> = Rolling a ball downhill โ€” it builds up speed on consistent slopes.<br>
                    <strong>Adam</strong> = A smart hiker with GPS who adapts step size per-dimension and remembers past terrain.
                </div>

                <h3>The Optimization Problem</h3>
                <p>Training finds weights that <strong>minimize the loss function</strong>. The loss surface is a high-dimensional landscape with valleys (good), plateaus (stuck), and saddle points (tricky). Different optimizers navigate this landscape differently.</p>
                <div class="formula" style="text-align:center;">
                    $$\\theta^* = \\arg\\min_{\\theta} L(\\theta; X, y)$$
                </div>

                <h3>Learning Rate: The Most Important Hyperparameter</h3>
                <div class="info-box">
                    <div class="box-title">โšก Learning Rate Effects</div>
                    <div class="box-content">
                        <strong>Too high (0.1):</strong> Overshoots the minimum, loss oscillates wildly or diverges to infinity<br>
                        <strong>Too low (0.00001):</strong> Converges extremely slowly, might get stuck in local minima<br>
                        <strong>Just right (0.001):</strong> Smooth convergence to a good minimum<br><br>
                        <strong>Rule of thumb:</strong> Start with lr=0.001 for Adam, lr=0.01 for SGD. Use learning rate schedulers (cosine annealing, step decay) to reduce lr during training.
                    </div>
                </div>
`,
                concepts: `
                <h3>1. SGD (Stochastic Gradient Descent)</h3>
                <p>The simplest optimizer. Compute the gradient on a mini-batch and take a step proportional to the learning rate:</p>
                <div class="formula" style="text-align:center;">$$\\theta_{t+1} = \\theta_t - \\eta \\nabla L(\\theta_t)$$</div>
                <p><strong>Problem:</strong> SGD oscillates in ravines (narrow valleys) and is slow on plateaus. It treats all parameters equally regardless of how frequently they update.</p>

                <h3>2. SGD with Momentum</h3>
                <p>Adds a "velocity" term that remembers past gradients. Like a ball rolling downhill โ€” it accelerates when the gradient consistently points the same direction:</p>
                <div class="formula" style="text-align:center;">
                    $$v_t = \\gamma v_{t-1} + \\eta \\nabla L(\\theta_t)$$
                    $$\\theta_{t+1} = \\theta_t - v_t$$
                </div>
                <p>Where $\\gamma$ is the momentum coefficient (typically 0.9). This dampens oscillations and speeds convergence 2-10x.</p>

                <h3>3. RMSprop</h3>
                <p>Adapts the learning rate <strong>per parameter</strong>. Parameters with large gradients get smaller updates, and vice versa:</p>
                <div class="formula" style="text-align:center;">
                    $$s_t = \\beta s_{t-1} + (1-\\beta)g_t^2$$
                    $$\\theta_{t+1} = \\theta_t - \\frac{\\eta}{\\sqrt{s_t + \\epsilon}} g_t$$
                </div>
                <p>Invented by Geoff Hinton in a Coursera lecture slide (never formally published!).</p>

                <h3>4. Adam (Adaptive Moment Estimation) โญ</h3>
                <p><strong>The default optimizer for most deep learning.</strong> It combines the best of Momentum (first moment) and RMSprop (second moment):</p>
                <div class="formula" style="text-align:center;">
                    $$m_t = \\beta_1 m_{t-1} + (1-\\beta_1)g_t \\quad \\text{(1st moment: mean of gradients)}$$
                    $$v_t = \\beta_2 v_{t-1} + (1-\\beta_2)g_t^2 \\quad \\text{(2nd moment: variance of gradients)}$$
                    $$\\hat{m}_t = \\frac{m_t}{1-\\beta_1^t}, \\quad \\hat{v}_t = \\frac{v_t}{1-\\beta_2^t} \\quad \\text{(bias correction)}$$
                    $$\\theta_{t+1} = \\theta_t - \\frac{\\eta \\hat{m}_t}{\\sqrt{\\hat{v}_t} + \\epsilon}$$
                </div>
                <p>Default hyperparameters: $\\beta_1=0.9$, $\\beta_2=0.999$, $\\epsilon=10^{-8}$, $\\eta=0.001$.</p>

                <h3>5. AdamW (Adam with Decoupled Weight Decay)</h3>
                <p>Standard Adam applies weight decay <em>inside</em> the adaptive learning rate, which doesn't regularize properly. AdamW <strong>decouples</strong> weight decay from the gradient update:</p>
                <div class="formula" style="text-align:center;">$$\\theta_{t+1} = (1 - \\lambda)\\theta_t - \\frac{\\eta \\hat{m}_t}{\\sqrt{\\hat{v}_t} + \\epsilon}$$</div>
                <p><strong>Used by:</strong> GPT, BERT, LLaMA, and virtually all modern large models.</p>

                <div class="callout tip">
                    <div class="callout-title">๐ŸŽฏ Which Optimizer Should You Use?</div>
                    <strong>Default:</strong> Adam or AdamW with lr=0.001<br>
                    <strong>Computer Vision:</strong> SGD with Momentum (lr=0.01, momentum=0.9) often generalizes better<br>
                    <strong>Large Language Models:</strong> AdamW with cosine lr schedule and warmup<br>
                    <strong>Fine-tuning pretrained:</strong> AdamW with very low lr (2e-5 to 5e-5)
                </div>
`,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿš€ Training Acceleration</div>
                        <div class="box-content">
                            Modern optimizers (Adam) reduce training time by 5-10ร— compared to basic SGD
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Architecture-Specific</div>
                        <div class="box-content">
                            CNNs: SGD+Momentum | Transformers: AdamW | RNNs: RMSprop | Default: Adam
                        </div>
                    </div>

                    <h3>Optimizer Comparison</h3>
                    <table>
                        <tr><th>Optimizer</th><th>Key Idea</th><th>Problem</th></tr>
                        <tr><td>SGD</td><td>Simple, fast</td><td>Noisy convergence</td></tr>
                        <tr><td>Momentum</td><td>Smooths updates</td><td>Needs tuning</td></tr>
                        <tr><td>AdaGrad</td><td>Adaptive LR</td><td>LR shrinks too much</td></tr>
                        <tr><td>RMSProp</td><td>Fixes AdaGrad</td><td>No momentum</td></tr>
                        <tr><td><strong>Adam</strong></td><td><strong>Best of all</strong></td><td>Slightly more computation</td></tr>
                    </table>

                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽค Probable Interview Questions</div>
                        1. Difference between optimizer and gradient descent?<br>
                        2. Why does SGD oscillate?<br>
                        3. Why does AdaGrad fail in deep networks?<br>
                        4. How does RMSProp fix AdaGrad?<br>
                        5. Why is bias correction needed in Adam?<br>
                        6. What happens if learning rate is too high?<br>
                        7. When would you prefer SGD over Adam?<br>
                        8. What is momentum intuitively?<br>
                        9. Why is Adam the default choice?<br>
                        10. Can Adam overfit?
                    </div>
                `,
                math: `
                    <h3>Gradient Descent: The Foundation</h3>
                    <p>All optimizers are variations of gradient descent. The goal: minimize the loss function L(w).</p>
                    
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>w = w - ฮฑ ร— โˆ‡L(w)</strong>
                    </div>
                    
                    <h3>1. Stochastic Gradient Descent (SGD)</h3>
                    <div class="formula">
                        w_{t+1} = w_t - ฮฑ ร— โˆ‡L(w_t)<br><br>
                        Where ฮฑ = learning rate (typically 0.01 - 0.1)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: SGD Step</div>
                        <strong>Current w:</strong> 2.0, <strong>Gradient:</strong> โˆ‡L = 0.5, <strong>ฮฑ:</strong> 0.1<br><br>
                        w_new = 2.0 - 0.1 ร— 0.5 = 2.0 - 0.05 = <strong>1.95</strong><br>
                        The weight moved slightly toward lower loss!
                    </div>
                    
                    <h3>2. SGD with Momentum</h3>
                    <p>Adds a "velocity" term to accelerate through flat regions and dampen oscillations.</p>
                    
                    <div class="formula">
                        v_{t+1} = ฮฒ ร— v_t + โˆ‡L(w_t)<br>
                        w_{t+1} = w_t - ฮฑ ร— v_{t+1}<br><br>
                        Where ฮฒ = momentum coefficient (typically 0.9)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Momentum Step</div>
                        <strong>v_t:</strong> 0.3, <strong>โˆ‡L:</strong> 0.5, <strong>ฮฒ:</strong> 0.9, <strong>ฮฑ:</strong> 0.1<br><br>
                        v_new = 0.9 ร— 0.3 + 0.5 = 0.27 + 0.5 = <strong>0.77</strong><br>
                        w_new = w - 0.1 ร— 0.77 = <strong>larger step!</strong><br>
                        Momentum accumulates past gradients for faster convergence.
                    </div>
                    
                    <h3>3. AdaGrad (Adaptive Gradient)</h3>
                    <p>Adapts learning rate per-parameter based on how frequently each parameter is updated.</p>
                    
                    <div class="formula">
                        <strong>Accumulated Gradient:</strong><br>
                        G_t = G_{t-1} + (โˆ‡L)ยฒ<br><br>
                        <strong>Update Rule:</strong><br>
                        w_{t+1} = w_t - ฮท / โˆš(G_t + ฮต) ร— โˆ‡L<br><br>
                        Where ฮต = 1e-8 (numerical stability)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: AdaGrad Intuition</div>
                        <strong>Frequent parameters</strong> โ†’ G_t grows fast โ†’ learning rate shrinks<br>
                        <strong>Rare parameters</strong> โ†’ G_t stays small โ†’ learning rate stays large<br><br>
                        <strong>Problem:</strong> G_t only accumulates (never forgets), so learning rate keeps shrinking and training may stop early!<br>
                        <strong>This is exactly why RMSprop was invented โ†’</strong>
                    </div>
                    
                    <h3>4. RMSprop (Root Mean Square Propagation)</h3>
                    <p>Fixes AdaGrad's shrinking problem by using a <strong>decaying average</strong> of recent squared gradients instead of summing all.</p>
                    
                    <div class="formula">
                        v_t = ฮฒ ร— v_{t-1} + (1-ฮฒ) ร— (โˆ‡L)ยฒ<br>
                        w_{t+1} = w_t - ฮฑ ร— โˆ‡L / โˆš(v_t + ฮต)<br><br>
                        ฮฒ = 0.9, ฮต = 1e-8 (numerical stability)
                    </div>
                    
                    <h3>5. Adam (Adaptive Moment Estimation)</h3>
                    <p>Combines momentum (from SGD) AND adaptive learning rates (from RMSprop). The most popular optimizer.</p>
                    
                    <div class="formula" style="background: rgba(255, 107, 53, 0.08); padding: 20px; border-radius: 8px;">
                        <strong>Step 1 - First Moment (Momentum):</strong><br>
                        m_t = ฮฒโ‚ ร— m_{t-1} + (1-ฮฒโ‚) ร— โˆ‡L<br><br>
                        <strong>Step 2 - Second Moment (RMSprop):</strong><br>
                        v_t = ฮฒโ‚‚ ร— v_{t-1} + (1-ฮฒโ‚‚) ร— (โˆ‡L)ยฒ<br><br>
                        <strong>Step 3 - Bias Correction:</strong><br>
                        mฬ‚_t = m_t / (1 - ฮฒโ‚แต—)<br>
                        vฬ‚_t = v_t / (1 - ฮฒโ‚‚แต—)<br><br>
                        <strong>Step 4 - Update:</strong><br>
                        w_{t+1} = w_t - ฮฑ ร— mฬ‚_t / (โˆšvฬ‚_t + ฮต)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Adam Step-by-Step</div>
                        <strong>Hyperparameters:</strong> ฮฑ=0.001, ฮฒโ‚=0.9, ฮฒโ‚‚=0.999, ฮต=1e-8<br>
                        <strong>t=2:</strong> โˆ‡L = 0.5, mโ‚ = 0.05, vโ‚ = 0.00025<br><br>
                        mโ‚‚ = 0.9 ร— 0.05 + 0.1 ร— 0.5 = 0.045 + 0.05 = 0.095<br>
                        vโ‚‚ = 0.999 ร— 0.00025 + 0.001 ร— 0.25 = 0.000499<br><br>
                        mฬ‚โ‚‚ = 0.095 / (1 - 0.81) = 0.095 / 0.19 = 0.50<br>
                        vฬ‚โ‚‚ = 0.000499 / (1 - 0.998) = 0.2495<br><br>
                        ฮ”w = 0.001 ร— 0.50 / (โˆš0.2495 + 1e-8) โ‰ˆ <strong>0.001</strong>
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Why Bias Correction?</div>
                        mโ‚€ = 0, vโ‚€ = 0 initialization biases early estimates toward zero.<br>
                        Dividing by (1 - ฮฒแต—) compensates for this, especially in early training steps.
                    </div>
                `,
                code: `
                    <h3>Implementing Optimizers in PyTorch</h3>
                    <p>PyTorch provides all common optimizers in <code>torch.optim</code>. Here's a complete example showing how to use them and how to implement SGD from scratch.</p>
                    <span class="code-title">๐Ÿ“„ optimizers_comparison.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> torch.optim <span class="keyword">as</span> optim

<span class="comment"># --- Simple model for demonstration ---</span>
model = nn.Sequential(
    nn.Linear(<span class="number">784</span>, <span class="number">256</span>),
    nn.ReLU(),
    nn.Linear(<span class="number">256</span>, <span class="number">10</span>),
)

<span class="comment"># ====== 1. SGD ======</span>
optimizer = optim.SGD(model.parameters(), lr=<span class="number">0.01</span>)

<span class="comment"># ====== 2. SGD with Momentum ======</span>
optimizer = optim.SGD(model.parameters(), lr=<span class="number">0.01</span>, momentum=<span class="number">0.9</span>)

<span class="comment"># ====== 3. Adam (Most Common) ======</span>
optimizer = optim.Adam(model.parameters(), lr=<span class="number">0.001</span>)

<span class="comment"># ====== 4. AdamW (For Transformers/LLMs) ======</span>
optimizer = optim.AdamW(model.parameters(), lr=<span class="number">0.001</span>, weight_decay=<span class="number">0.01</span>)

<span class="comment"># ====== Training Loop ======</span>
criterion = nn.CrossEntropyLoss()

<span class="keyword">for</span> epoch <span class="keyword">in</span> range(<span class="number">10</span>):
    <span class="keyword">for</span> X_batch, y_batch <span class="keyword">in</span> train_loader:
        <span class="comment"># 1. Forward pass</span>
        predictions = model(X_batch)
        loss = criterion(predictions, y_batch)

        <span class="comment"># 2. Backward pass</span>
        optimizer.zero_grad()     <span class="comment"># Clear old gradients</span>
        loss.backward()           <span class="comment"># Compute gradients</span>

        <span class="comment"># 3. Update weights</span>
        optimizer.step()          <span class="comment"># Apply optimizer rule</span>

    <span class="keyword">print</span>(f<span class="string">"Epoch {epoch+1}, Loss: {loss.item():.4f}"</span>)
</div>

                    <h3>SGD from Scratch</h3>
                    <p>Understanding what happens inside <code>optimizer.step()</code>:</p>
                    <span class="code-title">๐Ÿ“„ sgd_from_scratch.py</span><div class="code-block"><span class="keyword">import</span> numpy <span class="keyword">as</span> np

<span class="keyword">class</span> <span class="function">SGD</span>:
    <span class="string">"""Stochastic Gradient Descent with Momentum."""</span>
    <span class="keyword">def</span> <span class="function">__init__</span>(self, params, lr=<span class="number">0.01</span>, momentum=<span class="number">0.9</span>):
        self.params = params
        self.lr = lr
        self.momentum = momentum
        self.velocities = [np.zeros_like(p) <span class="keyword">for</span> p <span class="keyword">in</span> params]

    <span class="keyword">def</span> <span class="function">step</span>(self, gradients):
        <span class="keyword">for</span> i, (param, grad) <span class="keyword">in</span> enumerate(zip(self.params, gradients)):
            <span class="comment"># v = momentum * v_prev + lr * gradient</span>
            self.velocities[i] = self.momentum * self.velocities[i] + self.lr * grad
            <span class="comment"># param = param - velocity</span>
            param -= self.velocities[i]

<span class="comment"># Usage</span>
W = np.random.randn(<span class="number">3</span>, <span class="number">3</span>) * <span class="number">0.01</span>
b = np.zeros(<span class="number">3</span>)
optimizer = SGD([W, b], lr=<span class="number">0.01</span>, momentum=<span class="number">0.9</span>)

<span class="comment"># After computing gradients dW, db:</span>
<span class="comment"># optimizer.step([dW, db])</span>
</div>

                    <h3>Learning Rate Schedulers</h3>
                    <span class="code-title">๐Ÿ“„ lr_schedulers.py</span><div class="code-block"><span class="keyword">from</span> torch.optim.lr_scheduler <span class="keyword">import</span> StepLR, CosineAnnealingLR

optimizer = optim.Adam(model.parameters(), lr=<span class="number">0.001</span>)

<span class="comment"># Reduce LR by 0.1 every 30 epochs</span>
scheduler = StepLR(optimizer, step_size=<span class="number">30</span>, gamma=<span class="number">0.1</span>)

<span class="comment"># Cosine annealing (smooth decay, used in modern training)</span>
scheduler = CosineAnnealingLR(optimizer, T_max=<span class="number">100</span>, eta_min=<span class="number">1e-6</span>)

<span class="keyword">for</span> epoch <span class="keyword">in</span> range(<span class="number">100</span>):
    train_one_epoch()
    scheduler.step()  <span class="comment"># Update learning rate</span>
    <span class="keyword">print</span>(f<span class="string">"LR: {scheduler.get_last_lr()[0]:.6f}"</span>)
</div>
`
            },
            "backprop": {
                overview: `
                <p>Backpropagation is the algorithm that makes neural networks <strong>learn</strong>. It computes how much each weight in the network contributed to the error, then adjusts each weight accordingly. It's conceptually simple: <strong>the chain rule of calculus applied systematically from output to input</strong>.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ’ก The Factory Analogy</div>
                    Imagine a factory with 5 stations producing widgets. A quality inspector at the end finds defects. Backpropagation is like tracing the defect backward through each station to find which worker caused the problem and by how much. Each worker (weight) then adjusts their technique proportionally to their contribution to the defect.
                </div>

                <h3>The Algorithm in 4 Steps</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Forward Pass:</strong> Compute outputs layer by layer: $z^l = W^l a^{l-1} + b^l$, then $a^l = \\sigma(z^l)$</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Compute Loss:</strong> Compare prediction to truth: $L = \\text{CrossEntropy}(\\hat{y}, y)$</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Backward Pass:</strong> Compute $\\frac{\\partial L}{\\partial W^l}$ for every layer using the chain rule</div></div>
                <div class="list-item"><div class="list-num">4</div><div><strong>Update:</strong> $W^l \\leftarrow W^l - \\eta \\frac{\\partial L}{\\partial W^l}$</div></div>

                <h3>Computational Graphs</h3>
                <p>Modern frameworks (PyTorch, TensorFlow) build a <strong>computational graph</strong> during the forward pass. Each operation becomes a node. During backprop, they traverse this graph in reverse, applying the chain rule at each node. This is called <strong>automatic differentiation (autograd)</strong>.</p>

                <div class="info-box">
                    <div class="box-title">๐Ÿ”‘ Key Insight</div>
                    <div class="box-content">
                        Backprop's time complexity is <strong>O(W)</strong> โ€” proportional to the number of weights. This is the same as a forward pass! Computing all gradients is no more expensive than computing the prediction itself.
                    </div>
                </div>
`,
                concepts: `
                    <div class="formula">
                        Chain Rule:<br>
                        โˆ‚L/โˆ‚w = โˆ‚L/โˆ‚y ร— โˆ‚y/โˆ‚z ร— โˆ‚z/โˆ‚w<br>
                        <br>
                        For layer l:<br>
                        ฮดหก = (W^(l+1))^T ฮด^(l+1) โŠ™ ฯƒ'(z^l)<br>
                        โˆ‚L/โˆ‚W^l = ฮด^l (a^(l-1))^T
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿง  Universal Training Method</div>
                        <div class="box-content">
                            Every modern neural network uses backprop - from CNNs to Transformers to GANs
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ”ง Automatic Differentiation</div>
                        <div class="box-content">
                            PyTorch, TensorFlow implement automatic backprop - you define forward pass, framework does backward
                        </div>
                    </div>

                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽค Probable Interview Questions</div>
                        1. What is the role of bias in a perceptron?<br>
                        2. Why can't we use MSE for classification?<br>
                        3. Difference between loss function and evaluation metric?<br>
                        4. Why is mini-batch GD preferred?<br>
                        5. Does backpropagation update weights?<br>
                        6. Can gradient descent work without backpropagation?<br>
                        7. What happens if learning rate is too high?<br>
                        8. How many times does forward propagation occur per epoch?<br>
                        9. What happens if we remove bias?<br>
                        10. What is the chain rule and why is it essential for backprop?
                    </div>
                `,
                math: `
                    <h3>The 4 Fundamental Equations of Backprop</h3>
                    <p>Backpropagation is essentially the chain rule applied iteratively. We define the error signal ฮด = โˆ‚L/โˆ‚z.</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Error at Output Layer (L):</strong><br>
                        ฮดแดธ = โˆ‡โ‚L โŠ™ ฯƒ'(zแดธ)<br>
                        <span class="formula-caption">Example for MSE: (aแดธ - y) โŠ™ ฯƒ'(zแดธ)</span></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Error at Layer l (Backwards):</strong><br>
                        ฮดหก = ((Wหกโบยน)แต€ ฮดหกโบยน) โŠ™ ฯƒ'(zหก)</div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Gradient w.r.t Bias:</strong><br>
                        โˆ‚L / โˆ‚bหก = ฮดหก</div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Gradient w.r.t Weights:</strong><br>
                        โˆ‚L / โˆ‚Wหก = ฮดหก (aหกโปยน)แต€</div>
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain Walkthrough</div>
                        Suppose single neuron: z = wx + b, Loss L = (ฯƒ(z) - y)ยฒ/2<br>
                        1. <strong>Forward:</strong> z=2, a=ฯƒ(2)โ‰ˆ0.88, y=1, L=0.007<br>
                        2. <strong>Backward:</strong><br>
                        &nbsp;&nbsp;&nbsp;โˆ‚L/โˆ‚a = (a-y) = -0.12<br>
                        &nbsp;&nbsp;&nbsp;โˆ‚a/โˆ‚z = ฯƒ(z)(1-ฯƒ(z)) = 0.88 * 0.12 = 0.1056<br>
                        &nbsp;&nbsp;&nbsp;ฮด = โˆ‚L/โˆ‚z = -0.12 * 0.1056 = -0.01267<br>
                        &nbsp;&nbsp;&nbsp;<strong>โˆ‚L/โˆ‚w = ฮด * x</strong> | <strong>โˆ‚L/โˆ‚b = ฮด</strong>
                    </div>
                `,
                code: `
                    <h3>Backpropagation from Scratch</h3>
                    <p>A complete 2-layer neural network trained with backpropagation using only NumPy. This is the best way to truly understand how gradients flow.</p>
                    <span class="code-title">๐Ÿ“„ backprop_numpy.py</span><div class="code-block"><span class="keyword">import</span> numpy <span class="keyword">as</span> np

np.random.seed(<span class="number">42</span>)

<span class="comment"># --- Data: XOR problem ---</span>
X = np.array([[<span class="number">0</span>,<span class="number">0</span>], [<span class="number">0</span>,<span class="number">1</span>], [<span class="number">1</span>,<span class="number">0</span>], [<span class="number">1</span>,<span class="number">1</span>]])
y = np.array([[<span class="number">0</span>], [<span class="number">1</span>], [<span class="number">1</span>], [<span class="number">0</span>]])

<span class="comment"># --- Initialize weights ---</span>
W1 = np.random.randn(<span class="number">2</span>, <span class="number">4</span>) * <span class="number">0.5</span>   <span class="comment"># Input(2) -> Hidden(4)</span>
b1 = np.zeros((<span class="number">1</span>, <span class="number">4</span>))
W2 = np.random.randn(<span class="number">4</span>, <span class="number">1</span>) * <span class="number">0.5</span>   <span class="comment"># Hidden(4) -> Output(1)</span>
b2 = np.zeros((<span class="number">1</span>, <span class="number">1</span>))
lr = <span class="number">0.5</span>

<span class="keyword">def</span> <span class="function">sigmoid</span>(z):
    <span class="keyword">return</span> <span class="number">1</span> / (<span class="number">1</span> + np.exp(-z))

<span class="keyword">for</span> epoch <span class="keyword">in</span> range(<span class="number">10000</span>):
    <span class="comment"># ====== FORWARD PASS ======</span>
    z1 = X @ W1 + b1           <span class="comment"># (4, 4)</span>
    a1 = sigmoid(z1)            <span class="comment"># Hidden activation</span>
    z2 = a1 @ W2 + b2           <span class="comment"># (4, 1)</span>
    a2 = sigmoid(z2)            <span class="comment"># Output prediction</span>

    <span class="comment"># ====== COMPUTE LOSS (MSE) ======</span>
    loss = np.mean((y - a2) ** <span class="number">2</span>)

    <span class="comment"># ====== BACKWARD PASS (Chain Rule) ======</span>
    <span class="comment"># dL/da2 = -2(y - a2) / n</span>
    dL_da2 = -<span class="number">2</span> * (y - a2) / len(y)
    <span class="comment"># da2/dz2 = sigmoid'(z2) = a2(1 - a2)</span>
    dz2 = dL_da2 * a2 * (<span class="number">1</span> - a2)

    <span class="comment"># Gradients for W2, b2</span>
    dW2 = a1.T @ dz2            <span class="comment"># (4, 1)</span>
    db2 = dz2.sum(axis=<span class="number">0</span>, keepdims=<span class="keyword">True</span>)

    <span class="comment"># Propagate to hidden layer</span>
    dz1 = (dz2 @ W2.T) * a1 * (<span class="number">1</span> - a1)
    dW1 = X.T @ dz1             <span class="comment"># (2, 4)</span>
    db1 = dz1.sum(axis=<span class="number">0</span>, keepdims=<span class="keyword">True</span>)

    <span class="comment"># ====== UPDATE WEIGHTS ======</span>
    W2 -= lr * dW2
    b2 -= lr * db2
    W1 -= lr * dW1
    b1 -= lr * db1

    <span class="keyword">if</span> epoch % <span class="number">2000</span> == <span class="number">0</span>:
        <span class="keyword">print</span>(f<span class="string">"Epoch {epoch}: Loss = {loss:.6f}"</span>)

<span class="comment"># Final predictions</span>
<span class="keyword">print</span>(<span class="string">"Predictions:"</span>, a2.round(<span class="number">2</span>).flatten())
<span class="comment"># Expected: [0, 1, 1, 0] for XOR</span>
</div>

                    <h3>PyTorch Autograd (Automatic Backprop)</h3>
                    <span class="code-title">๐Ÿ“„ backprop_pytorch.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="comment"># PyTorch handles backprop automatically via autograd!</span>
x = torch.tensor([<span class="number">2.0</span>], requires_grad=<span class="keyword">True</span>)
y = x**<span class="number">2</span> + <span class="number">3</span>*x + <span class="number">1</span>   <span class="comment"># f(x) = x^2 + 3x + 1</span>
y.backward()            <span class="comment"># Compute df/dx automatically</span>
<span class="keyword">print</span>(x.grad)           <span class="comment"># 7.0  (derivative: 2x + 3, at x=2: 7)</span>
</div>
`
            },
            "regularization": {
                overview: `
                <p>Regularization prevents a neural network from <strong>memorizing the training data</strong> instead of learning general patterns. Without it, the network performs brilliantly on training data but fails on new data โ€” this is <strong>overfitting</strong>.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ“š The Exam Analogy</div>
                    Imagine a student who memorizes all answers in a textbook word-for-word but doesn't understand the concepts. They'll ace the exact same questions but fail on any new ones. Regularization forces the network to "understand" rather than "memorize."
                </div>

                <h3>Signs of Overfitting</h3>
                <div class="info-box">
                    <div class="box-title">๐Ÿšจ Red Flags</div>
                    <div class="box-content">
                        โœ— Training accuracy: 99%, Validation accuracy: 65% (huge gap)<br>
                        โœ— Training loss keeps decreasing but validation loss starts increasing<br>
                        โœ— Model works perfectly on seen data but fails on new examples<br>
                        โœ— Small dataset with a very large model (too many parameters for too little data)
                    </div>
                </div>

                <h3>Regularization Techniques</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>L2 Regularization (Weight Decay):</strong> Adds $\\lambda \\sum w^2$ to the loss. Penalizes large weights, encouraging smaller, more distributed weights.</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>L1 Regularization:</strong> Adds $\\lambda \\sum |w|$ to the loss. Encourages sparsity โ€” some weights become exactly zero.</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Dropout:</strong> During training, randomly sets neurons to 0 with probability $p$. Forces the network to be redundant โ€” no single neuron can be relied upon.</div></div>
                <div class="list-item"><div class="list-num">4</div><div><strong>Data Augmentation:</strong> Artificially increase training data by applying random transformations (flips, rotations, crops). The best regularizer is <em>more data</em>.</div></div>
                <div class="list-item"><div class="list-num">5</div><div><strong>Early Stopping:</strong> Monitor validation loss during training. Stop when it starts increasing even though training loss continues to decrease.</div></div>
                <div class="list-item"><div class="list-num">6</div><div><strong>Batch Normalization:</strong> While not designed as regularization, BN has a regularizing effect because mini-batch statistics add noise.</div></div>
`,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Best Practices</div>
                        <div class="box-content">
                            โ€ข Start with Dropout (0.5) for hidden layers<br>
                            โ€ข Add L2 if still overfitting (ฮป=0.01, 0.001)<br>
                            โ€ข Always use Early Stopping<br>
                            โ€ข Data Augmentation for images
                        </div>
                    </div>

                    <h3>Dropout vs Batch Normalization</h3>
                    <table>
                        <tr><th>Feature</th><th>Dropout</th><th>Batch Normalization</th></tr>
                        <tr><td>Purpose</td><td>Regularization</td><td>Faster training + mild regularization</td></tr>
                        <tr><td>Mechanism</td><td>Randomly drops neurons</td><td>Normalizes layer inputs</td></tr>
                        <tr><td>Training vs Test</td><td>Different behavior</td><td>Different behavior</td></tr>
                        <tr><td>Combined?</td><td colspan="2">Yes, use BatchNorm <em>before</em> Dropout</td></tr>
                    </table>

                    <div class="callout tip">
                        <div class="callout-title">๐ŸŽค Probable Interview Questions</div>
                        1. Why can't we initialize all weights to zero?<br>
                        2. Difference between Xavier and He initialization?<br>
                        3. What is the vanishing gradient problem?<br>
                        4. How does Dropout prevent overfitting?<br>
                        5. Can we use Dropout at test time?<br>
                        6. Why is He initialization used with ReLU?<br>
                        7. What happens if weights are too large initially?<br>
                        8. Does Batch Normalization eliminate the need for Dropout?<br>
                        9. L1 vs L2 regularization โ€” when to use each?<br>
                        10. What is the exploding gradient problem and how to fix it?
                    </div>
                `,
                math: `
                    <h3>L2 Regularization (Weight Decay)</h3>
                    <p>Add a penalty proportional to the squared magnitude of weights.</p>
                    
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>L_total = L_data + ฮป ร— ฮฃ wยฒ</strong>
                    </div>
                    
                    <h4>Gradient with L2:</h4>
                    <div class="formula">
                        โˆ‚L_total/โˆ‚w = โˆ‚L_data/โˆ‚w + 2ฮปw<br><br>
                        Update rule becomes:<br>
                        w = w - ฮฑ(โˆ‡L + 2ฮปw) = w(1 - 2ฮฑฮป) - ฮฑโˆ‡L
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: L2 Effect</div>
                        <strong>Without L2:</strong> w = 5.0, โˆ‡L = 0.1, ฮฑ = 0.1<br>
                        w_new = 5.0 - 0.1 ร— 0.1 = 4.99<br><br>
                        <strong>With L2 (ฮป=0.01):</strong><br>
                        w_new = 5.0 ร— (1 - 2ร—0.1ร—0.01) - 0.1 ร— 0.1<br>
                        w_new = 5.0 ร— 0.998 - 0.01 = 4.99 - 0.01 = <strong>4.98</strong><br><br>
                        The weight shrinks faster! Large weights shrink most.
                    </div>
                    
                    <h3>L1 Regularization (Lasso)</h3>
                    <p>Adds penalty proportional to absolute value of weights - encourages sparsity.</p>
                    
                    <div class="formula">
                        L_total = L_data + ฮป ร— ฮฃ |w|<br><br>
                        Gradient: โˆ‚L/โˆ‚w = โˆ‡L_data + ฮป ร— sign(w)
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก L1 vs L2</div>
                        โ€ข <strong>L1:</strong> Creates sparse weights (many zeros) โ†’ Feature selection<br>
                        โ€ข <strong>L2:</strong> Small but non-zero weights โ†’ More stable<br>
                        โ€ข <strong>Elastic Net:</strong> ฮปโ‚|w| + ฮปโ‚‚wยฒ (both!)
                    </div>
                    
                    <h3>Dropout Mathematics</h3>
                    <p>Randomly set neurons to zero with probability p during training.</p>
                    
                    <div class="formula">
                        <strong>Training:</strong><br>
                        r ~ Bernoulli(1-p)  [mask of 0s and 1s]<br>
                        รฃ = a โŠ™ r           [element-wise multiply]<br><br>
                        <strong>Inference (scaling):</strong><br>
                        รฃ = a ร— (1-p)       [scale by keep probability]
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Dropout Example</div>
                        <strong>Layer output (4 neurons):</strong> a = [1.0, 2.0, 0.5, 1.5]<br>
                        <strong>Dropout p = 0.5:</strong> r = [1, 0, 1, 0] (random mask)<br><br>
                        <strong>Training output:</strong> รฃ = [1.0, 0, 0.5, 0]<br>
                        <strong>Inference output:</strong> รฃ = [0.5, 1.0, 0.25, 0.75]<br><br>
                        During inference, we scale by (1-p)=0.5 to maintain expected value!
                    </div>
                    
                    <h3>Why Dropout Works</h3>
                    <div class="formula">
                        Dropout โ‰ˆ Training an ensemble of 2โฟ sub-networks<br>
                        (where n = number of neurons that can be dropped)<br><br>
                        Each forward pass is a different architecture!
                    </div>

                    <h3>Weight Initialization Mathematics</h3>
                    
                    <h4>Xavier Initialization (for Sigmoid/Tanh)</h4>
                    <div class="formula">
                        w ~ N(0, ฯƒยฒ)  where  ฯƒยฒ = 2 / (n_in + n_out)<br><br>
                        Goal: Keep Var(output) โ‰ˆ Var(input) across layers
                    </div>

                    <h4>He Initialization (for ReLU)</h4>
                    <div class="formula">
                        w ~ N(0, ฯƒยฒ)  where  ฯƒยฒ = 2 / n_in<br><br>
                        ReLU zeros out ~50% of activations, so variance is halved โ†’ multiply by 2 to compensate!
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Why Zero Init Fails</div>
                        If all weights = 0, every neuron computes the <strong>same output</strong>.<br>
                        All gradients are <strong>identical</strong> โ†’ All weights update the same way.<br>
                        Result: All neurons stay identical forever! The network is as good as <strong>1 neuron</strong>.<br><br>
                        <strong>Random Init:</strong> w ~ N(0, 0.01) works for shallow networks but gradients shrink exponentially in deep ones.<br>
                        <strong>Xavier:</strong> Calibrates variance based on layer width โ†’ stable gradients for Sigmoid/Tanh.<br>
                        <strong>He:</strong> Accounts for ReLU zeroing out negative half โ†’ default for modern networks.
                    </div>
                `,
                code: `
                    <h3>Regularization Techniques in PyTorch</h3>
                    <p>Complete examples of the most important regularization methods.</p>
                    <span class="code-title">๐Ÿ“„ regularization_pytorch.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> torchvision.transforms <span class="keyword">as</span> T

<span class="comment"># ====== 1. Dropout ======</span>
<span class="keyword">class</span> <span class="function">ModelWithDropout</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(<span class="number">784</span>, <span class="number">256</span>),
            nn.ReLU(),
            nn.Dropout(p=<span class="number">0.5</span>),  <span class="comment"># 50% of neurons randomly zeroed</span>
            nn.Linear(<span class="number">256</span>, <span class="number">128</span>),
            nn.ReLU(),
            nn.Dropout(p=<span class="number">0.3</span>),  <span class="comment"># 30% dropout</span>
            nn.Linear(<span class="number">128</span>, <span class="number">10</span>),
        )

    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        <span class="keyword">return</span> self.net(x)

model = ModelWithDropout()
model.train()   <span class="comment"># Dropout active</span>
model.eval()    <span class="comment"># Dropout disabled (IMPORTANT for inference!)</span>

<span class="comment"># ====== 2. L2 Regularization (Weight Decay) ======</span>
optimizer = torch.optim.Adam(
    model.parameters(),
    lr=<span class="number">0.001</span>,
    weight_decay=<span class="number">0.01</span>,  <span class="comment"># L2 penalty lambda</span>
)

<span class="comment"># ====== 3. Data Augmentation ======</span>
train_transforms = T.Compose([
    T.RandomHorizontalFlip(p=<span class="number">0.5</span>),
    T.RandomRotation(degrees=<span class="number">15</span>),
    T.RandomResizedCrop(size=<span class="number">224</span>, scale=(<span class="number">0.8</span>, <span class="number">1.0</span>)),
    T.ColorJitter(brightness=<span class="number">0.2</span>, contrast=<span class="number">0.2</span>),
    T.ToTensor(),
    T.Normalize(mean=[<span class="number">0.485</span>, <span class="number">0.456</span>, <span class="number">0.406</span>],
                std=[<span class="number">0.229</span>, <span class="number">0.224</span>, <span class="number">0.225</span>]),
])

<span class="comment"># ====== 4. Early Stopping ======</span>
best_val_loss = float(<span class="string">'inf'</span>)
patience = <span class="number">5</span>
counter = <span class="number">0</span>

<span class="keyword">for</span> epoch <span class="keyword">in</span> range(<span class="number">100</span>):
    train_loss = train_one_epoch()
    val_loss = validate()

    <span class="keyword">if</span> val_loss < best_val_loss:
        best_val_loss = val_loss
        counter = <span class="number">0</span>
        torch.save(model.state_dict(), <span class="string">'best_model.pt'</span>)
    <span class="keyword">else</span>:
        counter += <span class="number">1</span>
        <span class="keyword">if</span> counter >= patience:
            <span class="keyword">print</span>(f<span class="string">"Early stopping at epoch {epoch}"</span>)
            <span class="keyword">break</span>
</div>
`
            },
            "batch-norm": {
                overview: `
                <p>Batch Normalization (BatchNorm) was one of the most impactful innovations in deep learning. It <strong>normalizes the inputs to each layer</strong>, which stabilizes and dramatically accelerates training. Before BatchNorm, training deep networks was extremely difficult.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽฏ The Core Problem BatchNorm Solves</div>
                    As data flows through layers, the distribution of activations keeps shifting โ€” this is called <strong>Internal Covariate Shift</strong>. Each layer has to constantly adapt to new input distributions, slowing down training. BatchNorm fixes this by normalizing each layer's input to have mean=0 and variance=1.
                </div>

                <h3>How It Works (Step by Step)</h3>
                <div class="formula" style="text-align:center;">
                    Given a mini-batch $B = \\{x_1, ..., x_m\\}$:<br><br>
                    <strong>Step 1 โ€” Mean:</strong> $$\\mu_B = \\frac{1}{m}\\sum_{i=1}^{m} x_i$$
                    <strong>Step 2 โ€” Variance:</strong> $$\\sigma_B^2 = \\frac{1}{m}\\sum_{i=1}^{m} (x_i - \\mu_B)^2$$
                    <strong>Step 3 โ€” Normalize:</strong> $$\\hat{x}_i = \\frac{x_i - \\mu_B}{\\sqrt{\\sigma_B^2 + \\epsilon}}$$
                    <strong>Step 4 โ€” Scale and Shift:</strong> $$y_i = \\gamma \\hat{x}_i + \\beta$$
                </div>
                <p>$\\gamma$ and $\\beta$ are <strong>learnable parameters</strong>. They allow the network to undo the normalization if that's optimal โ€” giving the network the flexibility to decide the best distribution for each layer.</p>

                <div class="info-box">
                    <div class="box-title">Benefits of BatchNorm</div>
                    <div class="box-content">
                        โœ“ <strong>Train 5-10x faster</strong> โ€” allows much higher learning rates<br>
                        โœ“ <strong>Reduces sensitivity</strong> to weight initialization<br>
                        โœ“ <strong>Acts as regularization</strong> โ€” mini-batch noise has a dropout-like effect<br>
                        โœ“ <strong>Enables deeper networks</strong> โ€” reduces vanishing/exploding gradients
                    </div>
                </div>

                <div class="callout warning">
                    <div class="callout-title">โš ๏ธ BatchNorm Gotchas</div>
                    <strong>1. Train vs. Eval:</strong> During training, BN uses mini-batch statistics. During inference, it uses running averages computed during training. Always call <code>model.eval()</code> before inference!<br>
                    <strong>2. Small batch sizes:</strong> BN performs poorly with batch_size &lt; 16 because statistics are noisy. Use LayerNorm instead (as in Transformers).<br>
                    <strong>3. Placement:</strong> Usually placed <em>after</em> the linear/conv layer and <em>before</em> the activation: Linear โ†’ BN โ†’ ReLU.
                </div>
`,
                math: `
                    <h3>The 4 Steps of Batch Normalization</h3>
                    <p>Calculated per mini-batch B = {xโ‚, ..., xโ‚˜}:</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Mini-Batch Mean:</strong> ฮผ_B = (1/m) ฮฃ xแตข</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Mini-Batch Variance:</strong> ฯƒยฒ_B = (1/m) ฮฃ (xแตข - ฮผ_B)ยฒ</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Normalize:</strong> xฬ‚แตข = (xแตข - ฮผ_B) / โˆš(ฯƒยฒ_B + ฮต)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Scale and Shift:</strong> yแตข = ฮณ xฬ‚แตข + ฮฒ</div>
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Why ฮณ and ฮฒ?</div>
                        If we only normalized to (0,1), we might restrict the representation power of the network. <br>
                        ฮณ and ฮฒ allow the network to <strong>undo</strong> the normalization if that's optimal: <br>
                        If ฮณ = โˆš(ฯƒยฒ) and ฮฒ = ฮผ, we get the original data back!
                    </div>
                `
            },
            "cv-intro": {
                overview: `
                    <h3>Why Computer Vision Needs Special Architectures</h3>
                    <p><strong>Problem:</strong> Images have huge dimensionality</p>
                    <ul>
                        <li>224ร—224 RGB image = 150,528 input features</li>
                        <li>Fully connected layer with 1000 neurons = 150M parameters!</li>
                        <li>Result: Overfitting, slow training, memory issues</li>
                    </ul>
                    
                    <h3>Solution: Convolutional Neural Networks</h3>
                    <ul>
                        <li><strong>Weight Sharing:</strong> Same filter applied everywhere (1000x fewer parameters)</li>
                        <li><strong>Local Connectivity:</strong> Neurons see small patches</li>
                        <li><strong>Translation Invariance:</strong> Detect cat anywhere in image</li>
                    </ul>
                `,
                concepts: `
                    <h3>Why CNNs Beat Fully Connected</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Parameter Efficiency:</strong> 1000ร— fewer parameters through weight sharing</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Translation Equivariance:</strong> Same object โ†’ same activation regardless of position</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ธ Real-World CV</div>
                        <div class="box-content">
                            Face ID, medical imaging (MRI/CT), autonomous drone navigation, manufacturing defect detection, and satellite imagery analysis
                        </div>
                    </div>
                `,
                math: `
                    <h3>The Parameter Explosion Problem</h3>
                    <p>Why do standard Neural Networks fail on images? Let's calculate the parameters for a small image.</p>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: MLP vs Images</div>
                        1. **Input:** 224 ร— 224 pixels with 3 color channels (RGB)<br>
                        2. **Input Size:** 224 ร— 224 ร— 3 = <strong>150,528 features</strong><br>
                        3. **Hidden Layer:** Suppose we want just 1000 neurons.<br>
                        4. **Matrix size:** [1000, 150528]<br>
                        5. **Total Weights:** 1000 ร— 150528 โ‰ˆ <strong>150 Million parameters</strong> for just ONE layer!
                    </div>

                    <h3>The CNN Solution: Weight Sharing</h3>
                    <p>Instead of every neuron looking at every pixel, we use <strong>translation invariance</strong>. If an edge detector works in the top-left, it should work in the bottom-right.</p>
                    
                    <div class="formula">
                        Total Params = (Kernel_H ร— Kernel_W ร— Input_Channels) ร— Num_Filters<br>
                        <br>
                        For a 3x3 filter: (3 ร— 3 ร— 3) ร— 64 = <strong>1,728 parameters</strong><br>
                        Reduction: 150M / 1.7k โ‰ˆ <strong>86,000ร— more efficient!</strong>
                    </div>
                `
            },
            "pooling": {
                overview: `
                    <h3>Pooling Layers</h3>
                    <p>Pooling reduces spatial dimensions while retaining important information.</p>
                    
                    <table>
                        <tr>
                            <th>Type</th>
                            <th>Operation</th>
                            <th>Use Case</th>
                        </tr>
                        <tr>
                            <td>Max Pooling</td>
                            <td>Take maximum value</td>
                            <td><strong>Most common</strong> - preserves strong activations</td>
                        </tr>
                        <tr>
                            <td>Average Pooling</td>
                            <td>Take average</td>
                            <td>Smoother, less common (used in final layers)</td>
                        </tr>
                        <tr>
                            <td>Global Pooling</td>
                            <td>Pool entire feature map</td>
                            <td>Replace FC layers (reduces parameters)</td>
                        </tr>
                    </table>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… Benefits</div>
                        โ€ข Reduces spatial size (faster computation)<br>
                        โ€ข Adds translation invariance<br>
                        โ€ข Prevents overfitting<br>
                        โ€ข Typical: 2ร—2 window, stride 2 (halves dimensions)
                    </div>
                `,
                concepts: `
                    <h3>Pooling Mechanics</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Downsampling:</strong> Reduces Hร—W by pooling factor (typically 2ร—)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>No Learnable Parameters:</strong> Fixed operation (max/average)</div>
                    </div>
                    <div class="formula">
                        Example: 4ร—4 input โ†’ 2ร—2 max pooling โ†’ 2ร—2 output
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Standard CNN Component</div>
                        <div class="box-content">
                            Used after conv layers in AlexNet, VGG, and most classic CNNs to progressively reduce spatial dimensions
                        </div>
                    </div>
                `,
                math: `
                    <h3>Max Pooling: Winning Signal Selection</h3>
                    <p>Pooling operations are non-parametric (no weights). They simply select or average values within a local window.</p>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: 2x2 Max Pooling</div>
                        **Input (4x4):**<br>
                        [1 3 | 2 1]<br>
                        [5 1 | 0 2]<br>
                        -----------<br>
                        [1 1 | 8 2]<br>
                        [0 2 | 4 1]<br>
                        <br>
                        **Output (2x2):**<br>
                        Step 1: max(1, 3, 5, 1) = <strong>5</strong><br>
                        Step 2: max(2, 1, 0, 2) = <strong>2</strong><br>
                        Step 3: max(1, 1, 0, 2) = <strong>2</strong><br>
                        Step 4: max(8, 2, 4, 1) = <strong>8</strong><br>
                        **Final:** [5 2] / [2 8]
                    </div>

                    <h3>Backprop through Pooling</h3>
                    <div class="list-item">
                        <div class="list-num">๐Ÿ’ก</div>
                        <div><strong>Max Pooling:</strong> Gradient is routed ONLY to the neuron that had the maximum value. All others get 0.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">๐Ÿ’ก</div>
                        <div><strong>Average Pooling:</strong> Gradient is distributed evenly among all neurons in the window.</div>
                    </div>
                `
            },
            "cnn-basics": {
                overview: `
                    <h3>CNN Architecture Pattern</h3>
                    <div class="formula">
                        Input โ†’ [Conv โ†’ ReLU โ†’ Pool] ร— N โ†’ Flatten โ†’ FC โ†’ Softmax
                    </div>
                    
                    <h3>Typical Layering Strategy</h3>
                    <ul>
                        <li><strong>Early Layers:</strong> Detect low-level features (edges, textures) - small filters (3ร—3)</li>
                        <li><strong>Middle Layers:</strong> Combine into patterns, parts - more filters, same size</li>
                        <li><strong>Deep Layers:</strong> High-level concepts (faces, objects) - many filters</li>
                        <li><strong>Final FC Layers:</strong> Classification based on learned features</li>
                    </ul>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก Filter Progression</div>
                        Layer 1: 32 filters (edges)<br>
                        Layer 2: 64 filters (textures)<br>
                        Layer 3: 128 filters (patterns)<br>
                        Layer 4: 256 filters (parts)<br>
                        Common pattern: double filters after each pooling
                    </div>
                `,
                concepts: `
                    <h3>Module Design Principles</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Spatial Reduction:</strong> Progressively downsample (224โ†’112โ†’56โ†’28...)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Channel Expansion:</strong> Increase filters as spatial dims decrease</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ All Modern Vision Models</div>
                        <div class="box-content">
                            This pattern forms the backbone of ResNet, MobileNet, EfficientNet - fundamental CNN design
                        </div>
                    </div>
                `,
                math: `
                    <h3>1. The Golden Formula for Output Size</h3>
                    <p>Given Input (W), Filter Size (F), Padding (P), and Stride (S):</p>
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0;">
                        Output Size = โŒŠ(W - F + 2P) / SโŒ‹ + 1
                    </div>

                    <h3>2. Parameter Count Calculation</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Parameters PER Filter:</strong> (F ร— F ร— C_in) + 1 (bias)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Total Parameters:</strong> N_filters ร— ((F ร— F ร— C_in) + 1)</div>
                    </div>

                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain Calculation</div>
                        <strong>Input:</strong> 224x224x3 | <strong>Layer:</strong> 64 filters of 3x3 | <strong>Stride:</strong> 1 | <strong>Padding:</strong> 1<br>
                        1. <strong>Output Size:</strong> (224 - 3 + 2(1))/1 + 1 = 224 (Same Padding)<br>
                        2. <strong>Params:</strong> 64 * (3 * 3 * 3 + 1) = 64 * 28 = <strong>1,792 parameters</strong><br>
                        3. <strong>FLOPs:</strong> 224 * 224 * 1792 โ‰ˆ <strong>90 Million operations</strong> per image!
                    </div>
                `,
                code: `
                    <h3>Building a CNN from Scratch in PyTorch</h3>
                    <p>A complete CNN for classifying CIFAR-10 images (32ร—32 RGB) into 10 categories.</p>
                    <span class="code-title">๐Ÿ“„ cnn_cifar10.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn
<span class="keyword">import</span> torch.nn.functional <span class="keyword">as</span> F

<span class="keyword">class</span> <span class="function">SimpleCNN</span>(nn.Module):
    <span class="string">"""
    Architecture:
    Input (3, 32, 32)
    -> Conv(3->32, 3x3) -> BN -> ReLU -> MaxPool(2x2) -> (32, 16, 16)
    -> Conv(32->64, 3x3) -> BN -> ReLU -> MaxPool(2x2) -> (64, 8, 8)
    -> Conv(64->128, 3x3) -> BN -> ReLU -> MaxPool(2x2) -> (128, 4, 4)
    -> Flatten -> FC(2048, 256) -> Dropout -> FC(256, 10)
    """</span>
    <span class="keyword">def</span> <span class="function">__init__</span>(self):
        super().__init__()
        <span class="comment"># Convolutional layers</span>
        self.conv1 = nn.Conv2d(<span class="number">3</span>, <span class="number">32</span>, kernel_size=<span class="number">3</span>, padding=<span class="number">1</span>)
        self.bn1 = nn.BatchNorm2d(<span class="number">32</span>)
        self.conv2 = nn.Conv2d(<span class="number">32</span>, <span class="number">64</span>, kernel_size=<span class="number">3</span>, padding=<span class="number">1</span>)
        self.bn2 = nn.BatchNorm2d(<span class="number">64</span>)
        self.conv3 = nn.Conv2d(<span class="number">64</span>, <span class="number">128</span>, kernel_size=<span class="number">3</span>, padding=<span class="number">1</span>)
        self.bn3 = nn.BatchNorm2d(<span class="number">128</span>)
        self.pool = nn.MaxPool2d(<span class="number">2</span>, <span class="number">2</span>)  <span class="comment"># Halves spatial dimensions</span>

        <span class="comment"># Fully connected layers</span>
        self.fc1 = nn.Linear(<span class="number">128</span> * <span class="number">4</span> * <span class="number">4</span>, <span class="number">256</span>)
        self.dropout = nn.Dropout(<span class="number">0.5</span>)
        self.fc2 = nn.Linear(<span class="number">256</span>, <span class="number">10</span>)

    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        x = self.pool(F.relu(self.bn1(self.conv1(x))))  <span class="comment"># (B, 32, 16, 16)</span>
        x = self.pool(F.relu(self.bn2(self.conv2(x))))  <span class="comment"># (B, 64, 8, 8)</span>
        x = self.pool(F.relu(self.bn3(self.conv3(x))))  <span class="comment"># (B, 128, 4, 4)</span>
        x = x.view(x.size(<span class="number">0</span>), -<span class="number">1</span>)                      <span class="comment"># Flatten</span>
        x = self.dropout(F.relu(self.fc1(x)))
        x = self.fc2(x)
        <span class="keyword">return</span> x

<span class="comment"># --- Training Setup ---</span>
model = SimpleCNN()
<span class="keyword">print</span>(f<span class="string">"Total parameters: {sum(p.numel() for p in model.parameters()):,}"</span>)
<span class="comment"># Total parameters: ~600K (tiny by today's standards)</span>

criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=<span class="number">0.001</span>)
</div>
`
            },
            "viz-filters": {
                overview: `
                    <h3>What CNNs Learn</h3>
                    <p>CNN filters automatically learn hierarchical visual features:</p>
                    
                    <h3>Layer-by-Layer Visualization</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Layer 1:</strong> Edges and colors (horizontal, vertical, diagonal lines)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Layer 2:</strong> Textures and patterns (corners, curves, simple shapes)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Layer 3:</strong> Object parts (eyes, wheels, windows)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Layer 4-5:</strong> Whole objects (faces, cars, animals)</div>
                    </div>
                `,
                concepts: `
                    <h3>Visualization Techniques</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Activation Maximization:</strong> Find input that maximizes filter response</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Grad-CAM:</strong> Highlight important regions for predictions</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Model Interpretability</div>
                        <div class="box-content">
                            Understanding what CNNs learn helps debug failures, build trust, and improve architecture design
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽจ Art & Style Transfer</div>
                        <div class="box-content">
                            Filter visualizations inspired neural style transfer (VGG features)
                        </div>
                    </div>
                `,
                math: `
                    <h3>Activation Maximization</h3>
                    <p>Find the input x* that maximizes a specific neuron's activation.</p>
                    
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>x* = argmax_x [a_ij(x) - ฮป||x||ยฒ]</strong>
                    </div>
                    
                    <h4>Gradient Ascent on Input:</h4>
                    <div class="formula">
                        x_{t+1} = x_t + ฮฑ ร— โˆ‚a_ij/โˆ‚x<br><br>
                        Where:<br>
                        โ€ข a_ij = activation of neuron (i,j) in layer l<br>
                        โ€ข ฮฑ = step size<br>
                        โ€ข ฮป||x||ยฒ = regularization to keep input natural-looking
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Generate What a Filter "Sees"</div>
                        <strong>Goal:</strong> Find image that maximally activates Conv1 filter #5<br><br>
                        1. Start with x = random noise (224ร—224ร—3)<br>
                        2. Forward pass โ†’ get activation aโ‚… at filter 5<br>
                        3. Backward pass: โˆ‚aโ‚…/โˆ‚x (gradient of activation w.r.t. input)<br>
                        4. Update: x = x + 0.01 ร— โˆ‚aโ‚…/โˆ‚x<br>
                        5. Repeat 100-500 times<br><br>
                        <strong>Result:</strong> Image showing what pattern the filter detects!
                    </div>
                    
                    <h3>Grad-CAM (Gradient-weighted Class Activation Mapping)</h3>
                    <p>Highlight which regions of the image were important for a specific class prediction.</p>
                    
                    <div class="formula" style="background: rgba(255, 107, 53, 0.08); padding: 20px; border-radius: 8px;">
                        <strong>Step 1 - Global Average Pool the Gradients:</strong><br>
                        ฮฑโ‚– = (1/Z) ร— ฮฃแตข ฮฃโฑผ (โˆ‚yแถœ/โˆ‚Aโ‚–โฑสฒ)<br><br>
                        <strong>Step 2 - Weighted Sum of Feature Maps:</strong><br>
                        L_Grad-CAM = ReLU(ฮฃโ‚– ฮฑโ‚– ร— Aโ‚–)<br><br>
                        Where:<br>
                        โ€ข yแถœ = score for class c (before softmax)<br>
                        โ€ข Aโ‚– = k-th feature map of last conv layer<br>
                        โ€ข ฮฑโ‚– = importance weight of feature map k
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Grad-CAM Calculation</div>
                        <strong>Last conv layer:</strong> 14ร—14ร—512 feature maps<br>
                        <strong>Predicted class:</strong> "Dog" (class 5)<br><br>
                        1. Get gradient โˆ‚yโ‚…/โˆ‚A for all 512 feature maps<br>
                        2. Average each gradient map: ฮฑโ‚ = 0.8, ฮฑโ‚‚ = 0.1, ฮฑโ‚ƒ = 0.5...<br>
                        3. Weighted sum: L = 0.8ร—Aโ‚ + 0.1ร—Aโ‚‚ + 0.5ร—Aโ‚ƒ + ...<br>
                        4. Apply ReLU (keep positive contributions only)<br>
                        5. Upsample to input size (14ร—14 โ†’ 224ร—224)<br><br>
                        <strong>Result:</strong> Heatmap showing dog's face/body highlighted!
                    </div>
                    
                    <h3>Saliency Maps (Vanilla Gradient)</h3>
                    <div class="formula">
                        Saliency(x) = |โˆ‚yแถœ/โˆ‚x|<br><br>
                        Take absolute value of gradient of class score w.r.t. input pixels.
                    </div>
                `
            },
            "lenet": {
                overview: `
                    <h3>LeNet-5 (1998) - The Pioneer</h3>
                    <p>First successful CNN for digit recognition (MNIST). Introduced the Conv โ†’ Pool โ†’ Conv โ†’ Pool pattern still used today.</p>
                    
                    <h3>Architecture</h3>
                    <div class="formula">
                        Input 32ร—32 โ†’ Conv(6 filters, 5ร—5) โ†’ AvgPool โ†’ Conv(16 filters, 5ร—5) โ†’ AvgPool โ†’ FC(120) โ†’ FC(84)โ†’ FC(10)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ† Historical Impact</div>
                        โ€ข Used by US Postal Service for zip code recognition<br>
                        โ€ข Proved CNNs work for real-world tasks<br>
                        โ€ข Template for modern architectures
                    </div>
                `,
                concepts: `
                    <h3>Key Innovations</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Layered Architecture:</strong> Hierarchical feature extraction</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Shared Weights:</strong> Convolutional parameter sharing</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">โœ‰๏ธ Handwriting Recognition</div>
                        <div class="box-content">
                            USPS mail sorting, check processing, form digitization
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“š Educational Foundation</div>
                        <div class="box-content">
                            Perfect starting point for learning CNNs - simple enough to understand, complex enough to be useful
                        </div>
                    </div>
                `,
                math: `
                    <h3>LeNet-5 Complete Dimension Walkthrough</h3>
                    <p>Follow the tensor shapes through each layer of LeNet-5.</p>
                    
                    <div class="formula" style="font-size: 1.0rem; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 20px; border-radius: 8px;">
                        <strong>Output Size Formula:</strong><br>
                        W_out = (W_in - K + 2P) / S + 1<br>
                        Where K=kernel, P=padding, S=stride
                    </div>
                    
                    <h4>Layer-by-Layer Calculation:</h4>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div>
                            <strong>Input:</strong> 32 ร— 32 ร— 1 (grayscale MNIST)<br>
                            <span class="formula-caption">Original: 28ร—28, padded to 32ร—32</span>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div>
                            <strong>C1 - Conv:</strong> 6 filters, 5ร—5, stride 1, no padding<br>
                            Output: (32 - 5 + 0)/1 + 1 = <strong>28 ร— 28 ร— 6</strong><br>
                            Params: (5ร—5ร—1 + 1) ร— 6 = <strong>156</strong>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div>
                            <strong>S2 - AvgPool:</strong> 2ร—2, stride 2<br>
                            Output: 28/2 = <strong>14 ร— 14 ร— 6</strong><br>
                            Params: 0 (or 12 with learnable coefficients)
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div>
                            <strong>C3 - Conv:</strong> 16 filters, 5ร—5<br>
                            Output: (14 - 5)/1 + 1 = <strong>10 ร— 10 ร— 16</strong><br>
                            Params: (5ร—5ร—6 + 1) ร— 16 = <strong>2,416</strong>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div>
                            <strong>S4 - AvgPool:</strong> 2ร—2, stride 2<br>
                            Output: 10/2 = <strong>5 ร— 5 ร— 16</strong><br>
                            Params: 0
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div>
                            <strong>C5 - Conv:</strong> 120 filters, 5ร—5<br>
                            Output: (5 - 5)/1 + 1 = <strong>1 ร— 1 ร— 120</strong><br>
                            Params: (5ร—5ร—16 + 1) ร— 120 = <strong>48,120</strong>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">07</div>
                        <div>
                            <strong>F6 - FC:</strong> 120 โ†’ 84<br>
                            Params: 120 ร— 84 + 84 = <strong>10,164</strong>
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">08</div>
                        <div>
                            <strong>Output - FC:</strong> 84 โ†’ 10<br>
                            Params: 84 ร— 10 + 10 = <strong>850</strong>
                        </div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Total Parameter Count</div>
                        <strong>Convolutional Layers:</strong><br>
                        C1: 156 + C3: 2,416 + C5: 48,120 = 50,692<br><br>
                        <strong>Fully Connected Layers:</strong><br>
                        F6: 10,164 + Output: 850 = 11,014<br><br>
                        <strong>Total:</strong> โ‰ˆ <strong>61,706 parameters</strong><br><br>
                        Compare to AlexNet's 60 million - LeNet is 1000ร— smaller!
                    </div>
                    
                    <h3>Receptive Field Calculation</h3>
                    <div class="formula">
                        After C1 (5ร—5): Each neuron sees 5ร—5 pixels<br>
                        After S2: Sees 6ร—6 pixels (pooling expands RF)<br>
                        After C3: Sees 14ร—14 pixels<br>
                        After S4: Sees 16ร—16 pixels<br>
                        After C5: <strong>Sees entire 32ร—32 input!</strong>
                    </div>
                `
            },
            "alexnet": {
                overview: `
                    <h3>AlexNet (2012) - The Deep Learning Revolution</h3>
                    <p>Won ImageNet 2012 by huge margin (15.3% vs 26.2% error), igniting the deep learning revolution.</p>
                    
                    <h3>Key Innovations</h3>
                    <ul>
                        <li><strong>ReLU Activation:</strong> Faster training than sigmoid/tanh</li>
                        <li><strong>Dropout:</strong> Prevents overfitting (p=0.5)</li>
                        <li><strong>Data Augmentation:</strong> Random crops/flips</li>
                        <li><strong>GPU Training:</strong> Used 2 GTX580 GPUs</li>
                        <li><strong>Deep:</strong> 8 layers (5 conv + 3 FC), 60M parameters</li>
                    </ul>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก Why So Important?</div>
                        First to show that deeper networks + more data + GPU compute = breakthrough performance
                    </div>
                `,
                concepts: `
                    <h3>Technical Contributions</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>ReLU:</strong> Solved vanishing gradients, enabled deeper networks</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Dropout:</strong> First major regularization for deep nets</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ ImageNet Challenge</div>
                        <div class="box-content">
                            Shattered records on 1000-class classification, proving deep learning superiority
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿš€ Industry Catalyst</div>
                        <div class="box-content">
                            Sparked AI renaissance - Google, Facebook, Microsoft pivoted to deep learning after AlexNet
                        </div>
                    </div>
                `,
                math: `
                    <h3>Paper & Pain: Parameter Counting</h3>
                    <p>Understanding AlexNet's 60M parameters:</p>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Conv Layers:</strong> Only ~2.3 Million parameters. They do most of the work with small memory!</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>FC Layers:</strong> Over **58 Million parameters**. The first FC layer (FC6) takes 4096 * (6*6*256) โ‰ˆ 37M params!</div>
                    </div>
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ The Design Flaw</div>
                        FC layers are the memory bottleneck. Modern models (ResNet, Inception) replace these with Global Average Pooling to save 90% parameters.
                    </div>
                `
            },
            "vgg": {
                overview: `
                    <h3>VGGNet (2014) - The Power of Depth</h3>
                    <p>VGG showed that depth matters - 16-19 layers using only small 3ร—3 filters.</p>
                `,
                concepts: `
                    <h3>Small Filters, Receptive Field</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Uniformity:</strong> Uses 3ร—3 filters everywhere with stride 1, padding 1.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Pooling Pattern:</strong> 2ร—2 max pooling after every 2-3 conv layers.</div>
                    </div>
                `,
                math: `
                    <h3>The 5ร—5 vs 3ร—3+3ร—3 Equivalence</h3>
                    <p>Why stack 3x3 filters instead of one large filter?</p>
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Paramount Efficiency</div>
                        1. **Receptive Field:** Two 3x3 layers cover 5x5 area. Three 3x3 layers cover 7x7 area.<br>
                        2. **Param Count (C filters):**<br>
                        โ€ข One 7x7 layer: 7ยฒ ร— Cยฒ = 49Cยฒ parameters.<br>
                        โ€ข Three 3x3 layers: 3 ร— (3ยฒ ร— Cยฒ) = 27Cยฒ parameters.<br>
                        **Result:** 45% reduction in weights for the SAME "view" of the image!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ–ผ๏ธ Feature Backbone</div>
                        VGG is the preferred architectural backbone for Neural Style Transfer and early GANs due to its simple, clean feature extraction properties.
                    </div>
                `
            },
            "resnet": {
                overview: `
                <p>ResNet (Residual Networks) solved the <strong>degradation problem</strong> โ€” deeper networks were performing WORSE than shallower ones, not because of overfitting, but because gradients couldn't flow through many layers. The solution? <strong>Skip connections</strong> that let gradients bypass layers entirely.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ—๏ธ The Highway Analogy</div>
                    Imagine a highway with an exit ramp. If the road ahead is blocked (gradient vanishes), you can take the exit ramp and bypass the blockage. Skip connections are these exit ramps โ€” they guarantee that information (and gradients) can always flow through the network, even if some layers become useless.
                </div>

                <h3>The Residual Block</h3>
                <p>Instead of learning the full mapping $H(x)$, the block learns the <strong>residual</strong> $F(x) = H(x) - x$. The output is:</p>
                <div class="formula" style="text-align:center;">
                    $$y = F(x, \\{W_i\\}) + x$$
                </div>
                <p><strong>Why this works:</strong> If the optimal mapping is close to identity (common in deep networks), it's much easier for the network to learn $F(x) \\approx 0$ than to learn $H(x) \\approx x$. Pushing weights toward zero is easy; learning a complex identity mapping is hard.</p>

                <h3>ResNet Variants</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Model</th>
                        <th style="padding: 10px; color: var(--cyan);">Layers</th>
                        <th style="padding: 10px; color: var(--cyan);">Parameters</th>
                        <th style="padding: 10px; color: var(--cyan);">Top-1 Accuracy</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">ResNet-18</td><td>18</td><td>11.7M</td><td>69.8%</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">ResNet-34</td><td>34</td><td>21.8M</td><td>73.3%</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">ResNet-50</td><td>50</td><td>25.6M</td><td>76.1%</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">ResNet-101</td><td>101</td><td>44.5M</td><td>77.4%</td></tr>
                    <tr><td style="padding: 8px;">ResNet-152</td><td>152</td><td>60.2M</td><td>78.3%</td></tr>
                </table>

                <div class="callout tip">
                    <div class="callout-title">๐Ÿ’ก Impact</div>
                    ResNet won the 2015 ImageNet competition with 152 layers and 3.6% top-5 error โ€” the first time a neural network surpassed human performance (5.1%). ResNet concepts are now used in virtually every modern architecture.
                </div>
`,
                concepts: `
                    <h3>Identity & Projection Shortcuts</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Identity Shortcut:</strong> Used when dimensions match. y = F(x, {W}) + x</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Projection Shortcut (1ร—1 Conv):</strong> Used when dimensions change. y = F(x, {W}) + W_s x</div>
                    </div>
                `,
                math: `
                    <h3>The Vanishing Gradient Solution</h3>
                    <p>Why do skip connections help? Let's differentiate the output y = F(x) + x:</p>
                    <div class="formula">
                        โˆ‚y/โˆ‚x = โˆ‚F/โˆ‚x + 1
                    </div>
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Gradient Flow</div>
                        The "+1" term acts as a **gradient highway**. Even if the weights in F(x) are small (causing โˆ‚F/โˆ‚x โ†’ 0), the gradient can still flow through the +1 term. <br>
                        This prevents the gradient from vanishing even in networks with 1000+ layers!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ—๏ธ Modern Vision Backbones</div>
                        <div class="box-content">ResNet is the default starting point for nearly all computer vision tasks today (Mask R-CNN, YOLO, etc.).</div>
                    </div>
                `,
                code: `
                    <h3>Skip Connection Math</h3>
                    <div class="formula" style="text-align:center;">
                        $$\\mathcal{H}(x) = \\mathcal{F}(x) + x$$
                        The network learns the <strong>residual</strong> $\\mathcal{F}(x) = \\mathcal{H}(x) - x$ instead of the full mapping.
                    </div>
<span class="code-title">๐Ÿ“„ resnet_pytorch.py</span><div class="code-block"><span class="keyword">import</span> torchvision.models <span class="keyword">as</span> models

<span class="comment"># Load pretrained ResNet-50</span>
model = models.resnet50(weights=<span class="string">"IMAGENET1K_V2"</span>)
<span class="keyword">print</span>(f<span class="string">"Parameters: {sum(p.numel() for p in model.parameters()):,}"</span>)
<span class="comment"># Output: 25,557,032 parameters</span></div>
                `
            },
            "inception": {
                overview: `
                    <h3>Inception/GoogLeNet (2014) - Going Wider</h3>
                    <p>Instead of going deeper, Inception modules go wider - using multiple filter sizes in parallel.</p>
                    
                    <h3>Inception Module</h3>
                    <div class="formula">
                        Input โ†’ [1ร—1 conv] โŠ• [3ร—3 conv] โŠ• [5ร—5 conv] โŠ• [3ร—3 pool] โ†’ Concatenate
                    </div>
                `,
                concepts: `
                    <h3>Core Innovations</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>1ร—1 Bottlenecks:</strong> Dimensionality reduction before expensive convolutions.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Auxiliary Classifiers:</strong> Used during training to combat gradient vanishing in middle layers.</div>
                    </div>
                `,
                math: `
                    <h3>1ร—1 Convolution Math (Network-in-Network)</h3>
                    <p>A 1ร—1 convolution acts like a channel-wise MLP. It maps input channels C to output channels C' using 1ร—1ร—C parameters per filter.</p>
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Compression</div>
                        Input: 28x28x256 | Target: 28x28x512 with 3x3 Filters.<br>
                        **Direct:** 512 * (3*3*256) โ‰ˆ 1.1 Million params.<br>
                        **Inception (1x1 bottleneck to 64):**<br>
                        Step 1 (1x1): 64 * (1*1*256) = 16k params.<br>
                        Step 2 (3x3): 512 * (3*3*64) = 294k params.<br>
                        **Total:** 310k params. **~3.5ร— reduction in parameters!**
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽ๏ธ Computational Efficiency</div>
                        Inception designs are optimized for running deep networks on limited compute budgets.
                    </div>
                `
            },
            "mobilenet": {
                overview: `
                    <h3>MobileNet - CNNs for Mobile Devices</h3>
                    <p>Designed for mobile/embedded vision using depthwise separable convolutions.</p>
                    
                    <h3>Depthwise Separable Convolution</h3>
                    <div class="formula">
                        Standard Conv = Depthwise Conv + Pointwise (1ร—1) Conv
                    </div>
                    
                    <h3>Computation Reduction</h3>
                    <table>
                        <tr>
                            <th>Method</th>
                            <th>Parameters</th>
                            <th>FLOPs</th>
                        </tr>
                        <tr>
                            <td>Standard 3ร—3 Conv</td>
                            <td>3ร—3ร—C_inร—C_out</td>
                            <td>High</td>
                        </tr>
                        <tr>
                            <td>Depthwise Separable</td>
                            <td>3ร—3ร—C_in + C_inร—C_out</td>
                            <td><strong>8-9ร— less!</strong></td>
                        </tr>
                    </table>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… Applications</div>
                        โ€ข Real-time mobile apps (camera filters, AR)<br>
                        โ€ข Edge devices (drones, IoT)<br>
                        โ€ข Latency-critical systems<br>
                        โ€ข Good accuracy with 10-20ร— speedup
                    </div>
                `,
                concepts: `
                    <h3>Efficiency Factors</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Width Multiplier (ฮฑ):</strong> Thins the network by reducing channels.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Resolution Multiplier (ฯ):</strong> Reduces input image size.</div>
                    </div>
                `,
                math: `
                    <h3>Depthwise Separable Math</h3>
                    <p>Standard convolution complexity: Fยฒ ร— C_in ร— C_out ร— H ร— W</p>
                    <p>Separable complexity: (Fยฒ ร— C_in + C_in ร— C_out) ร— H ร— W</p>
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: The 9ร— Speedup</div>
                        Reduction ratio is roughly: 1/C_out + 1/Fยฒ. <br>
                        For 3x3 filters (F=3): Reduction is roughly **1/9th** the computation of standard conv!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ฑ Edge Devices</div>
                        <div class="box-content">Real-time object detection on smartphones, web browsers (TensorFlow.js), and IoT devices.</div>
                    </div>
                `
            },
            "transfer-learning": {
                overview: `
                <p>Transfer learning is the most <strong>practical technique</strong> in modern deep learning. Instead of training from scratch (which requires millions of images and weeks of GPU time), you <strong>reuse a model already trained on a large dataset</strong> (like ImageNet's 14M images) and fine-tune it for your specific task.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽ“ The Education Analogy</div>
                    Transfer learning is like a medical student who already learned anatomy, chemistry, and biology (pretrained knowledge). Instead of re-learning everything from scratch for cardiology (your task), they just need specialized training on heart-related topics. The foundational knowledge <strong>transfers</strong>.
                </div>

                <h3>Two Strategies</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Feature Extraction (Freeze backbone)</strong><br>Freeze all pretrained layers. Only train a new classification head. Best when you have <strong>little data</strong> (&lt;1000 images) or your task is similar to ImageNet.</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Fine-tuning (Unfreeze some layers)</strong><br>Unfreeze the last few layers and train with a very small learning rate (1e-4 to 1e-5). Best when you have <strong>moderate data</strong> (1000-50000 images) or your task is somewhat different.</div></div>

                <h3>When to Use Which Strategy</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Data Size</th>
                        <th style="padding: 10px; color: var(--cyan);">Similar to ImageNet?</th>
                        <th style="padding: 10px; color: var(--cyan);">Strategy</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Small (&lt;1K)</td><td>Yes</td><td>Feature extraction</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Small (&lt;1K)</td><td>No</td><td>Feature extraction + heavy augmentation</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Medium (1K-50K)</td><td>Yes</td><td>Fine-tune last few layers</td></tr>
                    <tr><td style="padding: 8px;">Large (&gt;50K)</td><td>No</td><td>Fine-tune entire network (low lr)</td></tr>
                </table>
`,
                concepts: `
                    <h3>Why Transfer Learning Works</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Feature Hierarchy:</strong> Early layers learn universal features (edges, textures) that transfer across domains</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Domain Similarity:</strong> The more similar source and target domains, the better transfer</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Regularization Effect:</strong> Pre-trained weights act as strong priors, preventing overfitting</div>
                    </div>
                    
                    <h3>Transfer Learning Quadrant</h3>
                    <table>
                        <tr>
                            <th></th>
                            <th>Similar Domain</th>
                            <th>Different Domain</th>
                        </tr>
                        <tr>
                            <td><strong>Large Data</strong></td>
                            <td>Fine-tune all layers</td>
                            <td>Fine-tune top layers</td>
                        </tr>
                        <tr>
                            <td><strong>Small Data</strong></td>
                            <td>Feature extraction</td>
                            <td>Feature extraction (risky)</td>
                        </tr>
                    </table>
                `,
                math: `
                    <h3>Learning Rate Strategies</h3>
                    <p>Different layers need different learning rates during fine-tuning.</p>
                    
                    <div class="formula">
                        Discriminative Fine-tuning:<br>
                        lr_layer_n = lr_base ร— decay^(L-n)<br>
                        <br>
                        Where L = total layers, n = layer index<br>
                        Example: lr_base=1e-3, decay=0.9<br>
                        Layer 1: 1e-3 ร— 0.9^9 โ‰ˆ 3.9e-4<br>
                        Layer 10: 1e-3 ร— 0.9^0 = 1e-3
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Domain Shift</div>
                        When source and target distributions differ:<br>
                        โ€ข <strong>Covariate Shift:</strong> P(X) changes, P(Y|X) same<br>
                        โ€ข <strong>Label Shift:</strong> P(Y) changes, P(X|Y) same<br>
                        โ€ข <strong>Concept Shift:</strong> P(Y|X) changes<br>
                        Transfer learning handles covariate shift well but struggles with concept shift.
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Medical Imaging</div>
                        <div class="box-content">
                            Train on ImageNet, fine-tune for X-ray diagnosis with only 1000 labeled images. Achieves 90%+ accuracy vs 60% from scratch.
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ›’ Retail & E-commerce</div>
                        <div class="box-content">
                            Product classification, visual search, inventory management using pre-trained ResNet/EfficientNet models.
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŒ Satellite Imagery</div>
                        <div class="box-content">
                            Land use classification, deforestation detection, urban planning using models pre-trained on aerial imagery.
                        </div>
                    </div>
                `,
                code: `<span class="code-title">๐Ÿ“„ transfer_learning.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torchvision.models <span class="keyword">as</span> models
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="comment"># --- Load pretrained ResNet-18 ---</span>
model = models.resnet18(weights=<span class="string">"IMAGENET1K_V1"</span>)

<span class="comment"># --- Strategy 1: Feature Extraction (freeze all) ---</span>
<span class="keyword">for</span> param <span class="keyword">in</span> model.parameters():
    param.requires_grad = <span class="keyword">False</span>

<span class="comment"># Replace final layer for 5 classes</span>
model.fc = nn.Linear(model.fc.in_features, <span class="number">5</span>)

<span class="comment"># Only train the new layer</span>
optimizer = torch.optim.Adam(model.fc.parameters(), lr=<span class="number">0.001</span>)

<span class="comment"># --- Strategy 2: Fine-tuning (unfreeze some layers) ---</span>
<span class="keyword">for</span> param <span class="keyword">in</span> model.layer4.parameters():
    param.requires_grad = <span class="keyword">True</span>  <span class="comment"># unfreeze last residual block</span>

<span class="keyword">print</span>(f<span class="string">"Trainable: {sum(p.numel() for p in model.parameters() if p.requires_grad):,}"</span>)</div>
                `
            },
            "localization": {
                overview: `
                    <h3>Object Localization</h3>
                    <p>Predict both class and bounding box for a single object in image.</p>
                    
                    <h3>Multi-Task Loss</h3>
                    <div class="formula">
                        Total Loss = L_classification + ฮป ร— L_bbox<br>
                        <br>
                        Where:<br>
                        L_classification = Cross-Entropy<br>
                        L_bbox = Smooth L1 or IoU loss<br>
                        ฮป = balance term (typically 1-10)
                    </div>
                    
                    <h3>Bounding Box Representation</h3>
                    <ul>
                        <li><strong>Option 1:</strong> (x_min, y_min, x_max, y_max)</li>
                        <li><strong>Option 2:</strong> (x_center, y_center, width, height) โ† Most common</li>
                    </ul>
                `,
                concepts: `
                    <h3>Localization vs Detection</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Classification:</strong> What is in the image? โ†’ "Cat"</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Localization:</strong> Where is the single object? โ†’ "Cat at [100, 50, 200, 150]"</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Detection:</strong> Where are ALL objects? โ†’ Multiple bounding boxes</div>
                    </div>
                    
                    <h3>Network Architecture</h3>
                    <p>Modify a classification network (ResNet, VGG) by adding a regression head:</p>
                    <div class="formula">
                        CNN Backbone โ†’ Feature Map โ†’ [Classification Head (1000 classes)]<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;โ†’ [Regression Head (4 coordinates)]
                    </div>
                `,
                math: `
                    <h3>Smooth L1 Loss (Huber Loss)</h3>
                    <p>Combines L1 and L2 loss for robust bounding box regression.</p>
                    
                    <div class="formula">
                        SmoothL1(x) = { 0.5xยฒ if |x| < 1<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ |x| - 0.5 otherwise
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Why Smooth L1?</div>
                        โ€ข <strong>L2 Loss:</strong> Penalizes large errors too much (squared), sensitive to outliers<br>
                        โ€ข <strong>L1 Loss:</strong> Robust to outliers but has discontinuous gradient at 0<br>
                        โ€ข <strong>Smooth L1:</strong> Best of both worlds - quadratic near 0, linear for large errors
                    </div>
                    
                    <h3>IoU Loss</h3>
                    <div class="formula">
                        L_IoU = 1 - IoU(pred, target)<br>
                        Where IoU = Intersection / Union
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿš— Self-Driving Cars</div>
                        <div class="box-content">Localize the primary vehicle ahead for adaptive cruise control</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ธ Photo Auto-Crop</div>
                        <div class="box-content">Detect main subject and automatically crop to optimal composition</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Medical Imaging</div>
                        <div class="box-content">Localize tumors, organs, or anomalies in X-rays and CT scans</div>
                    </div>
                `
            },
            "rcnn": {
                overview: `
                    <h3>R-CNN Family Evolution</h3>
                    <table>
                        <tr>
                            <th>Model</th>
                            <th>Year</th>
                            <th>Speed (FPS)</th>
                            <th>Key Innovation</th>
                        </tr>
                        <tr>
                            <td>R-CNN</td>
                            <td>2014</td>
                            <td>0.05</td>
                            <td>Selective Search + CNN features</td>
                        </tr>
                        <tr>
                            <td>Fast R-CNN</td>
                            <td>2015</td>
                            <td>0.5</td>
                            <td>RoI Pooling (share conv features)</td>
                        </tr>
                        <tr>
                            <td>Faster R-CNN</td>
                            <td>2015</td>
                            <td>7</td>
                            <td>Region Proposal Network (RPN)</td>
                        </tr>
                        <tr>
                            <td>Mask R-CNN</td>
                            <td>2017</td>
                            <td>5</td>
                            <td>+ Instance Segmentation masks</td>
                        </tr>
                    </table>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก When to Use</div>
                        Faster R-CNN: Best accuracy for detection (not real-time)<br>
                        Mask R-CNN: Detection + instance segmentation
                    </div>
                `,
                concepts: `
                    <h3>Two-Stage Detection Pipeline</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Stage 1 - Region Proposal:</strong> Find ~2000 candidate regions that might contain objects</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Stage 2 - Classification:</strong> Classify each region and refine bounding box</div>
                    </div>
                    
                    <h3>Region Proposal Network (RPN)</h3>
                    <p>The key innovation of Faster R-CNN - learns to propose regions instead of using hand-crafted algorithms.</p>
                    <div class="formula">
                        RPN Output per location:<br>
                        โ€ข k anchor boxes ร— 4 coordinates = 4k regression outputs<br>
                        โ€ข k anchor boxes ร— 2 objectness scores = 2k classification outputs<br>
                        Typical k = 9 (3 scales ร— 3 aspect ratios)
                    </div>
                `,
                math: `
                    <h3>RoI Pooling: Fixed-Size Feature Maps</h3>
                    <p>Convert variable-size regions into fixed 7ร—7 feature maps for FC layers.</p>
                    
                    <div class="formula">
                        For each RoI of size Hร—W:<br>
                        1. Divide into 7ร—7 grid (cells of size H/7 ร— W/7)<br>
                        2. Max-pool each cell โ†’ single value<br>
                        3. Output: Fixed 7ร—7 feature map regardless of input size
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: RoI Align vs RoI Pool</div>
                        <strong>Problem:</strong> RoI Pooling quantizes coordinates, causing misalignment.<br>
                        <strong>Solution:</strong> RoI Align uses bilinear interpolation instead of rounding.<br>
                        This is critical for Mask R-CNN where pixel-level accuracy matters!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Medical Imaging</div>
                        <div class="box-content">High-accuracy tumor detection where speed is less critical than precision</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ท Photo Analysis</div>
                        <div class="box-content">Face detection, scene understanding, object counting in static images</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ”ฌ Scientific Research</div>
                        <div class="box-content">Cell detection, particle tracking, microscopy image analysis</div>
                    </div>
                `
            },
            "ssd": {
                overview: `
                    <h3>SSD (Single Shot MultiBox Detector)</h3>
                    <p>Balances speed and accuracy by predicting boxes at multiple scales.</p>
                    
                    <h3>Key Ideas</h3>
                    <ul>
                        <li><strong>Multi-Scale:</strong> Predictions from different layers (early = small objects, deep = large)</li>
                        <li><strong>Default Boxes (Anchors):</strong> Pre-defined boxes of various aspects ratios</li>
                        <li><strong>Single Pass:</strong> No separate region proposal step</li>
                    </ul>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“Š Performance</div>
                        SSD300: 59 FPS, 74.3% mAP<br>
                        SSD512: 22 FPS, 76.8% mAP<br>
                        <br>
                        Sweet spot between YOLO (faster) and Faster R-CNN (more accurate)
                    </div>
                `,
                concepts: `
                    <h3>Multi-Scale Feature Maps</h3>
                    <p>SSD makes predictions at multiple layers, each detecting objects at different scales.</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Early Layers (38ร—38):</strong> Detect small objects (high resolution)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Middle Layers (19ร—19, 10ร—10):</strong> Detect medium objects</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Deep Layers (5ร—5, 3ร—3, 1ร—1):</strong> Detect large objects</div>
                    </div>
                    
                    <h3>Default Boxes (Anchors)</h3>
                    <p>At each feature map cell, SSD predicts offsets for k default boxes with different aspect ratios (1:1, 2:1, 1:2, 3:1, 1:3).</p>
                `,
                math: `
                    <h3>SSD Loss Function</h3>
                    <p>Weighted sum of localization and confidence losses.</p>
                    
                    <div class="formula">
                        L(x, c, l, g) = (1/N) ร— [L_conf(x, c) + ฮฑ ร— L_loc(x, l, g)]<br>
                        <br>
                        Where:<br>
                        โ€ข L_conf = Softmax loss over class confidences<br>
                        โ€ข L_loc = Smooth L1 loss over box coordinates<br>
                        โ€ข ฮฑ = Weight factor (typically 1)<br>
                        โ€ข N = Number of matched default boxes
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Hard Negative Mining</div>
                        Problem: Most default boxes are background (class imbalance).<br>
                        Solution: Sort negative boxes by confidence loss, pick top ones so pos:neg = 1:3.<br>
                        This focuses training on hard negatives, not easy ones.
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“น Video Analytics</div>
                        <div class="box-content">Real-time object detection in security cameras, sports broadcasting</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿค– Robotics</div>
                        <div class="box-content">Object detection for manipulation tasks, obstacle avoidance</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ฑ Mobile Apps</div>
                        <div class="box-content">Lightweight models for on-device detection (MobileNet-SSD)</div>
                    </div>
                `
            },
            "semantic-seg": {
                overview: `
                    <h3>Semantic Segmentation</h3>
                    <p>Classify every pixel in the image (pixel-wise classification).</p>
                    
                    <h3>Popular Architectures</h3>
                    <table>
                        <tr>
                            <th>Model</th>
                            <th>Key Feature</th>
                        </tr>
                        <tr>
                            <td>FCN</td>
                            <td>Fully Convolutional (no FC layers)</td>
                        </tr>
                        <tr>
                            <td>U-Net</td>
                            <td>Skip connections from encoder to decoder</td>
                        </tr>
                        <tr>
                            <td>DeepLab</td>
                            <td>Atrous (dilated) convolutions + ASPP</td>
                        </tr>
                    </table>
                    
                    <div class="formula">
                        U-Net Pattern:<br>
                        Input โ†’ Encoder (downsample) โ†’ Bottleneck โ†’ Decoder (upsample) โ†’ Pixel-wise Output<br>
                        With skip connections from encoder to decoder at each level
                    </div>
                `,
                concepts: `
                    <h3>Key Concepts</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Encoder-Decoder:</strong> Downsample to capture context, upsample to recover spatial detail</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Skip Connections:</strong> Pass high-resolution features from encoder to decoder (U-Net)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Atrous Convolution:</strong> Expand receptive field without losing resolution (DeepLab)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>ASPP:</strong> Atrous Spatial Pyramid Pooling - capture multi-scale context</div>
                    </div>
                `,
                math: `
                    <h3>Dice Loss for Segmentation</h3>
                    <p>Better than cross-entropy for imbalanced classes (small objects).</p>
                    
                    <div class="formula">
                        Dice = 2 ร— |A โˆฉ B| / (|A| + |B|)<br>
                        Dice Loss = 1 - Dice<br>
                        <br>
                        Where A = predicted mask, B = ground truth mask
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Why Dice > Cross-Entropy?</div>
                        If only 1% of pixels are foreground:<br>
                        โ€ข Cross-Entropy: Model can get 99% accuracy by predicting all background!<br>
                        โ€ข Dice: Penalizes missed foreground pixels heavily<br>
                        โ€ข Often use combination: L = BCE + Dice
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Medical Imaging</div>
                        <div class="box-content">Tumor segmentation, organ delineation, cell analysis</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿš— Autonomous Driving</div>
                        <div class="box-content">Road segmentation, free space detection, drivable area</div>
                    </div>
                `
            },
            "instance-seg": {
                overview: `
                    <h3>Instance Segmentation</h3>
                    <p>Detect AND segment each individual object (combines object detection + semantic segmentation).</p>
                    
                    <h3>Difference from Semantic Segmentation</h3>
                    <ul>
                        <li><strong>Semantic:</strong> All "person" pixels get same label</li>
                        <li><strong>Instance:</strong> Person #1, Person #2, Person #3 (separate instances)</li>
                    </ul>
                    
                    <h3>Main Approach: Mask R-CNN</h3>
                    <div class="formula">
                        Faster R-CNN + Segmentation Branch<br>
                        <br>
                        For each RoI:<br>
                        1. Bounding box regression<br>
                        2. Class prediction<br>
                        3. <strong>Binary mask for the object</strong>
                    </div>
                `,
                concepts: `
                    <h3>Mask R-CNN Architecture</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Backbone:</strong> ResNet-50/101 with Feature Pyramid Network (FPN)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>RPN:</strong> Region Proposal Network (same as Faster R-CNN)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>RoI Align:</strong> Better than RoI Pooling (no quantization)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Mask Head:</strong> Small FCN that outputs 28ร—28 binary mask per class</div>
                    </div>
                `,
                math: `
                    <h3>Multi-Task Loss</h3>
                    <p>Mask R-CNN optimizes three losses simultaneously:</p>
                    
                    <div class="formula">
                        L = L_cls + L_box + L_mask<br>
                        <br>
                        Where:<br>
                        โ€ข L_cls = Classification loss (cross-entropy)<br>
                        โ€ข L_box = Bounding box regression (smooth L1)<br>
                        โ€ข L_mask = Binary cross-entropy per-pixel mask loss
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Key Insight: Decoupled Masks</div>
                        Mask R-CNN predicts a binary mask for EACH class independently.<br>
                        This avoids competition between classes and improves accuracy.
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ธ Photo Editing</div>
                        <div class="box-content">Auto-select objects for editing, background removal, composition</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿค– Robotics</div>
                        <div class="box-content">Object manipulation - need exact shape, not just bounding box</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฌ Video Production</div>
                        <div class="box-content">Rotoscoping, VFX, green screen replacement</div>
                    </div>
                `
            },
            "face-recog": {
                overview: `
                    <h3>Face Recognition with Siamese Networks</h3>
                    <p>Learn similarity between faces using metric learning instead of classification.</p>
                    
                    <h3>Triplet Loss Training</h3>
                    <div class="formula">
                        Loss = max(||f(A) - f(P)||ยฒ - ||f(A) - f(N)||ยฒ + margin, 0)<br>
                        <br>
                        Where:<br>
                        A = Anchor (reference face)<br>
                        P = Positive (same person)<br>
                        N = Negative (different person)<br>
                        margin = minimum separation (e.g., 0.2)
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก One-Shot Learning</div>
                        After training, recognize new people with just 1-2 photos!<br>
                        No retraining needed - just compare embeddings.
                    </div>
                `,
                concepts: `
                    <h3>Face Recognition Pipeline</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Face Detection:</strong> Find faces in image (MTCNN, RetinaFace)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Alignment:</strong> Normalize face orientation and scale</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Embedding:</strong> Extract 128/512-dim feature vector (FaceNet, ArcFace)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Matching:</strong> Compare embeddings with cosine similarity or L2 distance</div>
                    </div>
                    
                    <h3>Key Models</h3>
                    <table>
                        <tr><th>Model</th><th>Key Innovation</th></tr>
                        <tr><td>FaceNet</td><td>Triplet loss, 128-dim embedding</td></tr>
                        <tr><td>ArcFace</td><td>Additive angular margin loss, SOTA accuracy</td></tr>
                        <tr><td>DeepFace</td><td>Facebook's early success</td></tr>
                    </table>
                `,
                math: `
                    <h3>Triplet Loss Intuition</h3>
                    <p>Push same-person faces closer, different-person faces apart.</p>
                    
                    <div class="formula">
                        ||f(A) - f(P)||ยฒ + margin < ||f(A) - f(N)||ยฒ
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Hard Triplet Mining</div>
                        Easy triplets: Random selection - margin already satisfied, loss=0<br>
                        Hard triplets: Find P closest to anchor, N closest to anchor from different class<br>
                        <strong>Training on hard triplets is critical for convergence!</strong>
                    </div>
                    
                    <h3>ArcFace Angular Margin</h3>
                    <div class="formula">
                        L = -log(e^(sยทcos(ฮธ + m)) / (e^(sยทcos(ฮธ + m)) + ฮฃ e^(sยทcos(ฮธ_j))))<br>
                        Where m = angular margin, s = scale factor
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“ฑ Phone Unlock</div>
                        <div class="box-content">Face ID, biometric authentication</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ”’ Security</div>
                        <div class="box-content">Access control, surveillance, identity verification</div>
                    </div>
                `
            },
            "autoencoders": {
                overview: `
                    <h3>Autoencoders</h3>
                    <p>Unsupervised learning to compress data into latent representation and reconstruct it.</p>
                    
                    <h3>Architecture</h3>
                    <div class="formula">
                        Input โ†’ Encoder โ†’ Latent Code (bottleneck) โ†’ Decoder โ†’ Reconstruction<br>
                        <br>
                        Loss = ||Input - Reconstruction||ยฒ (MSE)
                    </div>
                    
                    <h3>Variants</h3>
                    <ul>
                        <li><strong>Vanilla:</strong> Basic autoencoder</li>
                        <li><strong>Denoising:</strong> Input corrupted, output clean (learns robust features)</li>
                        <li><strong>Variational (VAE):</strong> Probabilistic latent space (for generation)</li>
                        <li><strong>Sparse:</strong> Encourage sparse activations</li>
                    </ul>
                `,
                concepts: `
                    <h3>Key Concepts</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Bottleneck:</strong> Force information compression by using fewer dimensions than input</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Reconstruction:</strong> Learn to recreate input - captures essential features</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Latent Space:</strong> Compressed representation captures data structure</div>
                    </div>
                    
                    <h3>Variational Autoencoder (VAE)</h3>
                    <p>Instead of encoding to a point, encode to a probability distribution (mean + variance).</p>
                    <div class="formula">
                        Encoder outputs: ฮผ (mean) and ฯƒ (standard deviation)<br>
                        Sample: z = ฮผ + ฯƒ ร— ฮต (where ฮต ~ N(0,1))<br>
                        This is the "reparameterization trick" for backprop!
                    </div>
                `,
                math: `
                    <h3>VAE Loss Function (ELBO)</h3>
                    <p>VAE maximizes the Evidence Lower Bound:</p>
                    
                    <div class="formula">
                        L = E[log p(x|z)] - KL(q(z|x) || p(z))<br>
                        <br>
                        Where:<br>
                        โ€ข First term: Reconstruction quality<br>
                        โ€ข Second term: KL divergence regularization (push q toward N(0,1))
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: KL Divergence</div>
                        For Gaussians:<br>
                        KL = -0.5 ร— ฮฃ(1 + log(ฯƒยฒ) - ฮผยฒ - ฯƒยฒ)<br>
                        This has a closed-form solution - no sampling needed!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ—œ๏ธ Compression</div>
                        <div class="box-content">Dimensionality reduction, data compression, feature extraction</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Anomaly Detection</div>
                        <div class="box-content">High reconstruction error = anomaly (fraud detection, defect detection)</div>
                    </div>
                `
            },
            "gans": {
                overview: `
                <p>Generative Adversarial Networks (GANs) are a framework for training generative models using an <strong>adversarial game</strong> between two neural networks: a <strong>Generator</strong> (forger) and a <strong>Discriminator</strong> (detective).</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽจ The Art Forger Analogy</div>
                    The Generator is an art forger trying to create fake paintings that look real. The Discriminator is an art detective trying to spot fakes. As the detective gets better at spotting fakes, the forger improves to fool the detective. Eventually, the forger creates paintings so good that even the detective can't tell them apart from real ones.
                </div>

                <h3>The Min-Max Game</h3>
                <div class="formula" style="text-align:center;">
                    $$\\min_G \\max_D \\; V(D,G) = \\mathbb{E}_{x \\sim p_{data}}[\\log D(x)] + \\mathbb{E}_{z \\sim p_z}[\\log(1 - D(G(z)))]$$
                </div>
                <p><strong>D(x)</strong> = probability that $x$ is real. <strong>G(z)</strong> = fake image generated from noise $z$.</p>

                <h3>GAN Variants</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Variant</th>
                        <th style="padding: 10px; color: var(--cyan);">Innovation</th>
                        <th style="padding: 10px; color: var(--cyan);">Use Case</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">DCGAN</td><td>Convolutional architecture</td><td>Image generation</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">WGAN</td><td>Wasserstein distance (stable training)</td><td>Any generation task</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Pix2Pix</td><td>Paired image-to-image translation</td><td>Sketch โ†’ Photo</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">CycleGAN</td><td>Unpaired image translation</td><td>Horse โ†’ Zebra</td></tr>
                    <tr><td style="padding: 8px;">StyleGAN</td><td>Style-based generation (faces)</td><td>High-res face synthesis</td></tr>
                </table>

                <div class="callout warning">
                    <div class="callout-title">โš ๏ธ GAN Training Challenges</div>
                    <strong>Mode Collapse:</strong> Generator produces only one type of output. Solution: use WGAN or add diversity penalties.<br>
                    <strong>Training Instability:</strong> G and D can oscillate without converging. Solution: use spectral normalization, gradient penalty.<br>
                    <strong>Evaluation:</strong> Hard to objectively measure quality. Metrics like FID (Frรฉchet Inception Distance) help but aren't perfect.
                </div>
`,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐ŸŽจ Image Generation</div>
                        <div class="box-content">
                            <strong>StyleGAN:</strong> Photorealistic faces, art generation<br>
                            <strong>DCGAN:</strong> Bedroom images, object generation
                        </div>
                    </div>
                `,
                math: `
                    <h3>The Minimax Game Objective</h3>
                    <p>The original GAN objective from Ian Goodfellow (2014) is a zero-sum game between Discriminator (D) and Generator (G).</p>
                    
                    <div class="formula" style="font-size: 1.1rem; padding: 20px;">
                        min_G max_D V(D, G) = E_xโˆผp_data[log D(x)] + E_zโˆผp_z[log(1 - D(G(z)))]
                    </div>

                    <h3>Paper & Pain: Finding the Optimal Discriminator</h3>
                    <p>For a fixed Generator, the optimal Discriminator D* is:</p>
                    <div class="formula">
                        D*(x) = p_data(x) / (p_data(x) + p_g(x))
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Theoretical Insight</div>
                        When the Discriminator is optimal, the Generator's task is essentially to minimize the <strong>Jensen-Shannon Divergence (JSD)</strong> between the data distribution and the model distribution. <br>
                        <strong>Problem:</strong> JSD is "flat" when distributions don't overlap, leading to vanishing gradients. This is why <strong>Wasserstein GAN (WGAN)</strong> was inventedโ€”using Earth Mover's distance instead!
                    </div>

                    <h3>Generator Gradient Problem</h3>
                    <p>Early in training, D(G(z)) is near 0. The term log(1-D(G(z))) has a very small gradient. </p>
                    <div class="list-item">
                        <div class="list-num">๐Ÿ’ก</div>
                        <div><strong>Heuristic Fix:</strong> Instead of minimizing log(1-D(G(z))), we maximize <strong>log D(G(z))</strong>. This provides much stronger gradients early on!</div>
                    </div>
                `,
                code: `
                    <h3>GAN Objective (Min-Max Game)</h3>
                    <div class="formula" style="text-align:center;">
                        $$\\min_G \\max_D \\; V(D,G) = \\mathbb{E}_{x \\sim p_{data}}[\\log D(x)] + \\mathbb{E}_{z \\sim p_z}[\\log(1 - D(G(z)))]$$
                    </div>
                    <p><strong>Generator</strong> tries to minimize โ€” create fakes so good that $D(G(z)) \\to 1$. <strong>Discriminator</strong> tries to maximize โ€” correctly classify real vs fake.</p>
<span class="code-title">๐Ÿ“„ dcgan.py</span><div class="code-block"><span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="keyword">class</span> <span class="class-name">Generator</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self, latent_dim=<span class="number">100</span>):
        <span class="builtin">super</span>().__init__()
        self.net = nn.Sequential(
            nn.ConvTranspose2d(latent_dim, <span class="number">512</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">0</span>),
            nn.BatchNorm2d(<span class="number">512</span>), nn.ReLU(),
            nn.ConvTranspose2d(<span class="number">512</span>, <span class="number">256</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>),
            nn.BatchNorm2d(<span class="number">256</span>), nn.ReLU(),
            nn.ConvTranspose2d(<span class="number">256</span>, <span class="number">128</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>),
            nn.BatchNorm2d(<span class="number">128</span>), nn.ReLU(),
            nn.ConvTranspose2d(<span class="number">128</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>),
            nn.Tanh(),  <span class="comment"># Output: [-1, 1]</span>
        )
    <span class="keyword">def</span> <span class="function">forward</span>(self, z):
        <span class="keyword">return</span> self.net(z.view(-<span class="number">1</span>, <span class="number">100</span>, <span class="number">1</span>, <span class="number">1</span>))

<span class="keyword">class</span> <span class="class-name">Discriminator</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self):
        <span class="builtin">super</span>().__init__()
        self.net = nn.Sequential(
            nn.Conv2d(<span class="number">3</span>, <span class="number">64</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>),
            nn.LeakyReLU(<span class="number">0.2</span>),
            nn.Conv2d(<span class="number">64</span>, <span class="number">128</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>),
            nn.BatchNorm2d(<span class="number">128</span>), nn.LeakyReLU(<span class="number">0.2</span>),
            nn.Conv2d(<span class="number">128</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">0</span>),
            nn.Sigmoid(),
        )
    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        <span class="keyword">return</span> self.net(x).view(-<span class="number">1</span>)</div>
                `
            },
            "diffusion": {
                overview: `
                    <h3>Diffusion Models</h3>
                    <p>Learn to reverse a gradual noising process, generating high-quality images.</p>
                    
                    <h3>How Diffusion Works</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Forward Process:</strong> Gradually add Gaussian noise over T steps (xโ‚€ โ†’ xโ‚ โ†’ ... โ†’ x_T = pure noise)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Reverse Process:</strong> Train neural network to denoise (x_T โ†’ x_{T-1} โ†’ ... โ†’ xโ‚€ = clean image)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Generation:</strong> Start from random noise, iteratively denoise T steps</div>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… Advantages over GANs</div>
                        โ€ข More stable training (no adversarial dynamics)<br>
                        โ€ข Better sample quality and diversity<br>
                        โ€ข Mode coverage (no mode collapse)<br>
                        โ€ข Controllable generation (text-to-image)
                    </div>
                `,
                concepts: `
                    <h3>Key Components</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>U-Net Backbone:</strong> Encoder-decoder with skip connections predicts noise at each step</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Time Embedding:</strong> Tell the model which timestep it's at (sinusoidal encoding)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>CLIP Conditioning:</strong> Guide generation with text embeddings (Stable Diffusion)</div>
                    </div>
                    
                    <h3>Latent Diffusion</h3>
                    <p>Instead of diffusing in pixel space (expensive), work in VAE latent space (8ร— smaller).</p>
                    <div class="formula">
                        Image (512ร—512ร—3) โ†’ VAE Encoder โ†’ Latent (64ร—64ร—4) โ†’ Diffuse โ†’ Decode
                    </div>
                `,
                math: `
                    <h3>Forward Process (Noising)</h3>
                    <p>Add Gaussian noise according to a schedule ฮฒ_t:</p>
                    
                    <div class="formula">
                        q(x_t | x_{t-1}) = N(x_t; โˆš(1-ฮฒ_t) ร— x_{t-1}, ฮฒ_t ร— I)<br>
                        <br>
                        Or in closed form for any t:<br>
                        x_t = โˆš(แพฑ_t) ร— x_0 + โˆš(1-แพฑ_t) ร— ฮต<br>
                        Where แพฑ_t = ฮ _{s=1}^t (1-ฮฒ_s)
                    </div>
                    
                    <h3>Training Objective</h3>
                    <p>Simple noise prediction loss:</p>
                    <div class="formula">
                        L = E[||ฮต - ฮต_ฮธ(x_t, t)||ยฒ]
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Simplified Loss</div>
                        The full variational bound is complex, but Ho et al. (2020) showed this simple MSE loss on noise prediction works just as well and is much easier to implement!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ–ผ๏ธ Text-to-Image</div>
                        <div class="box-content">
                            <strong>Stable Diffusion:</strong> Open-source, runs on consumer GPUs<br>
                            <strong>DALL-E 2:</strong> OpenAI's photorealistic generator<br>
                            <strong>Midjourney:</strong> Artistic image generation
                        </div>
                    </div>
                `
            },
            "rnn": {
                overview: `
                <p>Recurrent Neural Networks (RNNs) are designed for <strong>sequential data</strong> โ€” text, time series, audio, video frames. Unlike feedforward networks that process inputs independently, RNNs have a <strong>memory</strong> (hidden state) that carries information from previous time steps.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ“– The Reading Analogy</div>
                    When you read a sentence, you don't forget the beginning when you reach the end. Your brain maintains context. RNNs do the same โ€” they process one word (token) at a time while maintaining a hidden state that summarizes everything seen so far.
                </div>

                <h3>Vanilla RNN vs. LSTM vs. GRU</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Feature</th>
                        <th style="padding: 10px; color: var(--cyan);">Vanilla RNN</th>
                        <th style="padding: 10px; color: var(--cyan);">LSTM</th>
                        <th style="padding: 10px; color: var(--cyan);">GRU</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Memory</td><td>Short (5-10 steps)</td><td>Long (100+ steps)</td><td>Long</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Gates</td><td>None</td><td>3 (forget, input, output)</td><td>2 (reset, update)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Parameters</td><td>Fewest</td><td>Most (4x hidden_dimยฒ)</td><td>Middle (3x hidden_dimยฒ)</td></tr>
                    <tr><td style="padding: 8px;">Use Today?</td><td>โŒ Rarely</td><td>โœ… Still useful</td><td>โœ… Often preferred</td></tr>
                </table>

                <h3>The Vanishing Gradient Problem in RNNs</h3>
                <p>Vanilla RNNs multiply the gradient by the same weight matrix at each time step. After many steps, the gradient either <strong>vanishes</strong> (matrix eigenvalues &lt; 1) or <strong>explodes</strong> (eigenvalues &gt; 1). LSTMs solve this with a special <strong>cell state</strong> highway that allows gradients to flow unchanged over many steps.</p>

                <div class="callout tip">
                    <div class="callout-title">๐Ÿ”ฎ Historical Note</div>
                    RNNs dominated NLP from 2013-2017. The Transformer architecture (2017) has now largely replaced them because Transformers can process all tokens in parallel, while RNNs must process sequentially. However, RNNs are still used for real-time streaming data and edge devices.
                </div>
`,
                concepts: `
                    <h3>Step-by-Step LSTM Walkthrough</h3>
                    <p>LSTMs control the cell state via "Gates".</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Forget Gate layer:</strong> "What do we throw away?"<br>
                        <span class="formula-caption">ฯƒ(W_f ยท [h_{t-1}, x_t] + b_f)</span><br>
                        Output 0 = complete forget, 1 = keep everything.</div>
                    </div>
                    
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Input Gate layer:</strong> "What new info do we add?"<br>
                        1. Sigmoid layer decides <strong>which values</strong> to update.<br>
                        2. Tanh layer creates <strong>new candidate values</strong> (~C_t).</div>
                    </div>
                    
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Update Cell State:</strong> The Critical Step<br>
                        <span class="formula" style="font-size:1.1rem">C_t = f_t * C_{t-1} + i_t * ~C_t</span><br>
                        We multiply old state by f_t (forgetting things) and add i_t * ~C_t (adding new things).</div>
                    </div>
                    
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Output Gate:</strong> "What do we reveal?"<br>
                        We filter the cell state: h_t = o_t * tanh(C_t).</div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก Intuition: Sigmoid vs Tanh</div>
                        โ€ข <strong>Sigmoid (0 to 1):</strong> Acts like a valve or gate. Open/Close.<br>
                        โ€ข <strong>Tanh (-1 to 1):</strong> Creates content/information. Normalized centered data.
                    </div>
                `,
                math: `
                    <h3>Paper & Pain: Why LSTMs Don't Vanish</h3>
                    <p>Let's look at the gradient flow in the Cell State equation:</p>
                    <div class="formula">
                        C_t = f_t \\cdot C_{t-1} + i_t \\cdot \\tilde{C}_t
                    </div>
                    
                    <p>During backpropagation (BPTT), the derivative of C_t with respect to C_{t-1} is:</p>
                    <div class="formula" style="color: #00ff88;">
                        \\frac{\\partial C_t}{\\partial C_{t-1}} = f_t + \\dots
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">โœ… The Additive Gradient Highway</div>
                        In standard RNNs, we had multiplicative gradients (W^t). <br>
                        In LSTMs, the gradient is <strong>additive</strong>. If the Forget Gate f_t โ‰ˆ 1, the gradient passes through UNCHANGED (1.0).<br>
                        The error signal can travel back 1000 steps without vanishing!
                    </div>

                    <h3>Paper & Pain: Manual "Echo" Task</h3>
                    <p>Task: Input stream of 0s. If explicit "1" appears, remember it and output "1" 3 steps later.</p>
                    <div class="list-item">
                        <div class="list-num">๐Ÿ“</div>
                        <div><strong>Strategy:</strong> Set Input Gate to Open (1) only on trigger. Set Forget Gate to Closed (1) to maintain memory.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">๐Ÿงฎ</div>
                        <div><strong>Weights:</strong> We can manually solve for weights that force i_t high only when x_t=1.</div>
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ—ฃ๏ธ Sequence-to-Sequence</div>
                        <div class="box-content">
                            <strong>Translation:</strong> Google Translate (pre-Transformer) used massive LSTM stacks (GNMT).
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">โœ๏ธ Handwriting Generation</div>
                        <div class="box-content">
                            <strong>Alex Graves (2013):</strong> LSTMs can generate realistic cursive handwriting by predicting pen coordinates.
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽต Music Composition</div>
                        <div class="box-content">
                            Generating melody and chords where context (key signature, tempo) must be maintained for minutes.
                        </div>
                    </div>
                `,
                code: `
                    <h3>LSTM Cell Equations</h3>
                    <div class="formula" style="text-align:center;">
                        <strong>Forget Gate:</strong> $$f_t = \\sigma(W_f \\cdot [h_{t-1}, x_t] + b_f)$$
                        <strong>Input Gate:</strong> $$i_t = \\sigma(W_i \\cdot [h_{t-1}, x_t] + b_i)$$
                        <strong>Cell Update:</strong> $$\\tilde{C}_t = \\tanh(W_C \\cdot [h_{t-1}, x_t] + b_C)$$
                        $$C_t = f_t \\odot C_{t-1} + i_t \\odot \\tilde{C}_t$$
                        <strong>Output Gate:</strong> $$o_t = \\sigma(W_o \\cdot [h_{t-1}, x_t] + b_o)$$
                        $$h_t = o_t \\odot \\tanh(C_t)$$
                    </div>
<span class="code-title">๐Ÿ“„ lstm_sentiment.py</span><div class="code-block"><span class="keyword">import</span> torch
<span class="keyword">import</span> torch.nn <span class="keyword">as</span> nn

<span class="keyword">class</span> <span class="class-name">SentimentLSTM</span>(nn.Module):
    <span class="keyword">def</span> <span class="function">__init__</span>(self, vocab_size, embed_dim, hidden_dim):
        <span class="builtin">super</span>().__init__()
        self.embedding = nn.Embedding(vocab_size, embed_dim)
        self.lstm = nn.LSTM(embed_dim, hidden_dim, batch_first=<span class="keyword">True</span>, bidirectional=<span class="keyword">True</span>)
        self.fc = nn.Linear(hidden_dim * <span class="number">2</span>, <span class="number">1</span>)  <span class="comment"># *2 for bidirectional</span>
    
    <span class="keyword">def</span> <span class="function">forward</span>(self, x):
        embeds = self.embedding(x)                <span class="comment"># (batch, seq_len, embed_dim)</span>
        lstm_out, (h_n, c_n) = self.lstm(embeds)  <span class="comment"># h_n: final hidden states</span>
        hidden = torch.cat((h_n[-<span class="number">2</span>], h_n[-<span class="number">1</span>]), dim=<span class="number">1</span>)
        <span class="keyword">return</span> torch.sigmoid(self.fc(hidden))

model = SentimentLSTM(vocab_size=<span class="number">10000</span>, embed_dim=<span class="number">128</span>, hidden_dim=<span class="number">256</span>)
x = torch.randint(<span class="number">0</span>, <span class="number">10000</span>, (<span class="number">4</span>, <span class="number">50</span>))  <span class="comment"># batch=4, seq_len=50</span>
<span class="keyword">print</span>(model(x).shape)  <span class="comment"># (4, 1)</span></div>
                `
            },
            "bert": {
                overview: `
                <p>BERT (Bidirectional Encoder Representations from Transformers) revolutionized NLP in 2018. Unlike GPT which reads left-to-right, BERT reads <strong>both directions simultaneously</strong>, giving it a deeper understanding of context.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ“ The Fill-in-the-Blank Analogy</div>
                    BERT was trained by randomly masking 15% of words and predicting them using the surrounding context (both left and right). It's like a student learning vocabulary by doing fill-in-the-blank exercises: "The cat sat on the [MASK]" โ†’ "mat". This bidirectional context is what makes BERT so powerful for understanding language.
                </div>

                <h3>Two Training Objectives</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Masked Language Modeling (MLM):</strong> Randomly mask 15% of tokens and predict them. This forces the model to understand context from both sides.</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Next Sentence Prediction (NSP):</strong> Given two sentences, predict if sentence B follows sentence A. This teaches the model inter-sentence relationships. (Note: Later papers showed NSP isn't crucial.)</div></div>

                <h3>BERT vs GPT</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Feature</th>
                        <th style="padding: 10px; color: var(--cyan);">BERT</th>
                        <th style="padding: 10px; color: var(--cyan);">GPT</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Direction</td><td>Bidirectional</td><td>Left-to-right (autoregressive)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Best for</td><td>Understanding (classification, QA, NER)</td><td>Generation (text, code, chat)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Architecture</td><td>Transformer Encoder</td><td>Transformer Decoder</td></tr>
                    <tr><td style="padding: 8px;">Parameters</td><td>110M (base) / 340M (large)</td><td>175B (GPT-3) / 1.7T (GPT-4)</td></tr>
                </table>
`,
                concepts: `
                    <h3>BERT Architecture</h3>
                    <p>BERT uses a multi-layer bidirectional Transformer encoder based on Vaswani et al. (2017).</p>
                    
                    <h3>Model Variants</h3>
                    <table>
                        <tr>
                            <th>Model</th>
                            <th>Layers (L)</th>
                            <th>Hidden Size (H)</th>
                            <th>Attention Heads (A)</th>
                            <th>Parameters</th>
                        </tr>
                        <tr>
                            <td>BERT<sub>BASE</sub></td>
                            <td>12</td>
                            <td>768</td>
                            <td>12</td>
                            <td>110M</td>
                        </tr>
                        <tr>
                            <td>BERT<sub>LARGE</sub></td>
                            <td>24</td>
                            <td>1024</td>
                            <td>16</td>
                            <td>340M</td>
                        </tr>
                    </table>
                    
                    <p><em>Note: BERT<sub>BASE</sub> was designed to match GPT's size for comparison.</em></p>
                    
                    <h3>Input Representation</h3>
                    <p>BERT's input embedding is the sum of three components:</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Token Embeddings:</strong> WordPiece tokenization with 30,000 token vocabulary. Handles unknown words by splitting into subwords (e.g., "playing" โ†’ "play" + "##ing")</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Segment Embeddings:</strong> Learned embedding to distinguish sentence A from sentence B (E<sub>A</sub> or E<sub>B</sub>)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Position Embeddings:</strong> Learned positional encodings (unlike Transformers' sinusoidal), supports sequences up to 512 tokens</div>
                    </div>
                    
                    <div class="formula">
                        Input = Token_Embedding + Segment_Embedding + Position_Embedding
                    </div>
                    
                    <h3>Special Tokens</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿท๏ธ Special Token Usage</div>
                        <div class="box-content">
                            <strong>[CLS]:</strong> Prepended to every input. Final hidden state used for classification tasks<br>
                            <strong>[SEP]:</strong> Separates sentence pairs and marks sequence end<br>
                            <strong>[MASK]:</strong> Replaces masked tokens during pre-training (not used during fine-tuning)
                        </div>
                    </div>
                    
                    <h4>Example Input Format</h4>
                    <div class="formula">
                        [CLS] My dog is cute [SEP] He likes playing [SEP]<br>
                        <br>
                        Tokens:    [CLS] My dog is cute [SEP] He likes play ##ing [SEP]<br>
                        Segments:  E_A   E_A E_A E_A E_A E_A  E_B E_B   E_B  E_B   E_B<br>
                        Positions: 0     1   2   3   4   5    6   7     8    9     10
                    </div>
                    
                    <h3>Fine-tuning for Different Tasks</h3>
                    <table>
                        <tr><th>Task Type</th><th>Input Format</th><th>Output</th></tr>
                        <tr>
                            <td>Classification</td>
                            <td>[CLS] text [SEP]</td>
                            <td>[CLS] representation โ†’ classifier</td>
                        </tr>
                        <tr>
                            <td>Sentence Pair</td>
                            <td>[CLS] sent A [SEP] sent B [SEP]</td>
                            <td>[CLS] representation โ†’ classifier</td>
                        </tr>
                        <tr>
                            <td>Question Answering</td>
                            <td>[CLS] question [SEP] passage [SEP]</td>
                            <td>Start/End span vectors over passage tokens</td>
                        </tr>
                        <tr>
                            <td>Token Classification</td>
                            <td>[CLS] text [SEP]</td>
                            <td>Each token representation โ†’ label</td>
                        </tr>
                    </table>
                `,
                math: `
                    <h3>Pre-training Objective</h3>
                    <p>BERT simultaneously optimizes two unsupervised tasks:</p>
                    
                    <div class="formula">
                        L = L<sub>MLM</sub> + L<sub>NSP</sub>
                    </div>
                    
                    <h3>Masked Language Modeling (MLM)</h3>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: The Masking Strategy</div>
                        <strong>Problem:</strong> Standard left-to-right language modeling can't capture bidirectional context.<br>
                        <strong>Solution:</strong> Randomly mask 15% of tokens and predict them using full context.<br><br>
                        
                        <strong>However:</strong> [MASK] token doesn't appear during fine-tuning!<br>
                        <strong>Clever Fix:</strong> Of the 15% selected tokens:<br>
                        โ€ข 80% โ†’ Replace with [MASK]<br>
                        โ€ข 10% โ†’ Replace with random token<br>
                        โ€ข 10% โ†’ Keep unchanged<br><br>
                        
                        This forces the model to maintain context representations for ALL tokens!
                    </div>
                    
                    <h4>MLM Loss Derivation</h4>
                    <p>Let's work through the MLM objective step by step:</p>
                    
                    <div class="formula">
                        Given input sequence: x = [xโ‚, xโ‚‚, ..., x_n]<br>
                        Masked sequence: xฬƒ = [xฬƒโ‚, xฬƒโ‚‚, ..., xฬƒ_n]<br>
                        <br>
                        Let M = {iโ‚, iโ‚‚, ..., i_m} be indices of masked tokens<br>
                        <br>
                        For each masked position i โˆˆ M:<br>
                        h_i = BERT(xฬƒ)_i  (hidden state at position i)<br>
                        logits_i = W ยท h_i + b  (W โˆˆ โ„^(Vร—H), vocab size V)<br>
                        P(x_i | xฬƒ) = softmax(logits_i)<br>
                        <br>
                        Cross-entropy loss per token:<br>
                        L_i = -log P(x_i | xฬƒ)<br>
                        <br>
                        Total MLM loss:<br>
                        L_MLM = (1/|M|) ฮฃ_{iโˆˆM} L_i<br>
                        L_MLM = -(1/|M|) ฮฃ_{iโˆˆM} log P(x_i | xฬƒ)
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">๐Ÿ“Š Worked Example: MLM Calculation</div>
                        <strong>Input:</strong> "The cat sat on the mat"<br>
                        <strong>After masking (15%):</strong> "The [MASK] sat on the mat"<br>
                        <strong>Target:</strong> Predict "cat" at position 2<br><br>
                        
                        <strong>Step 1:</strong> Forward pass through BERT<br>
                        hโ‚‚ = BERT(xฬƒ)โ‚‚ โˆˆ โ„^768 (for BERT_BASE)<br><br>
                        
                        <strong>Step 2:</strong> Project to vocabulary space<br>
                        logitsโ‚‚ = W ยท hโ‚‚ + b โˆˆ โ„^30000<br><br>
                        
                        <strong>Step 3:</strong> Compute probabilities<br>
                        P(w | xฬƒ) = exp(logitsโ‚‚[w]) / ฮฃ_v exp(logitsโ‚‚[v])<br><br>
                        
                        <strong>Step 4:</strong> Compute loss (assume P("cat"|xฬƒ) = 0.73)<br>
                        L = -log(0.73) = 0.315
                    </div>
                    
                    <h3>Next Sentence Prediction (NSP)</h3>
                    <p>Binary classification task to understand sentence relationships.</p>
                    
                    <div class="formula">
                        Input: [CLS] sentence_A [SEP] sentence_B [SEP]<br>
                        <br>
                        Let C = final hidden state of [CLS] token โˆˆ โ„^H<br>
                        <br>
                        P(IsNext = True) = ฯƒ(W_NSP ยท C)<br>
                        where ฯƒ = sigmoid function, W_NSP โˆˆ โ„^(1ร—H)<br>
                        <br>
                        Binary cross-entropy loss:<br>
                        L_NSP = -[yยทlog(ลท) + (1-y)ยทlog(1-ลท)]<br>
                        where y = 1 if B follows A, else 0
                    </div>
                    
                    <h4>NSP Training Data Generation</h4>
                    <ul>
                        <li><strong>50% IsNext:</strong> B actually follows A in corpus</li>
                        <li><strong>50% NotNext:</strong> B sampled randomly from another document</li>
                    </ul>
                    
                    <h3>Fine-tuning Math: Question Answering (SQuAD)</h3>
                    
                    <div class="formula">
                        Input: [CLS] question [SEP] paragraph [SEP]<br>
                        <br>
                        Let T_i = final hidden state for token i in paragraph<br>
                        <br>
                        Start position logits: S_i = W_start ยท T_i<br>
                        End position logits: E_i = W_end ยท T_i<br>
                        <br>
                        P(start = i) = softmax(S)_i<br>
                        P(end = j) = softmax(E)_j<br>
                        <br>
                        Answer span = tokens from position i to j<br>
                        <br>
                        Training loss:<br>
                        L = -log P(start = i*) - log P(end = j*)<br>
                        where i*, j* are ground truth positions
                    </div>
                `,
                applications: `
                    <h3>SQuAD Benchmark Performance</h3>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ† Stanford Question Answering Dataset (SQuAD)</div>
                        <div class="box-content">
                            <strong>SQuAD 1.1:</strong> 100,000+ question-answer pairs on 500+ Wikipedia articles. Every question has an answer span in the passage.<br><br>
                            <strong>SQuAD 2.0:</strong> Adds 50,000+ unanswerable questions. Models must determine when no answer exists.<br><br>
                            <strong>Evaluation Metrics:</strong><br>
                            โ€ข <strong>EM (Exact Match):</strong> % of predictions matching ground truth exactly<br>
                            โ€ข <strong>F1:</strong> Token-level overlap between prediction and ground truth
                        </div>
                    </div>
                    
                    <h3>SQuAD 1.1 Results</h3>
                    <table>
                        <tr><th>Model</th><th>EM</th><th>F1</th></tr>
                        <tr><td>Human Performance</td><td>82.3</td><td>91.2</td></tr>
                        <tr><td>BERT<sub>BASE</sub></td><td>80.8</td><td>88.5</td></tr>
                        <tr><td>BERT<sub>LARGE</sub></td><td><strong>84.1</strong></td><td><strong>90.9</strong></td></tr>
                    </table>
                    <p><em>BERT<sub>LARGE</sub> surpassed human performance on EM!</em></p>
                    
                    <h3>SQuAD 2.0 Results</h3>
                    <table>
                        <tr><th>Model</th><th>EM</th><th>F1</th></tr>
                        <tr><td>Human Performance</td><td>86.9</td><td>89.5</td></tr>
                        <tr><td>BERT<sub>BASE</sub></td><td>73.7</td><td>76.3</td></tr>
                        <tr><td>BERT<sub>LARGE</sub></td><td><strong>78.7</strong></td><td><strong>81.9</strong></td></tr>
                    </table>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก Example SQuAD Question</div>
                        <strong>Passage:</strong> "The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France."<br><br>
                        <strong>Question:</strong> "In what country is Normandy located?"<br><br>
                        <strong>BERT Answer:</strong> "France" โœ“<br>
                        <strong>Start Token:</strong> position 32<br>
                        <strong>End Token:</strong> position 32
                    </div>
                    
                    <h3>GLUE Benchmark (General Language Understanding Evaluation)</h3>
                    <p>BERT set new state-of-the-art on all 9 GLUE tasks:</p>
                    <table>
                        <tr><th>Task</th><th>Metric</th><th>Previous SOTA</th><th>BERT<sub>LARGE</sub></th></tr>
                        <tr><td>MNLI (NLI)</td><td>Acc</td><td>86.6</td><td><strong>86.7</strong></td></tr>
                        <tr><td>QQP (Paraphrase)</td><td>F1</td><td>66.1</td><td><strong>72.1</strong></td></tr>
                        <tr><td>QNLI (QA/NLI)</td><td>Acc</td><td>87.4</td><td><strong>92.7</strong></td></tr>
                        <tr><td>SST-2 (Sentiment)</td><td>Acc</td><td>93.2</td><td><strong>94.9</strong></td></tr>
                        <tr><td>CoLA (Acceptability)</td><td>Matthew's</td><td>35.0</td><td><strong>60.5</strong></td></tr>
                    </table>
                    
                    <h3>Additional Applications</h3>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Google Search</div>
                        <div class="box-content">
                            In October 2019, Google began using BERT for 1 in 10 English search queries, calling it the biggest leap in 5 years. BERT helps understand search intent and context.
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿท๏ธ Named Entity Recognition (NER)</div>
                        <div class="box-content">
                            BERT excels at identifying entities (person, location, organization) in text by treating it as token classification. Each token gets a label (B-PER, I-PER, B-LOC, etc.).
                        </div>
                    </div>
                    
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“Š Text Classification</div>
                        <div class="box-content">
                            Sentiment analysis, topic classification, spam detection - all benefit from BERT's contextual understanding. Simply use [CLS] representation with a classifier.
                        </div>
                    </div>
                    
                    <h3>Using BERT: Quick Code Example</h3>
                    <div class="formula">
                        # Using Hugging Face Transformers<br>
                        from transformers import BertTokenizer, BertForQuestionAnswering<br>
                        import torch<br>
                        <br>
                        # Load pre-trained model and tokenizer<br>
                        tokenizer = BertTokenizer.from_pretrained('bert-large-uncased-whole-word-masking-finetuned-squad')<br>
                        model = BertForQuestionAnswering.from_pretrained('bert-large-uncased-whole-word-masking-finetuned-squad')<br>
                        <br>
                        # Example<br>
                        question = "What is BERT?"<br>
                        context = "BERT is a bidirectional Transformer for NLP."<br>
                        <br>
                        # Tokenize and get answer<br>
                        inputs = tokenizer(question, context, return_tensors='pt')<br>
                        outputs = model(**inputs)<br>
                        <br>
                        start_idx = torch.argmax(outputs.start_logits)<br>
                        end_idx = torch.argmax(outputs.end_logits)<br>
                        answer = tokenizer.convert_tokens_to_string(<br>
                            tokenizer.convert_ids_to_tokens(inputs['input_ids'][0][start_idx:end_idx+1])<br>
                        )<br>
                        print(answer)  # "a bidirectional Transformer for NLP"
                    </div>
                `,
                code: `
                    <h3>BERT Training Objectives</h3>
                    <div class="formula" style="text-align:center;">
                        <strong>MLM:</strong> $$L_{MLM} = -\\sum_{i \\in M} \\log P(x_i | x_{\\backslash M})$$
                        <strong>NSP:</strong> $$L_{NSP} = -[y\\log(p) + (1-y)\\log(1-p)]$$
                    </div>
<span class="code-title">๐Ÿ“„ bert_huggingface.py</span><div class="code-block"><span class="keyword">from</span> transformers <span class="keyword">import</span> BertTokenizer, BertModel, pipeline

<span class="comment"># --- Quick sentiment analysis ---</span>
classifier = pipeline(<span class="string">"sentiment-analysis"</span>)
result = classifier(<span class="string">"Deep learning is fascinating!"</span>)
<span class="keyword">print</span>(result)  <span class="comment"># [{'label': 'POSITIVE', 'score': 0.9998}]</span>

<span class="comment"># --- BERT Embeddings for custom tasks ---</span>
tokenizer = BertTokenizer.from_pretrained(<span class="string">"bert-base-uncased"</span>)
model = BertModel.from_pretrained(<span class="string">"bert-base-uncased"</span>)

text = <span class="string">"Neural networks learn features automatically"</span>
inputs = tokenizer(text, return_tensors=<span class="string">"pt"</span>)
outputs = model(**inputs)

<span class="comment"># CLS token embedding (sentence representation)</span>
cls_embedding = outputs.last_hidden_state[:, <span class="number">0</span>, :]
<span class="keyword">print</span>(f<span class="string">"Shape: {cls_embedding.shape}"</span>)  <span class="comment"># (1, 768)</span></div>
                `
            },
            "gpt": {
                overview: `
                <p>GPT (Generative Pre-trained Transformer) is the architecture behind ChatGPT, GitHub Copilot, and the AI revolution. It's a <strong>decoder-only Transformer</strong> trained to predict the next token in a sequence โ€” a simple objective that produces remarkably intelligent behavior.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽฏ The Core Idea</div>
                    GPT's entire training objective is <strong>next-token prediction</strong>: given "The cat sat on the", predict "mat". By doing this on trillions of tokens from the internet, the model learns grammar, facts, reasoning, coding, math โ€” all as a byproduct of predicting what comes next. It's arguably the most powerful simple idea in AI.
                </div>

                <h3>The GPT Family</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Model</th>
                        <th style="padding: 10px; color: var(--cyan);">Year</th>
                        <th style="padding: 10px; color: var(--cyan);">Parameters</th>
                        <th style="padding: 10px; color: var(--cyan);">Key Innovation</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">GPT-1</td><td>2018</td><td>117M</td><td>Pretrain on unlabeled text, fine-tune</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">GPT-2</td><td>2019</td><td>1.5B</td><td>Zero-shot task transfer</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">GPT-3</td><td>2020</td><td>175B</td><td>In-context learning, few-shot prompting</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">GPT-4</td><td>2023</td><td>~1.7T (MoE)</td><td>Multimodal (text + images), RLHF</td></tr>
                    <tr><td style="padding: 8px;">GPT-4o</td><td>2024</td><td>Unknown</td><td>Native multimodal (audio, video, text)</td></tr>
                </table>

                <h3>How GPT Generates Text</h3>
                <p>GPT uses <strong>autoregressive generation</strong>: it generates one token at a time, each conditioned on all previous tokens. The process:</p>
                <div class="list-item"><div class="list-num">1</div><div>Feed prompt tokens through the Transformer decoder</div></div>
                <div class="list-item"><div class="list-num">2</div><div>Get probability distribution over vocabulary (~50K tokens)</div></div>
                <div class="list-item"><div class="list-num">3</div><div>Sample from the distribution (temperature, top-k, top-p control randomness)</div></div>
                <div class="list-item"><div class="list-num">4</div><div>Append the new token and repeat from step 1</div></div>
`,
                concepts: `
                    <h3>GPT Architecture</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Decoder Only:</strong> Uses causal (masked) attention - can only see past tokens</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Autoregressive:</strong> Generate one token at a time, feed back as input</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Pre-training:</strong> Next token prediction on massive text corpus</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>RLHF:</strong> Reinforcement Learning from Human Feedback (ChatGPT)</div>
                    </div>
                    
                    <h3>In-Context Learning</h3>
                    <p>GPT-3+ can learn from examples in the prompt without updating weights!</p>
                    <div class="formula">
                        Zero-shot: "Translate to French: Hello" โ†’ "Bonjour"<br>
                        Few-shot: "catโ†’chat, dogโ†’chien, houseโ†’?" โ†’ "maison"
                    </div>
                `,
                math: `
                    <h3>Causal Language Modeling</h3>
                    <p>GPT is trained to maximize the likelihood of the next token:</p>
                    
                    <div class="formula">
                        L = -ฮฃ log P(x_t | x_{<t})<br>
                        <br>
                        Where P(x_t | x_{<t}) = softmax(h_t ร— W_vocab)
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Scaling Laws</div>
                        Performance scales predictably with compute, data, and parameters:<br>
                        L โˆ N^(-0.076) for model size N<br>
                        This is why OpenAI trained GPT-3 (175B) and GPT-4 (1.8T)!
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ฌ ChatGPT & Assistants</div>
                        <div class="box-content">
                            Conversational AI, customer support, tutoring, brainstorming
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ป Code Generation</div>
                        <div class="box-content">
                            GitHub Copilot, code completion, bug fixing, documentation
                        </div>
                    </div>
                `,
                code: `<span class="code-title">๐Ÿ“„ gpt_generation.py</span><div class="code-block"><span class="keyword">from</span> transformers <span class="keyword">import</span> GPT2LMHeadModel, GPT2Tokenizer

tokenizer = GPT2Tokenizer.from_pretrained(<span class="string">"gpt2"</span>)
model = GPT2LMHeadModel.from_pretrained(<span class="string">"gpt2"</span>)

<span class="comment"># Generate text</span>
prompt = <span class="string">"Deep learning has revolutionized"</span>
inputs = tokenizer.encode(prompt, return_tensors=<span class="string">"pt"</span>)

outputs = model.generate(
    inputs, max_length=<span class="number">100</span>,
    temperature=<span class="number">0.7</span>,        <span class="comment"># creativity control</span>
    top_k=<span class="number">50</span>,               <span class="comment"># top-k sampling</span>
    top_p=<span class="number">0.9</span>,              <span class="comment"># nucleus sampling</span>
    do_sample=<span class="keyword">True</span>,
    no_repeat_ngram_size=<span class="number">2</span>,
)

text = tokenizer.decode(outputs[<span class="number">0</span>])
<span class="keyword">print</span>(text)</div>
                `
            },
            "vit": {
                overview: `
                    <h3>Vision Transformer (ViT)</h3>
                    <p>Apply Transformer architecture directly to images by treating them as sequences of patches.</p>
                    
                    <h3>How ViT Works</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Patchify:</strong> Split 224ร—224 image into 16ร—16 patches (14ร—14 = 196 patches)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Linear Projection:</strong> Flatten each patch โ†’ linear embedding (like word embeddings)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Positional Encoding:</strong> Add position information</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Transformer Encoder:</strong> Standard Transformer (self-attention, FFN)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Classification:</strong> Use [CLS] token for final prediction</div>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก When ViT Shines</div>
                        โ€ข <strong>Large Datasets:</strong> Needs 10M+ images (or pre-training on ImageNet-21K)<br>
                        โ€ข <strong>Transfer Learning:</strong> Pre-trained ViT beats CNNs on many tasks<br>
                        โ€ข <strong>Long-Range Dependencies:</strong> Global attention vs CNN's local receptive field
                    </div>
                `,
                concepts: `
                    <h3>ViT vs CNN Comparison</h3>
                    <table>
                        <tr><th>Aspect</th><th>CNN</th><th>ViT</th></tr>
                        <tr><td>Inductive Bias</td><td>Locality, translation invariance</td><td>Minimal - learns from data</td></tr>
                        <tr><td>Data Efficiency</td><td>Better with small datasets</td><td>Needs large datasets</td></tr>
                        <tr><td>Receptive Field</td><td>Local (grows with depth)</td><td>Global from layer 1</td></tr>
                        <tr><td>Scalability</td><td>Diminishing returns</td><td>Scales well with compute</td></tr>
                    </table>
                    
                    <h3>Key Innovations</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>No Convolutions:</strong> Pure attention - "An Image is Worth 16x16 Words"</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Learnable Position:</strong> Position embeddings are learned, not sinusoidal</div>
                    </div>
                `,
                math: `
                    <h3>Patch Embedding</h3>
                    <p>Convert image patches to token embeddings:</p>
                    
                    <div class="formula">
                        z_0 = [x_cls; x_p^1 E; x_p^2 E; ...; x_p^N E] + E_pos<br>
                        <br>
                        Where:<br>
                        โ€ข x_p^i = flattened patch (16ร—16ร—3 = 768 dimensions)<br>
                        โ€ข E = learnable linear projection<br>
                        โ€ข E_pos = position embedding
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Computation</div>
                        ViT-Base: 12 layers, 768 hidden, 12 heads ~ 86M params<br>
                        Self-attention cost: O(nยฒยทd) where n=196 patches<br>
                        This is why ViT is efficient for images (196 tokens) vs text (1000+ tokens)
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ–ผ๏ธ Image Classification</div>
                        <div class="box-content">SOTA on ImageNet with pre-training. Google/DeepMind use for internal systems.</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Object Detection</div>
                        <div class="box-content">DETR, DINO - Transformer-based detection replacing Faster R-CNN</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฌ Video Understanding</div>
                        <div class="box-content">VideoViT, TimeSformer - extend patches to 3D (space + time)</div>
                    </div>
                `
            },
            "seq2seq": {
                overview: `
                    <h3>Seq2Seq with Attention</h3>
                    <p>The architecture that revolutionized Machine Translation (before Transformers).</p>
                    
                    <h3>The Bottleneck Problem</h3>
                    <p>Standard Encoder-Decoder models try to compress the entire sentence "I love deep learning" into a single vector (Context Vector).</p>
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Information Bottleneck</div>
                        For long sentences (e.g., 50 words), the fixed-size vector forgets early details. Performance degrades rapidly with length.
                    </div>
                    
                    <h3>The Attention Solution</h3>
                    <p><strong>Idea:</strong> Don't just look at the last state. Let the Decoder "look back" at ALL Encoder states at every step.</p>
                `,
                concepts: `
                    <h3>Visualizing Attention (Alammar Style)</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Encoder States:</strong> We keep all hidden states $h_1, h_2, h_3, h_4$.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Alignment Scores:</strong> Decoder asks: "How relevant is $h_i$ to what I'm translating now?"</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Context Vector:</strong> Weighted sum of relevant states. If attention is strong on $h_2$, the context vector looks a lot like $h_2$.</div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ’ก The "Searchlight" Analogy</div>
                        Attention is like a searchlight. When generating "รฉtudiant" (student), the light shines brightly on "student" in the input sentence.
                    </div>
                `,
                math: `
                    <h3>Attention Math (Bahdanau / Luong)</h3>
                    <p>Let Decoder state be $s_{t-1}$ and Encoder states be $h_j$.</p>
                    
                    <div class="formula">
                        1. Score: $e_{tj} = score(s_{t-1}, h_j)$ (e.g., Dot Product)<br>
                        2. Weights: $\\alpha_{tj} = softmax(e_{tj})$<br>
                        3. Context: $c_t = \\sum \\alpha_{tj} h_j$<br>
                        4. Output: $s_t = RNN(s_{t-1}, [y_{t-1}, c_t])$
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: Dot Product vs Additive</div>
                        โ€ข <strong>Dot Product (Luong):</strong> $s^T h$ (Fast, matrix mult)<br>
                        โ€ข <strong>Additive (Bahdanau):</strong> $v^T tanh(W_1 s + W_2 h)$ (More parameters, originally better for large dim)
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ—ฃ๏ธ Neural Machine Translation</div>
                        <div class="box-content">Google Translate (2016) switched to GNMT (Attention-based), reducing errors by 60%.</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ“„ Text Summarization</div>
                        <div class="box-content">Focusing on key sentences in a long document to generate a headline.</div>
                    </div>
                `
            },
            "research-papers": {
                overview: `
                    <h3>Seminal Papers Library</h3>
                    <p>A curated collection of the most impactful papers in Deep Learning history, with "Paper & Pain" insights.</p>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐ŸŽ“ How to Read Papers</div>
                        Don't just read the abstract. Look for the <strong>Objective Function</strong> and the <strong>Architecture Diagram</strong>. That's where the truth lies.
                    </div>
                `,
                concepts: `
                    <h3>Computer Vision Hall of Fame</h3>
                    
                    <div class="list-item">
                        <div class="list-num">2012</div>
                        <div><strong>AlexNet</strong> (Krizhevsky et al.)<br>
                        <em>"ImageNet Classification with Deep Convolutional Neural Networks"</em><br>
                        <span class="formula-caption">Insight: Relied on TWO GPUs because 3GB RAM wasn't enough. The split architecture was distinct.</span><br>
                        <a href="https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf" target="_blank" style="color: #ff6b35;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2014</div>
                        <div><strong>VGGNet</strong> (Simonyan & Zisserman)<br>
                        <em>"Very Deep Convolutional Networks for Large-Scale Image Recognition"</em><br>
                        <span class="formula-caption">Insight: 3x3 filters are all you need. Two 3x3 layers have the same receptive field as one 5x5 but fewer parameters.</span><br>
                        <a href="https://arxiv.org/pdf/1409.1556.pdf" target="_blank" style="color: #ff6b35;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2015</div>
                        <div><strong>U-Net</strong> (Ronneberger et al.)<br>
                        <em>"Convolutional Networks for Biomedical Image Segmentation"</em><br>
                        <span class="formula-caption">Insight: Skip connections concatenating features from encoder to decoder allow precise localization.</span><br>
                        <a href="https://arxiv.org/pdf/1505.04597.pdf" target="_blank" style="color: #ff6b35;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2015</div>
                        <div><strong>ResNet</strong> (He et al.)<br>
                        <em>"Deep Residual Learning for Image Recognition"</em><br>
                        <span class="formula-caption">Insight: It's easier to learn 0 than Identity. $f(x) = H(x) - x$.</span><br>
                        <a href="https://arxiv.org/pdf/1512.03385.pdf" target="_blank" style="color: #ff6b35;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2016</div>
                        <div><strong>YOLO</strong> (Redmon et al.)<br>
                        <em>"You Only Look Once: Unified, Real-Time Object Detection"</em><br>
                        <span class="formula-caption">Insight: Treated detection as a <strong>regression</strong> problem, not classification. Single forward pass.</span><br>
                        <a href="https://arxiv.org/pdf/1506.02640.pdf" target="_blank" style="color: #ff6b35;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <hr style="border-color: #333; margin: 20px 0;">
                    
                    <h3>NLP & GenAI Hall of Fame</h3>

                    <div class="list-item">
                        <div class="list-num">2014</div>
                        <div><strong>GANs</strong> (Goodfellow et al.)<br>
                        <em>"Generative Adversarial Networks"</em><br>
                        <span class="formula-caption">Insight: Training a generator by fighting a discriminator. The minimax game: $\\min_G \\max_D V(D, G)$.</span><br>
                        <a href="https://arxiv.org/pdf/1406.2661.pdf" target="_blank" style="color: #a371f7;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2017</div>
                        <div><strong>Attention Is All You Need</strong> (Vaswani et al.)<br>
                        <em>"Transformers"</em><br>
                        <span class="formula-caption">Insight: Sinusoidal Positional Embeddings allow the model to generalize to lengths unseen during training.</span><br>
                        <a href="https://arxiv.org/pdf/1706.03762.pdf" target="_blank" style="color: #00d4ff;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2018</div>
                        <div><strong>BERT</strong> (Devlin et al.)<br>
                        <em>"Pre-training of Deep Bidirectional Transformers"</em><br>
                        <span class="formula-caption">Insight: Masked LM (Cloze task) is inefficient (only 15% signal) but crucial for bidirectionality.</span><br>
                        <a href="https://arxiv.org/pdf/1810.04805.pdf" target="_blank" style="color: #00d4ff;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2020</div>
                        <div><strong>GPT-3</strong> (Brown et al.)<br>
                        <em>"Language Models are Few-Shot Learners"</em><br>
                        <span class="formula-caption">Insight: Scale is all you need. 175B parameters enable emergent behavior like in-context learning.</span><br>
                        <a href="https://arxiv.org/pdf/2005.14165.pdf" target="_blank" style="color: #00d4ff;">๐Ÿ“„ Read PDF</a></div>
                    </div>

                    <div class="list-item">
                        <div class="list-num">2020</div>
                        <div><strong>DDPM</strong> (Ho et al.)<br>
                        <em>"Denoising Diffusion Probabilistic Models"</em><br>
                        <span class="formula-caption">Insight: Predicting the noise $\\epsilon$ is mathematically equivalent to predicting the score function (gradient of data density).</span><br>
                        <a href="https://arxiv.org/pdf/2006.11239.pdf" target="_blank" style="color: #a371f7;">๐Ÿ“„ Read PDF</a></div>
                    </div>
                `,
                math: `
                    <h3>The Formulas That Changed AI</h3>
                    
                    <p><strong>ResNet Residual:</strong></p>
                    <div class="formula">y = F(x, \\{W_i\}) + x</div>
                    
                    <p><strong>Scaled Dot-Product Attention:</strong></p>
                    <div class="formula">Attention(Q, K, V) = softmax(\\frac{QK^T}{\\sqrt{d_k}})V</div>
                    
                    <p><strong>Diffusion Reverse Process:</strong></p>
                    <div class="formula">p_\\theta(x_{t-1}|x_t) = \\mathcal{N}(x_{t-1}; \\mu_\\theta(x_t, t), \\Sigma_\\theta(x_t, t))</div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿš€ Impact</div>
                        <div class="box-content">These papers form the foundation of ChatGPT, Midjourney, Self-Driving Cars, and Facial Recognition.</div>
                    </div>
                `
            },
            "gnn": {
                overview: `
                    <h3>Graph Neural Networks (GNNs)</h3>
                    <p>Deep learning on non-Euclidean data structures like social networks, molecules, and knowledge graphs.</p>
                    
                    <h3>Key Concepts</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Graph Structure:</strong> Nodes (entities) and Edges (relationships).</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Message Passing:</strong> Nodes exchange information with neighbors.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Aggregation:</strong> Combine incoming messages (Sum, Mean, Max).</div>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ’ก Why GNNs?</div>
                        Standard CNNs expect a fixed grid (euclidean). Graphs have arbitrary size and topology. GNNs are permutation invariant!
                    </div>
                `,
                concepts: `
                    <h3>Message Passing Neural Networks (MPNN)</h3>
                    <p>The core framework for most GNNs.</p>
                    
                    <div class="list-item">
                        <div class="list-num">1</div>
                        <div><strong>Message Function:</strong> Compute message from neighbor to node.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">2</div>
                        <div><strong>Aggregation Function:</strong> Sum all messages from neighbors.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">3</div>
                        <div><strong>Update Function:</strong> Update node state based on aggregated messages.</div>
                    </div>
                `,
                math: `
                    <h3>Graph Convolution Network (GCN)</h3>
                    <p>The "Hello World" of GNNs (Kipf & Welling, 2017).</p>
                    
                    <div class="formula">
                        H^{(l+1)} = ฯƒ(D^{-1/2} A D^{-1/2} H^{(l)} W^{(l)})
                    </div>
                    
                    <p>Where:</p>
                    <ul>
                        <li><strong>A:</strong> Adjacency Matrix (connections)</li>
                        <li><strong>D:</strong> Degree Matrix (number of connections)</li>
                        <li><strong>H:</strong> Node Features</li>
                        <li><strong>W:</strong> Learnable Weights</li>
                    </ul>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Over-smoothing</div>
                        If GNN is too deep, all node representations become indistinguishable. Usually 2-4 layers are enough.
                    </div>
                `,
                applications: `
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’Š Drug Discovery</div>
                        <div class="box-content">Predicting molecular properties, protein folding (AlphaFold)</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿš— Traffic Prediction</div>
                        <div class="box-content">Road networks, estimating travel times (Google Maps)</div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ›’ Recommender Systems</div>
                        <div class="box-content">Pinterest (PinSage), User-Item graphs</div>
                    </div>
                `
            },
            "vector-db": {
                overview: `
                <p>Vector databases store and search <strong>high-dimensional embeddings</strong> โ€” the numerical representations that AI models use to understand text, images, and audio. They enable <strong>semantic search</strong>: finding items by meaning, not just keywords.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ“š Traditional DB vs Vector DB</div>
                    <strong>Traditional (SQL):</strong> "Find documents with the word 'dog'" โ†’ Exact keyword match<br>
                    <strong>Vector DB:</strong> "Find documents about pets" โ†’ Returns articles about dogs, cats, hamsters โ€” because their <em>meaning</em> is similar even if they don't share exact words.
                </div>

                <h3>How It Works</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Embed:</strong> Convert text/images into vectors using an embedding model (e.g., OpenAI ada-002, sentence-transformers)</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Index:</strong> Store vectors in a specialized data structure (HNSW, IVF, product quantization) for fast search</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Query:</strong> Convert query to a vector, find the K nearest neighbors using cosine similarity or L2 distance</div></div>

                <h3>Popular Vector Databases</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Database</th>
                        <th style="padding: 10px; color: var(--cyan);">Type</th>
                        <th style="padding: 10px; color: var(--cyan);">Best For</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">ChromaDB</td><td>In-memory, local</td><td>Prototyping, small datasets</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">FAISS (Meta)</td><td>Library</td><td>Billion-scale search, GPU-accelerated</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Pinecone</td><td>Cloud service</td><td>Production SaaS, managed infrastructure</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Weaviate</td><td>Open-source</td><td>Multi-modal search, GraphQL API</td></tr>
                    <tr><td style="padding: 8px;">Milvus</td><td>Open-source</td><td>Enterprise, distributed scaling</td></tr>
                </table>
`,
                concepts: `
                    <h3>Core Concepts</h3>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Embeddings:</strong> Dense numerical representations of data (text, images, etc.) produced by neural networks. Example: OpenAI's text-embedding-3-small produces 1536-dim vectors.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Similarity Metrics:</strong> Cosine similarity (angle), Euclidean distance (L2), Dot product (magnitude-aware). Cosine is most common for text embeddings.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>ANN Algorithms:</strong> Approximate Nearest Neighbor โ€” trade small accuracy loss for massive speed gains (exact search is O(n), ANN is O(log n)).</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>HNSW (Hierarchical Navigable Small World):</strong> Graph-based index. Builds a multi-layer graph where higher layers have fewer, long-range connections. Most popular algorithm.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>IVF (Inverted File Index):</strong> Clusters vectors first (like k-means), then only searches relevant clusters. Fast but requires training step.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div><strong>Product Quantization (PQ):</strong> Compresses vectors by splitting them into sub-vectors and quantizing each. Reduces memory by 10-100x.</div>
                    </div>
                    
                    <h3>Embedding Pipeline</h3>
                    <div class="formul a">
                        1. Raw Data โ†’ Embedding Model โ†’ Vector (e.g., [0.12, -0.34, 0.56, ...])<br>
                        2. Store vector + metadata in Vector DB<br>
                        3. Query: Convert query โ†’ vector โ†’ Find nearest neighbors<br>
                        4. Return top-k most similar results with scores
                    </div>
                    
                    <div class="callout warning">
                        <div class="callout-title">โš ๏ธ Common Pitfalls</div>
                        โ€ข Using wrong distance metric (cosine for normalized, L2 for raw)<br>
                        โ€ข Not chunking documents properly (too large = diluted embedding)<br>
                        โ€ข Mixing embedding models (query and docs must use same model)<br>
                        โ€ข Ignoring metadata filtering (combine vector search + filters)
                    </div>
                `,
                math: `
                    <h3>๐Ÿ“ Paper & Pain: Vector Similarity Mathematics</h3>
                    
                    <h4>Cosine Similarity</h4>
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>cos(A, B) = (A ยท B) / (||A|| ร— ||B||)</strong>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Manual Calculation</div>
                        <strong>A = [1, 2, 3], B = [4, 5, 6]</strong><br><br>
                        <strong>Step 1 โ€” Dot Product:</strong><br>
                        A ยท B = (1ร—4) + (2ร—5) + (3ร—6) = 4 + 10 + 18 = <strong>32</strong><br><br>
                        <strong>Step 2 โ€” Magnitudes:</strong><br>
                        ||A|| = โˆš(1ยฒ + 2ยฒ + 3ยฒ) = โˆš14 โ‰ˆ 3.742<br>
                        ||B|| = โˆš(4ยฒ + 5ยฒ + 6ยฒ) = โˆš77 โ‰ˆ 8.775<br><br>
                        <strong>Step 3 โ€” Cosine Similarity:</strong><br>
                        cos(A, B) = 32 / (3.742 ร— 8.775) = 32 / 32.833 โ‰ˆ <strong>0.9746</strong><br><br>
                        <strong>Interpretation:</strong> Very high similarity (close to 1.0 = identical direction)
                    </div>
                    
                    <h4>Euclidean Distance (L2)</h4>
                    <div class="formula">
                        d(A, B) = โˆš(ฮฃ(aแตข - bแตข)ยฒ)<br><br>
                        For A = [1, 2, 3], B = [4, 5, 6]:<br>
                        d = โˆš((4-1)ยฒ + (5-2)ยฒ + (6-3)ยฒ) = โˆš(9 + 9 + 9) = โˆš27 โ‰ˆ <strong>5.196</strong>
                    </div>
                    
                    <h4>HNSW Complexity</h4>
                    <div class="formula">
                        Build time: O(N ร— log(N))<br>
                        Query time: O(log(N)) โ€” logarithmic!<br>
                        Memory: O(N ร— M) where M = max connections per node<br><br>
                        Compare to brute force: O(N) per query<br>
                        For N = 1 billion vectors: HNSW is ~30 orders of magnitude faster
                    </div>
                `,
                applications: `
                    <h3>Real-World Applications</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Semantic Search</div>
                        <div class="box-content">
                            <strong>Google, Bing, Notion AI:</strong> Search by meaning, not keywords<br>
                            <strong>Example:</strong> "How to fix my car" matches "automobile repair guide" even with zero keyword overlap
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿค– RAG (Retrieval-Augmented Generation)</div>
                        <div class="box-content">
                            Store knowledge base as vectors โ†’ retrieve relevant context โ†’ feed to LLM for grounded answers. Used by ChatGPT with browsing, Perplexity AI, and enterprise AI assistants.
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ›’ Recommendation Systems</div>
                        <div class="box-content">
                            <strong>Spotify (music):</strong> Embed songs as vectors, recommend nearest neighbors<br>
                            <strong>Netflix (movies):</strong> User + content embeddings for personalization
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ–ผ๏ธ Image & Multi-Modal Search</div>
                        <div class="box-content">
                            <strong>CLIP embeddings:</strong> Search images with text queries and vice versa<br>
                            <strong>Google Lens:</strong> Find products by uploading a photo
                        </div>
                    </div>
                `,
                code: `
                    <h3>Similarity Metrics</h3>
                    <div class="formula" style="text-align:center;">
                        <strong>Cosine Similarity:</strong> $$\\cos(\\theta) = \\frac{A \\cdot B}{\\|A\\| \\|B\\|}$$
                        <strong>L2 (Euclidean):</strong> $$d = \\sqrt{\\sum(a_i - b_i)^2}$$
                    </div>
<span class="code-title">๐Ÿ“„ chromadb_example.py</span><div class="code-block"><span class="keyword">import</span> chromadb

client = chromadb.Client()
collection = client.create_collection(<span class="string">"dl_docs"</span>)

<span class="comment"># Add documents</span>
collection.add(
    documents=[<span class="string">"Neural networks use backpropagation"</span>, <span class="string">"CNNs detect visual patterns"</span>],
    ids=[<span class="string">"doc1"</span>, <span class="string">"doc2"</span>],
)

<span class="comment"># Query</span>
results = collection.query(query_texts=[<span class="string">"How do neural nets learn?"</span>], n_results=<span class="number">1</span>)
<span class="keyword">print</span>(results[<span class="string">"documents"</span>])  <span class="comment"># [["Neural networks use backpropagation"]]</span></div>
                `
            },
            "rag": {
                overview: `
                <p>RAG (Retrieval-Augmented Generation) is the <strong>most practical pattern for building AI applications</strong> today. Instead of relying solely on an LLM's training data (which is frozen at training time), RAG retrieves relevant documents from your own knowledge base and includes them in the prompt.</p>

                <div class="callout insight">
                    <div class="callout-title">๐Ÿ’ก Why RAG Matters</div>
                    LLMs have two fundamental problems: (1) they hallucinate โ€” confidently generating false information, and (2) their knowledge has a cutoff date. RAG solves both by grounding the LLM's responses in <strong>actual, verifiable documents</strong> from your data.
                </div>

                <h3>The RAG Pipeline</h3>
                <div class="list-item"><div class="list-num">1</div><div><strong>Ingestion (Offline):</strong> Load documents โ†’ Split into chunks (500-1000 tokens) โ†’ Embed each chunk โ†’ Store in vector DB</div></div>
                <div class="list-item"><div class="list-num">2</div><div><strong>Retrieval (Online):</strong> User asks a question โ†’ Embed the question โ†’ Find K most similar chunks in vector DB</div></div>
                <div class="list-item"><div class="list-num">3</div><div><strong>Generation:</strong> Stuff retrieved chunks into the prompt as context โ†’ LLM generates an answer grounded in the context</div></div>

                <h3>RAG vs. Fine-Tuning</h3>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Aspect</th>
                        <th style="padding: 10px; color: var(--cyan);">RAG</th>
                        <th style="padding: 10px; color: var(--cyan);">Fine-Tuning</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Knowledge updates</td><td>Instant (add new docs)</td><td>Requires retraining</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Hallucination</td><td>Reduced (grounded in docs)</td><td>Can still hallucinate</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Cost</td><td>Low (no training needed)</td><td>High (GPU compute)</td></tr>
                    <tr><td style="padding: 8px;">Best for</td><td>QA over docs, support bots</td><td>Teaching new skills/style</td></tr>
                </table>
`,
                concepts: `
                    <h3>RAG Architecture Deep Dive</h3>
                    
                    <h4>1. Document Processing</h4>
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Loading:</strong> Parse PDFs, HTML, Markdown, Databases, APIs using document loaders (LangChain, LlamaIndex)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Chunking Strategies:</strong><br>
                            โ€ข <strong>Fixed-size:</strong> Split every N tokens (simplest, often good enough)<br>
                            โ€ข <strong>Recursive:</strong> Split by paragraphs โ†’ sentences โ†’ words (preserves structure)<br>
                            โ€ข <strong>Semantic:</strong> Use embeddings to detect topic boundaries<br>
                            โ€ข <strong>Overlap:</strong> Add 10-20% overlap between chunks to preserve context
                        </div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Embedding:</strong> Convert chunks to vectors using models like OpenAI text-embedding-3-small (1536-dim), Cohere embed-v3, or open-source models like BGE-large</div>
                    </div>
                    
                    <h4>2. Retrieval Strategies</h4>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>Dense Retrieval:</strong> Cosine similarity on embeddings (semantic search)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Sparse Retrieval:</strong> BM25/TF-IDF keyword matching (exact term matching)</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div><strong>Hybrid Search:</strong> Combine dense + sparse with Reciprocal Rank Fusion (RRF) โ€” usually best results</div>
                    </div>
                    
                    <h4>3. Advanced RAG Patterns</h4>
                    <div class="list-item">
                        <div class="list-num">07</div>
                        <div><strong>Multi-Query RAG:</strong> LLM generates multiple query variations โ†’ retrieve for each โ†’ merge results</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">08</div>
                        <div><strong>Re-ranking:</strong> Use a cross-encoder (e.g., Cohere Rerank) to re-score retrieved chunks for higher relevance</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">09</div>
                        <div><strong>Query Expansion:</strong> HyDE โ€” generate a hypothetical answer, embed that, then retrieve</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">10</div>
                        <div><strong>Agentic RAG:</strong> LLM decides when and what to retrieve; can self-reflect and re-retrieve if initial results are poor</div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ”‘ Production Checklist</div>
                        โœ… Chunk size 256-512 tokens with 10-20% overlap<br>
                        โœ… Use hybrid search (dense + BM25)<br>
                        โœ… Add re-ranker for precision<br>
                        โœ… Include metadata filtering (date, source, category)<br>
                        โœ… Monitor retrieval quality with evaluation metrics
                    </div>
                `,
                math: `
                    <h3>๐Ÿ“ RAG Evaluation Metrics</h3>
                    
                    <h4>Retrieval Quality</h4>
                    <div class="formula" style="font-size: 1.1rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>Recall@k = |Relevant โˆฉ Retrieved@k| / |Relevant|</strong><br><br>
                        <strong>Precision@k = |Relevant โˆฉ Retrieved@k| / k</strong><br><br>
                        <strong>MRR = 1/|Q| ร— ฮฃ(1 / rank_i)</strong>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Paper & Pain: MRR Calculation</div>
                        <strong>3 queries, first relevant result at ranks 1, 3, 2:</strong><br><br>
                        MRR = (1/3) ร— (1/1 + 1/3 + 1/2)<br>
                        MRR = (1/3) ร— (1.0 + 0.333 + 0.5)<br>
                        MRR = (1/3) ร— 1.833 = <strong>0.611</strong><br><br>
                        <strong>Interpretation:</strong> On average, the first relevant result appears around position 1.6
                    </div>
                    
                    <h4>Reciprocal Rank Fusion (Hybrid Search)</h4>
                    <div class="formula">
                        <strong>RRF(d) = ฮฃ 1 / (k + rank_i(d))</strong><br><br>
                        Where k = 60 (constant), rank_i = rank from retriever i<br><br>
                        Example: Document D appears at rank 2 in dense, rank 5 in sparse:<br>
                        RRF(D) = 1/(60+2) + 1/(60+5) = 0.0161 + 0.0154 = <strong>0.0315</strong>
                    </div>
                    
                    <h4>Chunking Size Impact</h4>
                    <div class="formula">
                        Optimal chunk size depends on:<br>
                        โ€ข Embedding model context window (usually 512 tokens max)<br>
                        โ€ข Query specificity (specific โ†’ smaller chunks)<br>
                        โ€ข Document structure (code โ†’ function-level, prose โ†’ paragraph-level)<br><br>
                        Rule of thumb: <strong>chunk_size โ‰ˆ 2-3ร— expected query length</strong>
                    </div>
                `,
                applications: `
                    <h3>RAG in Production</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ” Perplexity AI</div>
                        <div class="box-content">
                            RAG-powered search engine: retrieves web pages โ†’ feeds to LLM โ†’ generates cited answers. Processes 100M+ queries/month.
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ผ Enterprise Knowledge Bases</div>
                        <div class="box-content">
                            <strong>Notion AI, Glean, Guru:</strong> Index company docs โ†’ answer employee questions with source citations<br>
                            <strong>Legal AI:</strong> Retrieve relevant case law for legal research (Harvey AI)
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ป Code Assistants</div>
                        <div class="box-content">
                            <strong>GitHub Copilot, Cursor:</strong> Retrieve relevant code from the codebase to inform suggestions<br>
                            <strong>Documentation Q&A:</strong> Answer questions about SDKs and libraries
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿฅ Healthcare</div>
                        <div class="box-content">
                            Retrieve medical literature โ†’ generate evidence-based clinical summaries (Google Med-PaLM 2)
                        </div>
                    </div>
                    
                    <div class="callout tip">
                        <div class="callout-title">๐Ÿ› ๏ธ Popular Frameworks</div>
                        โ€ข <strong>LangChain:</strong> Most popular, modular pipeline builder<br>
                        โ€ข <strong>LlamaIndex:</strong> Data-focused, great for document processing<br>
                        โ€ข <strong>Haystack:</strong> Production-ready, NLP-first<br>
                        โ€ข <strong>Semantic Kernel:</strong> Microsoft's enterprise RAG framework
                    </div>
                `,
                code: `<span class="code-title">๐Ÿ“„ rag_langchain.py</span><div class="code-block"><span class="keyword">from</span> langchain.document_loaders <span class="keyword">import</span> PyPDFLoader
<span class="keyword">from</span> langchain.text_splitter <span class="keyword">import</span> RecursiveCharacterTextSplitter
<span class="keyword">from</span> langchain.embeddings <span class="keyword">import</span> OpenAIEmbeddings
<span class="keyword">from</span> langchain.vectorstores <span class="keyword">import</span> Chroma
<span class="keyword">from</span> langchain.chains <span class="keyword">import</span> RetrievalQA
<span class="keyword">from</span> langchain.llms <span class="keyword">import</span> OpenAI

<span class="comment"># 1. Load & chunk documents</span>
loader = PyPDFLoader(<span class="string">"deep_learning_book.pdf"</span>)
docs = loader.load()
splitter = RecursiveCharacterTextSplitter(chunk_size=<span class="number">1000</span>, chunk_overlap=<span class="number">200</span>)
chunks = splitter.split_documents(docs)

<span class="comment"># 2. Create vector store</span>
embeddings = OpenAIEmbeddings()
vectordb = Chroma.from_documents(chunks, embeddings, persist_directory=<span class="string">"./chroma_db"</span>)

<span class="comment"># 3. Query with RAG</span>
qa_chain = RetrievalQA.from_chain_type(
    llm=OpenAI(temperature=<span class="number">0</span>),
    retriever=vectordb.as_retriever(search_kwargs={<span class="string">"k"</span>: <span class="number">3</span>}),
)
answer = qa_chain.run(<span class="string">"What is backpropagation?"</span>)
<span class="keyword">print</span>(answer)</div>
                `
            },
            "advanced-llm": {
                overview: `
                <p>Fine-tuning a 7B+ parameter model requires enormous GPU memory (28GB+ for fp32). <strong>LoRA (Low-Rank Adaptation)</strong> makes this practical by training only a tiny fraction of parameters โ€” typically <strong>0.1% or less</strong> โ€” while achieving similar performance to full fine-tuning.</p>

                <div class="callout insight">
                    <div class="callout-title">๐ŸŽฏ The Key Insight</div>
                    Research showed that pretrained weight matrices have <strong>low intrinsic dimensionality</strong> โ€” meaning changes during fine-tuning can be represented by low-rank matrices. Instead of updating the full dร—d weight matrix W, we add a small update BA where B is dร—r and A is rร—d, with rank r << d.
                </div>

                <h3>LoRA Math</h3>
                <div class="formula" style="text-align:center;">
                    $$W' = W + \\Delta W = W + BA$$
                    $$B \\in \\mathbb{R}^{d \\times r}, \\; A \\in \\mathbb{R}^{r \\times d}, \\; r \\ll d$$
                </div>
                <p><strong>Example:</strong> For a 4096ร—4096 weight matrix (16.7M params), LoRA with r=16 adds only 2ร—4096ร—16 = 131K params โ€” a <strong>128x reduction</strong>.</p>

                <h3>Quantization + LoRA = QLoRA</h3>
                <p>QLoRA takes this further by keeping the base model in <strong>4-bit quantized</strong> format and training LoRA adapters in fp16. This means fine-tuning a 65B model on a <strong>single 48GB GPU</strong>.</p>
                <table style="width:100%; border-collapse: collapse; margin: 15px 0;">
                    <tr style="border-bottom: 2px solid var(--cyan);">
                        <th style="padding: 10px; color: var(--cyan);">Method</th>
                        <th style="padding: 10px; color: var(--cyan);">7B Model Memory</th>
                        <th style="padding: 10px; color: var(--cyan);">Trainable Params</th>
                    </tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Full Fine-tune (fp32)</td><td>28 GB</td><td>7B (100%)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">Full Fine-tune (fp16)</td><td>14 GB</td><td>7B (100%)</td></tr>
                    <tr style="border-bottom: 1px solid rgba(255,255,255,0.1);"><td style="padding: 8px;">LoRA (fp16)</td><td>14 GB</td><td>~4M (0.06%)</td></tr>
                    <tr><td style="padding: 8px;">QLoRA (4-bit)</td><td>~4 GB</td><td>~4M (0.06%)</td></tr>
                </table>
`,
                concepts: `
                    <h3>LoRA (Low-Rank Adaptation)</h3>
                    <p>Instead of updating all parameters, LoRA freezes the original weights and injects small trainable matrices into each layer.</p>
                    
                    <div class="list-item">
                        <div class="list-num">01</div>
                        <div><strong>Core Idea:</strong> Weight update ฮ”W can be decomposed as a low-rank matrix: ฮ”W = B ร— A, where B โˆˆ โ„^(dร—r) and A โˆˆ โ„^(rร—d), with r โ‰ช d</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">02</div>
                        <div><strong>Memory Savings:</strong> For a 7B model, full fine-tuning needs ~28GB VRAM. LoRA (r=16) needs ~6GB โ€” a 4.7x reduction.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">03</div>
                        <div><strong>Rank (r):</strong> Typical values: r=8, 16, 32, 64. Higher rank = more expressiveness but more parameters.</div>
                    </div>
                    
                    <h3>QLoRA (Quantized LoRA)</h3>
                    <div class="list-item">
                        <div class="list-num">04</div>
                        <div><strong>4-bit NormalFloat (NF4):</strong> Quantize frozen weights to 4-bit. Train LoRA adapters in fp16/bf16. Enables fine-tuning 65B models on a single 48GB GPU.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">05</div>
                        <div><strong>Double Quantization:</strong> Quantize the quantization constants themselves โ€” saves additional memory.</div>
                    </div>
                    
                    <h3>Quantization for Deployment</h3>
                    <div class="list-item">
                        <div class="list-num">06</div>
                        <div><strong>GGUF (llama.cpp):</strong> CPU-optimized format. Run Llama-2 70B on a MacBook with Q4_K_M quantization.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">07</div>
                        <div><strong>GPTQ:</strong> GPU-optimized post-training quantization. 3-4 bit with minimal quality loss.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">08</div>
                        <div><strong>AWQ (Activation-aware):</strong> Preserves important weight channels. State-of-the-art quality at 4-bit.</div>
                    </div>
                    
                    <h3>RLHF & DPO</h3>
                    <div class="list-item">
                        <div class="list-num">09</div>
                        <div><strong>RLHF:</strong> Train a reward model from human preferences, then use PPO to optimize the LLM's policy. Used by ChatGPT, Claude.</div>
                    </div>
                    <div class="list-item">
                        <div class="list-num">10</div>
                        <div><strong>DPO (Direct Preference Optimization):</strong> Skip the reward model entirely โ€” optimize directly from preference pairs. Simpler, lower compute, often comparable results.</div>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ” PEFT (Parameter-Efficient Fine-Tuning)</div>
                        PEFT is the umbrella term for all methods that train <1% of parameters:<br>
                        โ€ข <strong>LoRA / QLoRA:</strong> Low-rank weight decomposition<br>
                        โ€ข <strong>Prefix Tuning:</strong> Trainable prefix tokens<br>
                        โ€ข <strong>Adapters:</strong> Small bottleneck layers inserted into frozen model<br>
                        โ€ข <strong>IA3:</strong> Learned rescaling vectors (even fewer params than LoRA)
                    </div>
                `,
                math: `
                    <h3>๐Ÿ“ Paper & Pain: LoRA Mathematics</h3>
                    
                    <h4>Low-Rank Decomposition</h4>
                    <div class="formula" style="font-size: 1.2rem; text-align: center; margin: 20px 0; background: rgba(0, 212, 255, 0.08); padding: 25px; border-radius: 8px;">
                        <strong>W' = W + ฮ”W = W + B ร— A</strong><br>
                        <small>where W โˆˆ โ„^(dร—d), B โˆˆ โ„^(dร—r), A โˆˆ โ„^(rร—d), r โ‰ช d</small>
                    </div>
                    
                    <div class="callout insight">
                        <div class="callout-title">๐Ÿ“ Parameter Count Comparison</div>
                        <strong>Full fine-tuning of one attention layer (d=4096):</strong><br>
                        Parameters = d ร— d = 4096 ร— 4096 = <strong>16,777,216</strong><br><br>
                        <strong>LoRA (r=16):</strong><br>
                        Parameters = d ร— r + r ร— d = 4096 ร— 16 + 16 ร— 4096 = <strong>131,072</strong><br><br>
                        <strong>Reduction: 128x fewer parameters!</strong> (0.78% of original)<br><br>
                        For a full 7B model (all attention layers):<br>
                        Full: ~7B params to train (~28GB VRAM)<br>
                        LoRA (r=16): ~4.2M params to train (~1.5GB for adapters)
                    </div>
                    
                    <h4>Quantization Math</h4>
                    <div class="formula">
                        <strong>Linear Quantization (INT8):</strong><br>
                        q = round(w / scale + zero_point)<br>
                        w_approx = (q - zero_point) ร— scale<br><br>
                        <strong>Example:</strong><br>
                        Weight w = 0.73, scale = 0.01, zero_point = 128<br>
                        q = round(0.73 / 0.01 + 128) = round(201) = 201<br>
                        w_approx = (201 - 128) ร— 0.01 = 0.73 โœ“
                    </div>
                    
                    <h4>Memory Savings</h4>
                    <div class="formula">
                        <strong>Model Size = Parameters ร— Bytes per Parameter</strong><br><br>
                        7B model at fp32: 7B ร— 4 bytes = 28 GB<br>
                        7B model at fp16: 7B ร— 2 bytes = 14 GB<br>
                        7B model at INT8: 7B ร— 1 byte = 7 GB<br>
                        7B model at INT4: 7B ร— 0.5 bytes = 3.5 GB<br><br>
                        <strong>4-bit quantization = 8x memory reduction!</strong>
                    </div>
                    
                    <h4>DPO Loss Function</h4>
                    <div class="formula">
                        L_DPO = -E[log ฯƒ(ฮฒ(log ฯ€_ฮธ(y_w|x) - log ฯ€_ref(y_w|x) - log ฯ€_ฮธ(y_l|x) + log ฯ€_ref(y_l|x)))]<br><br>
                        Where:<br>
                        โ€ข y_w = preferred response, y_l = rejected response<br>
                        โ€ข ฯ€_ฮธ = policy model, ฯ€_ref = reference model<br>
                        โ€ข ฮฒ = temperature controlling deviation from reference
                    </div>
                `,
                applications: `
                    <h3>Production Deployment</h3>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ  Local LLM Deployment</div>
                        <div class="box-content">
                            <strong>Ollama:</strong> One-command local LLM deployment (ollama run llama3)<br>
                            <strong>llama.cpp:</strong> CPU inference with GGUF quantized models<br>
                            <strong>vLLM:</strong> High-throughput GPU serving with PagedAttention
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐ŸŽฏ Domain-Specific Fine-Tuning</div>
                        <div class="box-content">
                            <strong>Medical:</strong> BioMistral, Med-PaLM (clinical notes, diagnoses)<br>
                            <strong>Legal:</strong> SaulLM (contract analysis, case law)<br>
                            <strong>Code:</strong> CodeLlama, StarCoder (code generation, completion)
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ’ฐ Cost Optimization</div>
                        <div class="box-content">
                            <strong>Distillation:</strong> Train a small model to mimic a large one (GPT-4 โ†’ Phi-3)<br>
                            <strong>Speculative Decoding:</strong> Small model drafts, large model verifies (2-3x speedup)<br>
                            <strong>Mixture of Experts:</strong> Only activate 2 of 8 expert networks per token (Mixtral)
                        </div>
                    </div>
                    <div class="info-box">
                        <div class="box-title">๐Ÿ› ๏ธ Key Tools</div>
                        <div class="box-content">
                            <strong>Hugging Face PEFT:</strong> Official LoRA/QLoRA library<br>
                            <strong>Unsloth:</strong> 2x faster fine-tuning with 60% less memory<br>
                            <strong>Axolotl:</strong> Config-driven fine-tuning (no code needed)<br>
                            <strong>TRL:</strong> Transformer Reinforcement Learning (RLHF/DPO)
                        </div>
                    </div>
                `,
                code: `
                    <h3>LoRA Math</h3>
                    <div class="formula" style="text-align:center;">
                        $$W' = W + BA, \\quad B \\in \\mathbb{R}^{d \\times r}, \\; A \\in \\mathbb{R}^{r \\times d}, \\; r \\ll d$$
                        Trainable params: $2 \\times d \\times r$ instead of $d^2$ (e.g., <strong>128x reduction</strong>)
                    </div>
<span class="code-title">๐Ÿ“„ lora_finetuning.py</span><div class="code-block"><span class="keyword">from</span> peft <span class="keyword">import</span> LoraConfig, get_peft_model
<span class="keyword">from</span> transformers <span class="keyword">import</span> AutoModelForCausalLM, AutoTokenizer

<span class="comment"># Load base model</span>
model = AutoModelForCausalLM.from_pretrained(<span class="string">"meta-llama/Llama-2-7b-hf"</span>)

<span class="comment"># Apply LoRA</span>
lora_config = LoraConfig(
    r=<span class="number">16</span>,                  <span class="comment"># rank (lower = fewer params)</span>
    lora_alpha=<span class="number">32</span>,          <span class="comment"># scaling factor</span>
    target_modules=[<span class="string">"q_proj"</span>, <span class="string">"v_proj"</span>],  <span class="comment"># which layers to adapt</span>
    lora_dropout=<span class="number">0.05</span>,
    task_type=<span class="string">"CAUSAL_LM"</span>,
)

model = get_peft_model(model, lora_config)
model.print_trainable_parameters()
<span class="comment"># Output: trainable: 4,194,304 || all: 6,742,609,920 || 0.06%</span></div>
                `
            }
        };


        function createModuleHTML(module) {
            const content = MODULE_CONTENT[module.id] || {};

            return `
                <div class="module" id="${module.id}-module">
                    <button class="btn-back" onclick="switchTo('dashboard')">โ† Back to Dashboard</button>
                    <header>
                        <h1>${module.icon} ${module.title}</h1>
                        <p class="subtitle">${module.description}</p>
                    </header>

                    <div class="tabs">
                        <button class="tab-btn active" onclick="switchTab(event, '${module.id}-overview')">Overview</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-concepts')">Key Concepts</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-visualization')">๐Ÿ“Š Visualization</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-math')">Math</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-applications')">Applications</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-code')">๐Ÿ Python Code</button>
                        <button class="tab-btn" onclick="switchTab(event, '${module.id}-summary')">Summary</button>
                    </div>

                    <div id="${module.id}-overview" class="tab active">
                        <div class="section">
                            <h2>๐Ÿ“– Overview</h2>
                            ${content.overview || `
                                <p>Complete coverage of ${module.title.toLowerCase()}. Learn the fundamentals, mathematics, real-world applications, and implementation details.</p>
                                <div class="info-box">
                                    <div class="box-title">Learning Objectives</div>
                                    <div class="box-content">
                                        โœ“ Understand core concepts and theory<br>
                                        โœ“ Master mathematical foundations<br>
                                        โœ“ Learn practical applications<br>
                                        โœ“ Implement and experiment
                                    </div>
                                </div>
                            `}
                        </div>
                    </div>

                    <div id="${module.id}-concepts" class="tab">
                        <div class="section">
                            <h2>๐ŸŽฏ Key Concepts</h2>
                            ${content.concepts || `
                                <p>Fundamental concepts and building blocks for ${module.title.toLowerCase()}.</p>
                                <div class="callout insight">
                                    <div class="callout-title">๐Ÿ’ก Main Ideas</div>
                                    This section covers the core ideas you need to understand before diving into mathematics.
                                </div>
                            `}
                        </div>
                    </div>

                    <div id="${module.id}-visualization" class="tab">
                        <div class="section">
                            <h2>๐Ÿ“Š Interactive Visualization</h2>
                            <p>Visual representation to help understand ${module.title.toLowerCase()} concepts intuitively.</p>
                            <div id="${module.id}-viz" class="viz-container">
                                <canvas id="${module.id}-canvas" width="800" height="400" style="border: 1px solid rgba(0, 212, 255, 0.3); border-radius: 8px; background: rgba(0, 212, 255, 0.02);"></canvas>
                            </div>
                            <div class="viz-controls">
                                <button onclick="drawVisualization('${module.id}')" class="btn-viz">๐Ÿ”„ Refresh Visualization</button>
                                <button onclick="toggleVizAnimation('${module.id}')" class="btn-viz">โ–ถ๏ธ Animate</button>
                                <button onclick="downloadViz('${module.id}')" class="btn-viz">โฌ‡๏ธ Save Image</button>
                            </div>
                        </div>
                    </div>

                    <div id="${module.id}-math" class="tab">
                        <div class="section">
                            <h2>๐Ÿ“ Mathematical Foundation</h2>
                            ${content.math || `
                                <p>Rigorous mathematical treatment of ${module.title.toLowerCase()}.</p>
                                <div class="formula">
                                    Mathematical formulas and derivations go here
                                </div>
                            `}
                        </div>
                    </div>

                    <div id="${module.id}-applications" class="tab">
                        <div class="section">
                            <h2>๐ŸŒ Real-World Applications</h2>
                            ${content.applications || `
                                <p>How ${module.title.toLowerCase()} is used in practice across different industries.</p>
                                <div class="info-box">
                                    <div class="box-title">Use Cases</div>
                                    <div class="box-content">
                                        Common applications and practical examples
                                    </div>
                                </div>
                            `}
                        </div>
                    </div>

                    <div id="${module.id}-code" class="tab">
                        <div class="section">
                            <h2>๐Ÿ Python Implementation</h2>
                            ${content.code || `
                                <p>Production-ready Python code for ${module.title.toLowerCase()} using PyTorch and TensorFlow.</p>
                                <div class="callout tip">
                                    <div class="callout-title">๐Ÿ’ก Coming Soon</div>
                                    Python code examples for this module are being prepared.
                                </div>
                            `}
                        </div>
                    </div>

                    <div id="${module.id}-summary" class="tab">
                        <div class="section">
                            <h2>โœ… Summary</h2>
                            <div class="info-box">
                                <div class="box-title">Key Takeaways</div>
                                <div class="box-content">
                                    โœ“ Essential concepts covered<br>
                                    โœ“ Mathematical foundations understood<br>
                                    โœ“ Real-world applications identified<br>
                                    โœ“ Ready for implementation
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            `;
        }

        function initDashboard() {
            const grid = document.getElementById("modulesGrid");
            const container = document.getElementById("modulesContainer");

            modules.forEach((module, index) => {
                const card = document.createElement("div");
                // Add staggered animation class
                const staggerClass = `stagger stagger-${(index % 8) + 1}`;
                card.className = `card hover-glow ${staggerClass}`;
                card.style.borderColor = module.color;
                card.onclick = () => switchTo(module.id + "-module");
                card.innerHTML = `
                    <div class="card-icon">${module.icon}</div>
                    <h3>${module.title}</h3>
                    <p>${module.description}</p>
                    <span class="category-label">${module.category}</span>
                `;
                grid.appendChild(card);

                const moduleHTML = createModuleHTML(module);
                container.innerHTML += moduleHTML;
            });
        }

        function switchTo(target) {
            document.querySelectorAll('.dashboard, .module').forEach(el => {
                el.classList.remove('active');
            });
            const elem = document.getElementById(target);
            if (elem) elem.classList.add('active');
        }

        function switchTab(e, tabId) {
            const module = e.target.closest('.module');
            if (!module) return;

            module.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
            module.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));

            const tab = document.getElementById(tabId);
            if (tab) tab.classList.add('active');
            e.target.classList.add('active');

            // Re-render MathJax in the newly visible tab
            if (window.MathJax && window.MathJax.typesetPromise) {
                window.MathJax.typesetPromise([tab]).catch(function (err) { console.log('MathJax typeset:', err); });
            }

            // Trigger visualization when tabs are clicked
            setTimeout(() => {
                const moduleId = tabId.split('-')[0];
                if (tabId.includes('-concepts')) {
                    drawConceptsVisualization(moduleId);
                } else if (tabId.includes('-visualization')) {
                    drawConceptsVisualization(moduleId);
                } else if (tabId.includes('-math')) {
                    drawMathVisualization(moduleId);
                } else if (tabId.includes('-applications')) {
                    drawApplicationVisualization(moduleId);
                }
            }, 150);
        }

        // Visualization Functions - Concepts Tab
        function drawConceptsVisualization(moduleId) {
            const canvas = document.getElementById(moduleId + '-canvas');
            if (!canvas) return;

            const ctx = canvas.getContext('2d');
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.fillStyle = '#0f1419';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            const vizMap = {
                'nn-basics': drawNeuronAnimation,
                'perceptron': drawDecisionBoundary,
                'mlp': drawNetworkGraph,
                'activation': drawActivationFunctions,
                'weight-init': drawWeightDistribution,
                'loss': drawLossLandscape,
                'optimizers': drawConvergencePaths,
                'backprop': drawGradientFlow,
                'regularization': drawOverfitComparison,
                'batch-norm': drawBatchNormalization,
                'cv-intro': drawImageMatrix,
                'conv-layer': drawConvolutionAnimation,
                'pooling': drawPoolingDemo,
                'cnn-basics': drawCNNArchitecture,
                'viz-filters': drawLearnedFilters,
                'lenet': drawLeNetArchitecture,
                'alexnet': drawAlexNetArchitecture,
                'vgg': drawVGGArchitecture,
                'resnet': drawResNetArchitecture,
                'inception': drawInceptionModule,
                'mobilenet': drawMobileNetArchitecture,
                'transfer-learning': drawTransferLearning,
                'localization': drawBoundingBoxes,
                'rcnn': drawRCNNPipeline,
                'yolo': drawYOLOGrid,
                'ssd': drawSSDDetector,
                'semantic-seg': drawSemanticSegmentation,
                'instance-seg': drawInstanceSegmentation,
                'face-recog': drawFaceEmbeddings,
                'autoencoders': drawAutoencoderArchitecture,
                'gans': drawGANsGame,
                'diffusion': drawDiffusionProcess,
                'rnn': drawRNNUnrolled,
                'transformers': drawAttentionMatrix,
                'bert': drawBERTProcess,
                'gpt': drawGPTGeneration,
                'vit': drawVisionTransformer,
                'gnn': drawGraphNetwork,
                'seq2seq': drawSeq2SeqAttention,
                'research-papers': drawDefaultVisualization,
                'vector-db': drawVectorSpace,
                'rag': drawRAGPipeline,
                'advanced-llm': drawLoRADiagram
            };

            if (vizMap[moduleId]) {
                vizMap[moduleId](ctx, canvas);
            } else {
                drawDefaultVisualization(ctx, canvas);
            }
        }

        // Default Visualization
        function drawDefaultVisualization(ctx, canvas) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            ctx.fillStyle = 'rgba(0, 212, 255, 0.2)';
            ctx.fillRect(centerX - 120, centerY - 60, 240, 120);
            ctx.strokeStyle = '#00d4ff';
            ctx.lineWidth = 2;
            ctx.strokeRect(centerX - 120, centerY - 60, 240, 120);

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 18px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ“Š Interactive Visualization', centerX, centerY - 20);
            ctx.font = '13px Arial';
            ctx.fillText('Custom visualization for this topic', centerX, centerY + 20);
            ctx.font = '11px Arial';
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Click Refresh to render', centerX, centerY + 45);
        }

        // Default Math Visualization
        function drawDefaultMathVisualization(ctx, canvas) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            ctx.fillStyle = 'rgba(255, 107, 53, 0.2)';
            ctx.fillRect(centerX - 120, centerY - 60, 240, 120);
            ctx.strokeStyle = '#ff6b35';
            ctx.lineWidth = 2;
            ctx.strokeRect(centerX - 120, centerY - 60, 240, 120);

            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 18px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ“ Mathematical Formulas', centerX, centerY - 20);
            ctx.font = '13px Arial';
            ctx.fillText('Visual equation derivations', centerX, centerY + 20);
            ctx.font = '11px Arial';
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Click Visualize to render', centerX, centerY + 45);
        }

        // Default Application Visualization
        function drawDefaultApplicationVisualization(ctx, canvas) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            ctx.fillStyle = 'rgba(0, 255, 136, 0.2)';
            ctx.fillRect(centerX - 120, centerY - 60, 240, 120);
            ctx.strokeStyle = '#00ff88';
            ctx.lineWidth = 2;
            ctx.strokeRect(centerX - 120, centerY - 60, 240, 120);

            ctx.fillStyle = '#00ff88';
            ctx.font = 'bold 18px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐ŸŒ Real-World Applications', centerX, centerY - 20);
            ctx.font = '13px Arial';
            ctx.fillText('Practical use cases and examples', centerX, centerY + 20);
            ctx.font = '11px Arial';
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Click Show Applications to render', centerX, centerY + 45);
        }

        // Activation Functions Visualization
        function drawActivationFunctions(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;
            const centerX = width / 2;
            const centerY = height / 2;
            const scale = 40;

            // Draw grid
            ctx.strokeStyle = 'rgba(0, 212, 255, 0.1)';
            ctx.lineWidth = 1;
            for (let i = -5; i <= 5; i += 1) {
                const x = centerX + i * scale;
                ctx.beginPath();
                ctx.moveTo(x, centerY - 5 * scale);
                ctx.lineTo(x, centerY + 5 * scale);
                ctx.stroke();
            }

            // Draw axes
            ctx.strokeStyle = '#00d4ff';
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(centerX - 6 * scale, centerY);
            ctx.lineTo(centerX + 6 * scale, centerY);
            ctx.stroke();
            ctx.beginPath();
            ctx.moveTo(centerX, centerY - 6 * scale);
            ctx.lineTo(centerX, centerY + 6 * scale);
            ctx.stroke();

            // Draw activation functions
            const functions = [
                { name: 'ReLU', color: '#ff6b35', fn: x => Math.max(0, x) },
                { name: 'Sigmoid', color: '#00ff88', fn: x => 1 / (1 + Math.exp(-x)) },
                { name: 'Tanh', color: '#ffa500', fn: x => Math.tanh(x) }
            ];

            functions.forEach(func => {
                ctx.strokeStyle = func.color;
                ctx.lineWidth = 2;
                ctx.beginPath();
                for (let x = -5; x <= 5; x += 0.1) {
                    const y = func.fn(x);
                    const canvasX = centerX + x * scale;
                    const canvasY = centerY - y * scale;
                    if (x === -5) ctx.moveTo(canvasX, canvasY);
                    else ctx.lineTo(canvasX, canvasY);
                }
                ctx.stroke();
            });

            // Legend
            ctx.font = 'bold 12px Arial';
            functions.forEach((func, i) => {
                ctx.fillStyle = func.color;
                ctx.fillRect(10, 10 + i * 20, 10, 10);
                ctx.fillStyle = '#e4e6eb';
                ctx.fillText(func.name, 25, 19 + i * 20);
            });
        }

        // Neural Network Graph
        function drawNetworkGraph(ctx, canvas) {
            const layers = [2, 3, 3, 1];
            const width = canvas.width;
            const height = canvas.height;
            const layerWidth = width / (layers.length + 1);

            ctx.fillStyle = 'rgba(0, 212, 255, 0.05)';
            ctx.fillRect(0, 0, width, height);

            // Draw neurons and connections
            const neuronPositions = [];

            layers.forEach((numNeurons, layerIdx) => {
                const x = (layerIdx + 1) * layerWidth;
                const positions = [];

                for (let i = 0; i < numNeurons; i++) {
                    const y = height / (numNeurons + 1) * (i + 1);
                    positions.push({ x, y });

                    // Draw connections to next layer
                    if (layerIdx < layers.length - 1) {
                        const nextLayerPositions = [];
                        const nextX = (layerIdx + 2) * layerWidth;
                        for (let j = 0; j < layers[layerIdx + 1]; j++) {
                            const nextY = height / (layers[layerIdx + 1] + 1) * (j + 1);
                            nextLayerPositions.push({ x: nextX, y: nextY });
                        }

                        nextLayerPositions.forEach(next => {
                            ctx.strokeStyle = 'rgba(0, 212, 255, 0.2)';
                            ctx.lineWidth = 1;
                            ctx.beginPath();
                            ctx.moveTo(x, y);
                            ctx.lineTo(next.x, next.y);
                            ctx.stroke();
                        });
                    }
                }

                // Draw neurons
                positions.forEach(pos => {
                    ctx.fillStyle = '#00d4ff';
                    ctx.beginPath();
                    ctx.arc(pos.x, pos.y, 8, 0, Math.PI * 2);
                    ctx.fill();
                });

                neuronPositions.push(positions);
            });

            // Labels
            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 12px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Input', layerWidth, height - 10);
            ctx.fillText('Hidden 1', layerWidth * 2, height - 10);
            ctx.fillText('Hidden 2', layerWidth * 3, height - 10);
            ctx.fillText('Output', layerWidth * 4, height - 10);
        }

        // Convolution Animation
        function drawConvolutionAnimation(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;

            // Draw input image
            ctx.fillStyle = 'rgba(0, 212, 255, 0.1)';
            ctx.fillRect(20, 20, 150, 150);
            ctx.strokeStyle = '#00d4ff';
            ctx.lineWidth = 2;
            ctx.strokeRect(20, 20, 150, 150);

            // Draw filter
            ctx.fillStyle = 'rgba(255, 107, 53, 0.1)';
            const filterPos = 60 + Math.sin(Date.now() / 1000) * 40;
            ctx.fillRect(filterPos, 60, 60, 60);
            ctx.strokeStyle = '#ff6b35';
            ctx.lineWidth = 3;
            ctx.strokeRect(filterPos, 60, 60, 60);

            // Draw output
            ctx.fillStyle = 'rgba(0, 255, 136, 0.1)';
            ctx.fillRect(width - 170, 20, 150, 150);
            ctx.strokeStyle = '#00ff88';
            ctx.lineWidth = 2;
            ctx.strokeRect(width - 170, 20, 150, 150);

            // Draw feature map
            for (let i = 0; i < 5; i++) {
                for (let j = 0; j < 5; j++) {
                    const intensity = Math.random() * 100;
                    ctx.fillStyle = `rgba(0, 212, 255, ${intensity / 100})`;
                    ctx.fillRect(width - 160 + i * 25, 30 + j * 25, 20, 20);
                }
            }

            // Labels
            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 12px Arial';
            ctx.textAlign = 'left';
            ctx.fillText('Input Image', 20, 190);
            ctx.fillText('Filter', filterPos, 140);
            ctx.fillText('Feature Map', width - 170, 190);
        }

        // Loss Landscape
        function drawLossLandscape(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;

            for (let x = 0; x < width; x += 20) {
                for (let y = 0; y < height; y += 20) {
                    const nx = (x - width / 2) / (width / 4);
                    const ny = (y - height / 2) / (height / 4);
                    const loss = nx * nx + ny * ny;
                    const intensity = Math.min(255, loss * 50);
                    ctx.fillStyle = `rgb(${intensity}, ${100}, ${255 - intensity})`;
                    ctx.fillRect(x, y, 20, 20);
                }
            }

            // Draw descent path
            ctx.strokeStyle = '#00ff88';
            ctx.lineWidth = 2;
            ctx.beginPath();
            const startX = width / 2 + 80;
            const startY = height / 2 + 80;
            ctx.moveTo(startX, startY);

            for (let i = 0; i < 20; i++) {
                const angle = Math.atan2(startY - height / 2, startX - width / 2);
                const newX = startX - Math.cos(angle) * 15;
                const newY = startY - Math.sin(angle) * 15;
                ctx.lineTo(newX, newY);
            }
            ctx.stroke();

            // Minimum point
            ctx.fillStyle = '#00ff88';
            ctx.beginPath();
            ctx.arc(width / 2, height / 2, 8, 0, Math.PI * 2);
            ctx.fill();
        }

        // YOLO Grid
        function drawYOLOGrid(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;
            const gridSize = 7;
            const cellWidth = width / gridSize;
            const cellHeight = height / gridSize;

            // Draw grid
            ctx.strokeStyle = 'rgba(0, 212, 255, 0.3)';
            ctx.lineWidth = 1;
            for (let i = 0; i <= gridSize; i++) {
                ctx.beginPath();
                ctx.moveTo(i * cellWidth, 0);
                ctx.lineTo(i * cellWidth, height);
                ctx.stroke();

                ctx.beginPath();
                ctx.moveTo(0, i * cellHeight);
                ctx.lineTo(width, i * cellHeight);
                ctx.stroke();
            }

            // Draw detected objects
            const detections = [
                { x: 2, y: 2, w: 2, h: 2, conf: 0.95 },
                { x: 4, y: 5, w: 1.5, h: 1.5, conf: 0.87 }
            ];

            detections.forEach(det => {
                ctx.fillStyle = `rgba(255, 107, 53, ${det.conf * 0.5})`;
                ctx.fillRect(det.x * cellWidth, det.y * cellHeight, det.w * cellWidth, det.h * cellHeight);
                ctx.strokeStyle = '#ff6b35';
                ctx.lineWidth = 2;
                ctx.strokeRect(det.x * cellWidth, det.y * cellHeight, det.w * cellWidth, det.h * cellHeight);

                ctx.fillStyle = '#ff6b35';
                ctx.font = 'bold 12px Arial';
                ctx.fillText((det.conf * 100).toFixed(0) + '%', det.x * cellWidth + 5, det.y * cellHeight + 15);
            });
        }

        // Attention Matrix
        function drawAttentionMatrix(ctx, canvas) {
            const size = 8;
            const cellSize = Math.min(canvas.width, canvas.height) / size;

            for (let i = 0; i < size; i++) {
                for (let j = 0; j < size; j++) {
                    const distance = Math.abs(i - j);
                    const attention = Math.exp(-distance / 2);
                    const intensity = Math.floor(attention * 255);
                    ctx.fillStyle = `rgb(${intensity}, 100, ${200 - intensity})`;
                    ctx.fillRect(i * cellSize, j * cellSize, cellSize, cellSize);
                }
            }

            // Add labels
            ctx.fillStyle = '#e4e6eb';
            ctx.font = '10px Arial';
            ctx.textAlign = 'center';
            for (let i = 0; i < size; i++) {
                ctx.fillText('w' + i, i * cellSize + cellSize / 2, canvas.height - 5);
            }
        }

        // Math Visualization
        function drawMathVisualization(moduleId) {
            const canvas = document.getElementById(moduleId + '-math-canvas');
            if (!canvas) return;

            const ctx = canvas.getContext('2d');
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.fillStyle = '#0f1419';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            const mathVizMap = {
                'nn-basics': () => drawNNMath(ctx, canvas),
                'activation': () => drawActivationDerivatives(ctx, canvas),
                'loss': () => drawLossComparison(ctx, canvas),
                'optimizers': () => drawOptimizerSteps(ctx, canvas),
                'backprop': () => drawChainRule(ctx, canvas),
                'conv-layer': () => drawConvolutionMath(ctx, canvas),
                'pooling': () => drawPoolingMath(ctx, canvas),
                'regularization': () => drawRegularizationMath(ctx, canvas),
                'transformers': () => drawAttentionMath(ctx, canvas),
                'rnn': () => drawRNNMath(ctx, canvas),
                'gnn': () => drawGNNMath(ctx, canvas)
            };

            if (mathVizMap[moduleId]) {
                mathVizMap[moduleId]();
            } else {
                drawDefaultMathVisualization(ctx, canvas);
            }
        }

        // Application Visualization
        function drawApplicationVisualization(moduleId) {
            const canvas = document.getElementById(moduleId + '-app-canvas');
            if (!canvas) return;

            const ctx = canvas.getContext('2d');
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.fillStyle = '#0f1419';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            const appVizMap = {
                'nn-basics': () => drawNNApplications(ctx, canvas),
                'cnn-basics': () => drawCNNApplications(ctx, canvas),
                'conv-layer': () => drawConvolutionApplications(ctx, canvas),
                'yolo': () => drawYOLOApplications(ctx, canvas),
                'semantic-seg': () => drawSegmentationApplications(ctx, canvas),
                'instance-seg': () => drawInstanceSegmentationApps(ctx, canvas),
                'face-recog': () => drawFaceRecognitionApps(ctx, canvas),
                'transformers': () => drawTransformerApps(ctx, canvas),
                'bert': () => drawBERTApplications(ctx, canvas),
                'gpt': () => drawGPTApplications(ctx, canvas),
                'gans': () => drawGANApplications(ctx, canvas),
                'diffusion': () => drawDiffusionApplications(ctx, canvas),
                'gnn': () => drawGNNApplications(ctx, canvas)
            };

            if (appVizMap[moduleId]) {
                appVizMap[moduleId]();
            } else {
                drawDefaultApplicationVisualization(ctx, canvas);
            }
        }

        // Math visualization helper functions
        function drawNNMath(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 18px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Forward Pass: y = ฯƒ(Wx + b)', canvas.width / 2, 50);
            ctx.font = '14px Arial';
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Linear combination + Non-linearity', canvas.width / 2, 100);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('W: weights, b: bias, ฯƒ: activation', canvas.width / 2, 150);
        }

        function drawActivationDerivatives(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;
            const centerX = width / 2;
            const centerY = height / 2;
            const scale = 40;

            ctx.strokeStyle = 'rgba(0, 212, 255, 0.2)';
            ctx.lineWidth = 1;
            for (let i = -5; i <= 5; i += 1) {
                ctx.beginPath();
                ctx.moveTo(centerX + i * scale, centerY - 5 * scale);
                ctx.lineTo(centerX + i * scale, centerY + 5 * scale);
                ctx.stroke();
            }

            ctx.strokeStyle = '#00ff88';
            ctx.lineWidth = 3;
            ctx.beginPath();
            for (let x = -5; x <= 5; x += 0.1) {
                const y = 1 / (1 + Math.exp(-x)) * (1 - 1 / (1 + Math.exp(-x)));
                const canvasX = centerX + x * scale;
                const canvasY = centerY - y * scale * 10;
                if (x === -5) ctx.moveTo(canvasX, canvasY);
                else ctx.lineTo(canvasX, canvasY);
            }
            ctx.stroke();

            ctx.fillStyle = '#00ff88';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText("Sigmoid Derivative: ฯƒ'(x) = ฯƒ(x)(1-ฯƒ(x))", canvas.width / 2, 30);
        }

        function drawLossComparison(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;

            // MSE
            ctx.fillStyle = 'rgba(0, 212, 255, 0.2)';
            ctx.fillRect(20, 60, width / 2 - 30, height - 100);
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.fillText('MSE Loss', width / 4, 45);
            ctx.font = '12px Arial';
            ctx.fillText('L = (1/n)ฮฃ(y-ลท)ยฒ', width / 4, 90);
            ctx.fillText('Regression', width / 4, 115);

            // Cross-Entropy
            ctx.fillStyle = 'rgba(255, 107, 53, 0.2)';
            ctx.fillRect(width / 2 + 10, 60, width / 2 - 30, height - 100);
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 14px Arial';
            ctx.fillText('Cross-Entropy Loss', width * 3 / 4, 45);
            ctx.font = '12px Arial';
            ctx.fillText('L = -ฮฃ(yยทlog(ลท))', width * 3 / 4, 90);
            ctx.fillText('Classification', width * 3 / 4, 115);
        }

        function drawOptimizerSteps(ctx, canvas) {
            const width = canvas.width;
            const height = canvas.height;
            const centerY = height / 2;

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('SGD', width / 4, 50);
            ctx.font = '12px Arial';
            ctx.fillText('w = w - ฮฑยทโˆ‡L', width / 4, 100);

            ctx.fillStyle = '#00ff88';
            ctx.font = 'bold 16px Arial';
            ctx.fillText('Momentum', width / 2, 50);
            ctx.font = '12px Arial';
            ctx.fillText('v = ฮฒยทv + (1-ฮฒ)ยทโˆ‡L', width / 2, 100);

            ctx.fillStyle = '#ffa500';
            ctx.font = 'bold 16px Arial';
            ctx.fillText('Adam', width * 3 / 4, 50);
            ctx.font = '12px Arial';
            ctx.fillText('Adaptive learning rate', width * 3 / 4, 100);
        }

        function drawChainRule(ctx, canvas) {
            const width = canvas.width;
            ctx.fillStyle = '#00ff88';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Backpropagation Chain Rule', width / 2, 50);
            ctx.font = '12px Arial';
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('dL/dW = dL/dลท ยท dลท/da ยท da/dz ยท dz/dW', width / 2, 100);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Compute gradient by multiplying partial derivatives', width / 2, 150);
        }

        function drawConvolutionMath(ctx, canvas) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Convolution Operation', canvas.width / 2, 50);
            ctx.font = '12px Arial';
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('y[i,j] = ฮฃ ฮฃ w[m,n] * x[i+m,j+n] + b', canvas.width / 2, 100);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Sliding window element-wise multiplication and summation', canvas.width / 2, 150);
        }

        function drawPoolingMath(ctx, canvas) {
            const width = canvas.width;
            ctx.fillStyle = '#00ff88';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Max Pooling', width / 3, 50);
            ctx.font = '12px Arial';
            ctx.fillText('y = max(neighborhood)', width / 3, 100);

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.fillText('Average Pooling', width * 2 / 3, 50);
            ctx.font = '12px Arial';
            ctx.fillText('y = avg(neighborhood)', width * 2 / 3, 100);

            ctx.fillStyle = '#ffa500';
            ctx.font = '11px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Reduces spatial dimensions', width / 2, 150);
        }

        function drawRegularizationMath(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('L1 Regularization: L = Loss + ฮปฮฃ|w|', canvas.width / 2, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('L2 Regularization: L = Loss + ฮปฮฃwยฒ', canvas.width / 2, 110);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Prevents overfitting by penalizing large weights', canvas.width / 2, 160);
        }

        function drawAttentionMath(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Attention Mechanism', canvas.width / 2, 50);
            ctx.font = '12px Arial';
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Attention(Q,K,V) = softmax(QK^T/โˆšd_k) ยท V', canvas.width / 2, 100);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Query-Key matching determines how much to focus on each value', canvas.width / 2, 150);
        }

        function drawRNNMath(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('RNN Hidden State Update', canvas.width / 2, 50);
            ctx.font = '12px Arial';
            ctx.fillStyle = '#00ff88';
            ctx.fillText('h_t = ฯƒ(W_hยทh_(t-1) + W_xยทx_t + b)', canvas.width / 2, 100);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Processes sequences step-by-step with recurrent connections', canvas.width / 2, 150);
        }

        // Application visualization helper functions
        function drawNNApplications(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ“ฑ Stock Price Prediction', canvas.width / 4, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('๐Ÿฅ Medical Diagnosis', canvas.width / 2, 60);
            ctx.fillStyle = '#ffa500';
            ctx.fillText('๐ŸŽฎ Game AI', canvas.width * 3 / 4, 60);

            ctx.fillStyle = '#ff6b35';
            ctx.font = '12px Arial';
            ctx.fillText('Fraud Detection', canvas.width / 4, 120);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('Recommendation Systems', canvas.width / 2, 120);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Credit Scoring', canvas.width * 3 / 4, 120);
        }

        function drawCNNApplications(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Image Classification', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Object Detection', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Deep Learning Backbone', canvas.width / 2, 150);
        }

        function drawConvolutionApplications(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ“ท Image Feature Extraction', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('๐Ÿ” Edge Detection', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Foundation of Computer Vision', canvas.width / 2, 150);
        }

        function drawYOLOApplications(ctx, canvas) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿš— Autonomous Driving', canvas.width / 3, 60);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐Ÿ“น Real-time Video Detection', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#00ff88';
            ctx.font = '12px Arial';
            ctx.fillText('Ultra-fast inference for live applications', canvas.width / 2, 150);
        }

        function drawSegmentationApplications(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿฅ Medical Imaging', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('๐Ÿš— Autonomous Vehicles', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Pixel-level understanding of scenes', canvas.width / 2, 150);
        }

        function drawInstanceSegmentationApps(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ‘ฅ Person Detection & Tracking', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('๐ŸŽ Object Instance Counting', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Separates overlapping objects', canvas.width / 2, 150);
        }

        function drawFaceRecognitionApps(ctx, canvas) {
            ctx.fillStyle = '#ffa500';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ“ฑ Phone Unlock', canvas.width / 3, 60);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐Ÿ”’ Security Systems', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#00ff88';
            ctx.font = '12px Arial';
            ctx.fillText('Identity verification and access control', canvas.width / 2, 150);
        }

        function drawTransformerApps(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ’ฌ ChatGPT / LLMs', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('๐ŸŒ Machine Translation', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Foundation of modern NLP and beyond', canvas.width / 2, 150);
        }

        function drawBERTApplications(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ” Semantic Search', canvas.width / 3, 60);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('โ“ Question Answering', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#ffa500';
            ctx.font = '12px Arial';
            ctx.fillText('Deep language understanding', canvas.width / 2, 150);
        }

        function drawGPTApplications(ctx, canvas) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('โœ๏ธ Text Generation', canvas.width / 3, 60);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐Ÿ’ก Idea Assistance', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#00ff88';
            ctx.font = '12px Arial';
            ctx.fillText('Powerful autoregressive language models', canvas.width / 2, 150);
        }

        function drawGANApplications(ctx, canvas) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐ŸŽจ Image Generation', canvas.width / 3, 60);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐ŸŽญ Style Transfer', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#00ff88';
            ctx.font = '12px Arial';
            ctx.fillText('Creative content generation and enhancement', canvas.width / 2, 150);
        }

        function drawDiffusionApplications(ctx, canvas) {
            ctx.fillStyle = '#ffa500';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ–ผ๏ธ Image Synthesis', canvas.width / 3, 60);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐ŸŽฌ Stable Diffusion', canvas.width * 2 / 3, 60);

            ctx.fillStyle = '#00ff88';
            ctx.font = '12px Arial';
            ctx.fillText('State-of-the-art generative AI', canvas.width / 2, 150);
        }

        // Missing visualization stub functions
        function drawNeuronAnimation(ctx, canvas) {
            drawNetworkGraph(ctx, canvas);
        }

        function drawDecisionBoundary(ctx, canvas) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            // Draw decision boundary line
            ctx.strokeStyle = '#ff6b35';
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(0, centerY);
            ctx.lineTo(canvas.width, centerY);
            ctx.stroke();

            // Draw sample points
            for (let i = 0; i < 20; i++) {
                const x = Math.random() * canvas.width;
                const y = Math.random() * canvas.height;
                ctx.fillStyle = y < centerY ? '#00d4ff' : '#00ff88';
                ctx.beginPath();
                ctx.arc(x, y, 5, 0, Math.PI * 2);
                ctx.fill();
            }
        }

        function drawWeightDistribution(ctx, canvas) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            // Draw Gaussian distribution
            ctx.strokeStyle = '#00d4ff';
            ctx.lineWidth = 2;
            ctx.beginPath();
            for (let x = -100; x <= 100; x += 2) {
                const y = Math.exp(-(x * x) / 500) * 80;
                const canvasX = centerX + x;
                const canvasY = centerY - y;
                if (x === -100) ctx.moveTo(canvasX, canvasY);
                else ctx.lineTo(canvasX, canvasY);
            }
            ctx.stroke();

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Weight Distribution (Xavier/He Init)', centerX, 50);
        }

        function drawConvergencePaths(ctx, canvas) {
            drawLossLandscape(ctx, canvas);
        }

        function drawGradientFlow(ctx, canvas) {
            drawChainRule(ctx, canvas);
        }

        function drawOverfitComparison(ctx, canvas) {
            const width = canvas.width;
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Without Regularization', width / 4, 40);
            ctx.fillStyle = '#ff6b35';
            ctx.fillText('With Regularization', width * 3 / 4, 40);

            // Draw wavy overfit line
            ctx.strokeStyle = '#00d4ff';
            ctx.lineWidth = 2;
            ctx.beginPath();
            for (let x = 0; x < width / 2 - 20; x += 5) {
                const y = 100 + Math.sin(x / 10) * 30 + Math.random() * 20;
                if (x === 0) ctx.moveTo(x + 20, y);
                else ctx.lineTo(x + 20, y);
            }
            ctx.stroke();

            // Draw smooth regularized line
            ctx.strokeStyle = '#ff6b35';
            ctx.beginPath();
            for (let x = 0; x < width / 2 - 20; x += 5) {
                const y = 100 + Math.sin(x / 20) * 15;
                if (x === 0) ctx.moveTo(x + width / 2 + 20, y);
                else ctx.lineTo(x + width / 2 + 20, y);
            }
            ctx.stroke();
        }

        function drawBatchNormalization(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Batch Normalization: ฮผ=0, ฯƒยฒ=1', canvas.width / 2, 50);

            // Draw before/after distributions
            ctx.fillStyle = '#ffa500';
            ctx.fillText('Input Distribution', canvas.width / 4, 100);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Normalized Distribution', canvas.width * 3 / 4, 100);
        }

        function drawImageMatrix(ctx, canvas) {
            const cellSize = 20;
            for (let i = 0; i < 10; i++) {
                for (let j = 0; j < 10; j++) {
                    const intensity = Math.random();
                    ctx.fillStyle = `rgba(0, 212, 255, ${intensity})`;
                    ctx.fillRect(i * cellSize + 100, j * cellSize + 100, cellSize, cellSize);
                }
            }
            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Image as Matrix (Pixel Values)', canvas.width / 2, 50);
        }

        function drawPoolingDemo(ctx, canvas) {
            const cellSize = 30;
            const input = [[20, 30, 0, 5], [8, 12, 2, 0], [34, 70, 37, 4], [112, 100, 25, 12]];

            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Max Pooling Demo (2x2)', canvas.width / 2, 30);

            // Draw input matrix
            for (let i = 0; i < 4; i++) {
                for (let j = 0; j < 4; j++) {
                    ctx.strokeStyle = '#00d4ff';
                    ctx.strokeRect(50 + j * cellSize, 50 + i * cellSize, cellSize, cellSize);
                    ctx.fillStyle = '#e4e6eb';
                    ctx.font = '10px Arial';
                    ctx.fillText(input[i][j], 50 + j * cellSize + cellSize / 2, 50 + i * cellSize + cellSize / 2 + 4);
                }
            }

            // Draw output (max pooled)
            const pooled = [[20, 30], [112, 37]];
            for (let i = 0; i < 2; i++) {
                for (let j = 0; j < 2; j++) {
                    ctx.strokeStyle = '#00ff88';
                    ctx.strokeRect(250 + j * cellSize * 1.5, 70 + i * cellSize * 1.5, cellSize * 1.5, cellSize * 1.5);
                    ctx.fillStyle = '#00ff88';
                    ctx.font = 'bold 12px Arial';
                    ctx.fillText(pooled[i][j], 250 + j * cellSize * 1.5 + cellSize * 0.75, 70 + i * cellSize * 1.5 + cellSize * 0.75 + 5);
                }
            }
        }

        function drawCNNArchitecture(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 12px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Input', 60, 200);
            ctx.fillText('Conv', 160, 200);
            ctx.fillText('Pool', 260, 200);
            ctx.fillText('Conv', 360, 200);
            ctx.fillText('Pool', 460, 200);
            ctx.fillText('FC', 560, 200);
            ctx.fillText('Output', 660, 200);

            // Draw blocks
            const blocks = [60, 160, 260, 360, 460, 560, 660];
            blocks.forEach((x, i) => {
                const height = i === 0 ? 100 : (i < blocks.length - 2 ? 80 - i * 10 : 60);
                ctx.strokeStyle = '#00d4ff';
                ctx.strokeRect(x - 30, 100, 60, height);
            });
        }

        function drawLearnedFilters(ctx, canvas) {
            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('CNN Learned Filters', canvas.width / 2, 30);

            const labels = ['Edges', 'Textures', 'Patterns', 'Objects'];
            labels.forEach((label, i) => {
                const x = (i + 1) * canvas.width / 5;
                ctx.fillStyle = '#ff6b35';
                ctx.font = 'bold 12px Arial';
                ctx.fillText(label, x, 80);

                // Draw filter representation
                for (let j = 0; j < 3; j++) {
                    for (let k = 0; k < 3; k++) {
                        const intensity = Math.random();
                        ctx.fillStyle = `rgba(0, 212, 255, ${intensity})`;
                        ctx.fillRect(x - 20 + k * 12, 100 + j * 12, 10, 10);
                    }
                }
            });
        }

        function drawLeNetArchitecture(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawAlexNetArchitecture(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawVGGArchitecture(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawResNetArchitecture(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawInceptionModule(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawMobileNetArchitecture(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }
        function drawTransferLearning(ctx, canvas) { drawCNNArchitecture(ctx, canvas); }

        function drawBoundingBoxes(ctx, canvas) {
            // Draw sample image
            ctx.fillStyle = 'rgba(0, 212, 255, 0.1)';
            ctx.fillRect(50, 50, 300, 300);

            // Draw bounding boxes
            ctx.strokeStyle = '#ff6b35';
            ctx.lineWidth = 3;
            ctx.strokeRect(100, 100, 150, 150);
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 12px Arial';
            ctx.fillText('Dog 95%', 105, 95);

            ctx.strokeStyle = '#00ff88';
            ctx.strokeRect(180, 200, 100, 80);
            ctx.fillStyle = '#00ff88';
            ctx.fillText('Cat 87%', 185, 195);
        }

        function drawRCNNPipeline(ctx, canvas) { drawBoundingBoxes(ctx, canvas); }
        function drawSSDDetector(ctx, canvas) { drawBoundingBoxes(ctx, canvas); }

        function drawSemanticSegmentation(ctx, canvas) {
            const cellSize = 15;
            const colors = ['rgba(0, 212, 255, 0.5)', 'rgba(255, 107, 53, 0.5)', 'rgba(0, 255, 136, 0.5)'];

            for (let i = 0; i < 20; i++) {
                for (let j = 0; j < 20; j++) {
                    ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
                    ctx.fillRect(i * cellSize + 100, j * cellSize + 50, cellSize, cellSize);
                }
            }

            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Pixel-wise Classification', canvas.width / 2, 30);
        }

        function drawInstanceSegmentation(ctx, canvas) { drawSemanticSegmentation(ctx, canvas); }

        function drawFaceEmbeddings(ctx, canvas) {
            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Face Embedding Space', canvas.width / 2, 30);

            // Draw embedding vectors
            const faces = 5;
            for (let i = 0; i < faces; i++) {
                const x = 100 + Math.random() * (canvas.width - 200);
                const y = 100 + Math.random() * 200;
                ctx.fillStyle = '#00d4ff';
                ctx.beginPath();
                ctx.arc(x, y, 10, 0, Math.PI * 2);
                ctx.fill();
            }
        }

        function drawAutoencoderArchitecture(ctx, canvas) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 12px Arial';
            ctx.textAlign = 'center';

            const stages = ['Input', 'Encoder', 'Latent', 'Decoder', 'Output'];
            stages.forEach((label, i) => {
                const x = (i + 1) * canvas.width / 6;
                ctx.fillText(label, x, 50);
                const height = i === 2 ? 40 : (i === 0 || i === 4 ? 100 : 70);
                ctx.strokeStyle = '#00d4ff';
                ctx.strokeRect(x - 30, 100, 60, height);
            });
        }

        function drawGANsGame(ctx, canvas) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Generator', canvas.width / 3, 50);
            ctx.fillStyle = '#00d4ff';
            ctx.fillText('Discriminator', canvas.width * 2 / 3, 50);

            // DrawGenerator
            ctx.strokeStyle = '#ff6b35';
            ctx.strokeRect(canvas.width / 3 - 50, 100, 100, 100);

            // Draw Discriminator
            ctx.strokeStyle = '#00d4ff';
            ctx.strokeRect(canvas.width * 2 / 3 - 50, 100, 100, 100);

            // Draw arrow
            ctx.strokeStyle = '#00ff88';
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(canvas.width / 3 + 50, 150);
            ctx.lineTo(canvas.width * 2 / 3 - 50, 150);
            ctx.stroke();
        }

        function drawDiffusionProcess(ctx, canvas) {
            const steps = 5;
            const stepWidth = canvas.width / (steps + 1);

            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Diffusion Process: From Noise to Image', canvas.width / 2, 30);

            for (let i = 0; i < steps; i++) {
                const x = (i + 1) * stepWidth;
                const noise = 1 - (i / steps);
                ctx.fillStyle = `rgba(0, 212, 255, ${1 - noise})`;
                ctx.fillRect(x - 40, 100, 80, 80);
                ctx.strokeStyle = '#00d4ff';
                ctx.strokeRect(x - 40, 100, 80, 80);
            }
        }

        function drawRNNUnrolled(ctx, canvas) {
            const cells = 5;
            const cellWidth = canvas.width / (cells + 1);

            ctx.fillStyle = '#e4e6eb';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Unrolled RNN', canvas.width / 2, 30);

            for (let i = 0; i < cells; i++) {
                const x = (i + 1) * cellWidth;
                ctx.strokeStyle = '#00d4ff';
                ctx.strokeRect(x - 30, 100, 60, 60);

                if (i < cells - 1) {
                    ctx.strokeStyle = '#ff6b35';
                    ctx.lineWidth = 2;
                    ctx.beginPath();
                    ctx.moveTo(x + 30, 130);
                    ctx.lineTo(x + cellWidth - 30, 130);
                    ctx.stroke();
                }
            }
        }

        function drawBERTProcess(ctx, canvas) { drawAttentionMatrix(ctx, canvas); }
        function drawGPTGeneration(ctx, canvas) { drawAttentionMatrix(ctx, canvas); }
        function drawVisionTransformer(ctx, canvas) { drawAttentionMatrix(ctx, canvas); }

        function drawVisualization(moduleId) {
            drawConceptsVisualization(moduleId);
        }

        // Animation and download utilities
        let animationFrameId = null;

        function toggleVizAnimation(moduleId) {
            const btn = event.target;
            window.vizAnimating = !window.vizAnimating;

            if (window.vizAnimating) {
                btn.textContent = 'โน๏ธ Stop';
                btn.style.background = 'linear-gradient(135deg, #ff4444, #cc0000)';
                animateVisualization(moduleId);
            } else {
                btn.textContent = 'โ–ถ๏ธ Animate';
                btn.style.background = '';
                if (animationFrameId) {
                    cancelAnimationFrame(animationFrameId);
                    animationFrameId = null;
                }
            }
        }

        function animateVisualization(moduleId) {
            if (!window.vizAnimating) return;

            const canvas = document.getElementById(moduleId + '-canvas');
            if (!canvas) return;

            const ctx = canvas.getContext('2d');
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.fillStyle = '#0f1419';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            // Call the appropriate animated drawing function
            const animatedVizMap = {
                'nn-basics': drawAnimatedNetwork,
                'perceptron': drawAnimatedDecisionBoundary,
                'mlp': drawAnimatedMLP,
                'activation': drawAnimatedActivations,
                'conv-layer': drawAnimatedConvolution,
                'gnn': drawAnimatedGNN,
                'transformers': drawAnimatedAttention,
                'backprop': drawAnimatedGradientFlow,
                'gans': drawAnimatedGAN,
                'diffusion': drawAnimatedDiffusion,
                'rnn': drawAnimatedRNN
            };

            if (animatedVizMap[moduleId]) {
                animatedVizMap[moduleId](ctx, canvas, Date.now());
            } else {
                // Default animation - pulsing visualization
                drawDefaultAnimation(ctx, canvas, Date.now());
            }

            animationFrameId = requestAnimationFrame(() => animateVisualization(moduleId));
        }

        // Default animation for modules without specific animations
        function drawDefaultAnimation(ctx, canvas, time) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;
            const pulse = Math.sin(time / 300) * 0.3 + 0.7;

            // Animated neural network
            const layers = [3, 4, 4, 2];
            const layerWidth = canvas.width / (layers.length + 1);

            layers.forEach((neurons, layerIdx) => {
                const x = (layerIdx + 1) * layerWidth;
                const layerHeight = canvas.height / (neurons + 1);

                for (let i = 0; i < neurons; i++) {
                    const y = (i + 1) * layerHeight;
                    const radius = 12 + Math.sin(time / 200 + layerIdx + i) * 3;

                    // Draw neuron
                    ctx.fillStyle = `rgba(0, 212, 255, ${pulse})`;
                    ctx.beginPath();
                    ctx.arc(x, y, radius, 0, Math.PI * 2);
                    ctx.fill();

                    // Draw connections to next layer
                    if (layerIdx < layers.length - 1) {
                        const nextLayerHeight = canvas.height / (layers[layerIdx + 1] + 1);
                        const nextX = (layerIdx + 2) * layerWidth;

                        for (let j = 0; j < layers[layerIdx + 1]; j++) {
                            const nextY = (j + 1) * nextLayerHeight;
                            const signalProgress = ((time / 500) + layerIdx * 0.5) % 1;

                            ctx.strokeStyle = `rgba(0, 212, 255, ${0.3 + signalProgress * 0.3})`;
                            ctx.lineWidth = 1;
                            ctx.beginPath();
                            ctx.moveTo(x + radius, y);
                            ctx.lineTo(nextX - 12, nextY);
                            ctx.stroke();

                            // Animated signal dot
                            const dotX = x + radius + (nextX - 12 - x - radius) * signalProgress;
                            const dotY = y + (nextY - y) * signalProgress;
                            ctx.fillStyle = '#00ff88';
                            ctx.beginPath();
                            ctx.arc(dotX, dotY, 3, 0, Math.PI * 2);
                            ctx.fill();
                        }
                    }
                }
            });

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ”„ Neural Network Animation', centerX, 25);
        }

        // Animated GNN with message passing
        function drawAnimatedGNN(ctx, canvas, time) {
            ctx.fillStyle = '#9900ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Graph Neural Network - Message Passing', canvas.width / 2, 30);

            const nodes = [
                { x: 100, y: 100 }, { x: 200, y: 60 }, { x: 320, y: 120 },
                { x: 150, y: 200 }, { x: 400, y: 80 }, { x: 450, y: 180 }
            ];
            const edges = [[0, 1], [0, 3], [1, 2], [1, 4], [2, 3], [2, 4], [4, 5]];

            // Draw edges
            ctx.strokeStyle = 'rgba(153, 0, 255, 0.4)';
            ctx.lineWidth = 2;
            edges.forEach(e => {
                ctx.beginPath();
                ctx.moveTo(nodes[e[0]].x, nodes[e[0]].y);
                ctx.lineTo(nodes[e[1]].x, nodes[e[1]].y);
                ctx.stroke();
            });

            // Draw animated message passing
            const messageProgress = (time / 1000) % 1;
            ctx.fillStyle = '#00ff88';
            edges.forEach((e, idx) => {
                const progress = (messageProgress + idx * 0.15) % 1;
                const x = nodes[e[0]].x + (nodes[e[1]].x - nodes[e[0]].x) * progress;
                const y = nodes[e[0]].y + (nodes[e[1]].y - nodes[e[0]].y) * progress;
                ctx.beginPath();
                ctx.arc(x, y, 5, 0, Math.PI * 2);
                ctx.fill();
            });

            // Draw nodes with pulse
            const pulse = Math.sin(time / 300) * 5 + 15;
            nodes.forEach((n, i) => {
                ctx.fillStyle = '#9900ff';
                ctx.beginPath();
                ctx.arc(n.x, n.y, pulse, 0, Math.PI * 2);
                ctx.fill();
                ctx.fillStyle = 'white';
                ctx.font = '12px Arial';
                ctx.textAlign = 'center';
                ctx.fillText(i, n.x, n.y + 4);
            });
        }

        // Animated attention matrix
        function drawAnimatedAttention(ctx, canvas, time) {
            const words = ['The', 'cat', 'sat', 'on', 'mat'];
            const cellSize = 50;
            const startX = (canvas.width - words.length * cellSize) / 2;
            const startY = 80;

            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Self-Attention Animation', canvas.width / 2, 30);

            // Draw words
            ctx.font = '12px Arial';
            words.forEach((word, i) => {
                ctx.fillStyle = '#e4e6eb';
                ctx.fillText(word, startX + i * cellSize + cellSize / 2, startY - 10);
                ctx.save();
                ctx.translate(startX - 20, startY + i * cellSize + cellSize / 2);
                ctx.fillText(word, 0, 0);
                ctx.restore();
            });

            // Animated attention weights
            for (let i = 0; i < words.length; i++) {
                for (let j = 0; j < words.length; j++) {
                    const baseWeight = i === j ? 0.8 : 0.2 + Math.abs(i - j) * 0.1;
                    const animatedWeight = baseWeight + Math.sin(time / 500 + i + j) * 0.2;
                    const alpha = Math.max(0.1, Math.min(1, animatedWeight));

                    ctx.fillStyle = `rgba(0, 212, 255, ${alpha})`;
                    ctx.fillRect(startX + j * cellSize + 2, startY + i * cellSize + 2, cellSize - 4, cellSize - 4);

                    ctx.fillStyle = '#e4e6eb';
                    ctx.font = '10px Arial';
                    ctx.fillText(animatedWeight.toFixed(2), startX + j * cellSize + cellSize / 2, startY + i * cellSize + cellSize / 2 + 4);
                }
            }
        }

        // Animated gradient flow for backprop
        function drawAnimatedGradientFlow(ctx, canvas, time) {
            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Backpropagation - Gradient Flow', canvas.width / 2, 30);

            const layers = [2, 4, 4, 1];
            const layerWidth = canvas.width / (layers.length + 1);

            // Forward pass (left to right) - blue
            const forwardProgress = (time / 2000) % 1;

            layers.forEach((neurons, layerIdx) => {
                const x = (layerIdx + 1) * layerWidth;
                const layerHeight = canvas.height / (neurons + 1);

                for (let i = 0; i < neurons; i++) {
                    const y = (i + 1) * layerHeight;

                    // Pulse effect based on forward pass
                    const isActive = forwardProgress > layerIdx / layers.length;
                    const radius = isActive ? 15 + Math.sin(time / 200) * 3 : 12;

                    ctx.fillStyle = isActive ? '#00d4ff' : 'rgba(0, 212, 255, 0.3)';
                    ctx.beginPath();
                    ctx.arc(x, y, radius, 0, Math.PI * 2);
                    ctx.fill();
                }
            });

            // Backward pass (right to left) - orange/red gradients
            const backwardProgress = ((time / 2000) + 0.5) % 1;

            for (let layerIdx = layers.length - 2; layerIdx >= 0; layerIdx--) {
                const x1 = (layerIdx + 1) * layerWidth;
                const x2 = (layerIdx + 2) * layerWidth;
                const gradientActive = backwardProgress > (layers.length - 2 - layerIdx) / (layers.length - 1);

                if (gradientActive) {
                    const gradX = x2 - (x2 - x1) * ((backwardProgress * (layers.length - 1)) % 1);
                    ctx.fillStyle = '#ff6b35';
                    ctx.beginPath();
                    ctx.arc(gradX, canvas.height / 2, 8, 0, Math.PI * 2);
                    ctx.fill();
                }
            }

            ctx.fillStyle = '#e4e6eb';
            ctx.font = '12px Arial';
            ctx.fillText('Forward: Blue โ†’  |  Backward: Orange โ†', canvas.width / 2, canvas.height - 20);
        }

        // Animated network for nn-basics
        function drawAnimatedNetwork(ctx, canvas, time) {
            drawDefaultAnimation(ctx, canvas, time);
        }

        // Animated decision boundary for perceptron
        function drawAnimatedDecisionBoundary(ctx, canvas, time) {
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;

            ctx.fillStyle = '#ff6b35';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Perceptron Decision Boundary', canvas.width / 2, 30);

            // Animated rotating decision boundary
            const angle = time / 2000;
            const length = 200;

            ctx.strokeStyle = '#ff6b35';
            ctx.lineWidth = 3;
            ctx.beginPath();
            ctx.moveTo(centerX - Math.cos(angle) * length, centerY - Math.sin(angle) * length);
            ctx.lineTo(centerX + Math.cos(angle) * length, centerY + Math.sin(angle) * length);
            ctx.stroke();

            // Fixed sample points
            const points = [
                { x: 100, y: 80, c: 1 }, { x: 150, y: 100, c: 1 }, { x: 120, y: 150, c: 1 },
                { x: 400, y: 200, c: 0 }, { x: 450, y: 180, c: 0 }, { x: 380, y: 250, c: 0 }
            ];

            points.forEach(p => {
                ctx.fillStyle = p.c === 1 ? '#00d4ff' : '#00ff88';
                ctx.beginPath();
                ctx.arc(p.x, p.y, 8, 0, Math.PI * 2);
                ctx.fill();
            });
        }

        function drawAnimatedMLP(ctx, canvas, time) {
            drawDefaultAnimation(ctx, canvas, time);
        }

        function drawAnimatedActivations(ctx, canvas, time) {
            drawActivationFunctions(ctx, canvas);

            // Add animated input marker
            const x = Math.sin(time / 500) * 4;
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;
            const scale = 40;

            ctx.fillStyle = '#ffffff';
            ctx.beginPath();
            ctx.arc(centerX + x * scale, centerY, 6, 0, Math.PI * 2);
            ctx.fill();

            ctx.strokeStyle = '#ffffff';
            ctx.setLineDash([5, 5]);
            ctx.beginPath();
            ctx.moveTo(centerX + x * scale, 0);
            ctx.lineTo(centerX + x * scale, canvas.height);
            ctx.stroke();
            ctx.setLineDash([]);
        }

        function drawAnimatedConvolution(ctx, canvas, time) {
            drawConvolutionAnimation(ctx, canvas);
        }

        function drawAnimatedGAN(ctx, canvas, time) {
            ctx.fillStyle = '#ffaa00';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('GAN Training Animation', canvas.width / 2, 30);

            const phase = Math.floor(time / 1000) % 4;

            // Generator
            ctx.fillStyle = phase <= 1 ? '#00ff88' : 'rgba(0, 255, 136, 0.3)';
            ctx.fillRect(50, 100, 100, 80);
            ctx.fillStyle = '#e4e6eb';
            ctx.font = '12px Arial';
            ctx.fillText('Generator', 100, 145);

            // Fake image
            const noiseToFake = Math.sin(time / 300) * 0.5 + 0.5;
            ctx.fillStyle = `rgba(255, 170, 0, ${noiseToFake})`;
            ctx.fillRect(200, 110, 60, 60);
            ctx.fillStyle = '#e4e6eb';
            ctx.fillText('Fake', 230, 200);

            // Discriminator
            ctx.fillStyle = phase >= 2 ? '#ff6b35' : 'rgba(255, 107, 53, 0.3)';
            ctx.fillRect(320, 100, 100, 80);
            ctx.fillStyle = '#e4e6eb';
            ctx.fillText('Discriminator', 370, 145);

            // Output
            const output = phase === 3 ? 'Real?' : 'Fake?';
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 14px Arial';
            ctx.fillText(output, 370, 220);

            // Arrows
            ctx.strokeStyle = '#e4e6eb';
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(150, 140);
            ctx.lineTo(200, 140);
            ctx.stroke();
            ctx.beginPath();
            ctx.moveTo(260, 140);
            ctx.lineTo(320, 140);
            ctx.stroke();
        }

        function drawAnimatedDiffusion(ctx, canvas, time) {
            ctx.fillStyle = '#9900ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Diffusion Process Animation', canvas.width / 2, 30);

            const steps = 5;
            const stepWidth = canvas.width / (steps + 1);

            const progress = (time / 3000) % 1;
            const currentStep = Math.floor(progress * steps);

            for (let i = 0; i < steps; i++) {
                const x = (i + 1) * stepWidth;
                const y = 150;
                const noiseLevel = i / (steps - 1);
                const isActive = i <= currentStep;

                // Draw square with noise
                ctx.fillStyle = isActive ? '#9900ff' : 'rgba(153, 0, 255, 0.3)';
                ctx.fillRect(x - 30, y - 30, 60, 60);

                // Add noise dots
                if (noiseLevel > 0) {
                    for (let j = 0; j < noiseLevel * 20; j++) {
                        const nx = x - 25 + Math.random() * 50;
                        const ny = y - 25 + Math.random() * 50;
                        ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
                        ctx.fillRect(nx, ny, 2, 2);
                    }
                }

                ctx.fillStyle = '#e4e6eb';
                ctx.font = '10px Arial';
                ctx.fillText(`t=${i}`, x, y + 50);
            }

            ctx.fillStyle = '#e4e6eb';
            ctx.font = '12px Arial';
            ctx.fillText('Clean โ†’ Noisy (Forward) | Noisy โ†’ Clean (Reverse)', canvas.width / 2, canvas.height - 20);
        }

        function drawAnimatedRNN(ctx, canvas, time) {
            ctx.fillStyle = '#00d4ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('RNN Unrolled Through Time', canvas.width / 2, 30);

            const steps = 5;
            const stepWidth = canvas.width / (steps + 1);
            const progress = (time / 500) % steps;
            const activeStep = Math.floor(progress);

            for (let i = 0; i < steps; i++) {
                const x = (i + 1) * stepWidth;
                const y = 150;
                const isActive = i === activeStep;

                // Hidden state
                ctx.fillStyle = isActive ? '#00d4ff' : 'rgba(0, 212, 255, 0.3)';
                ctx.beginPath();
                ctx.arc(x, y, 25, 0, Math.PI * 2);
                ctx.fill();

                ctx.fillStyle = '#e4e6eb';
                ctx.font = '10px Arial';
                ctx.fillText(`h${i}`, x, y + 4);

                // Input arrow
                ctx.strokeStyle = isActive ? '#00ff88' : 'rgba(0, 255, 136, 0.3)';
                ctx.lineWidth = 2;
                ctx.beginPath();
                ctx.moveTo(x, y + 60);
                ctx.lineTo(x, y + 25);
                ctx.stroke();
                ctx.fillText(`x${i}`, x, y + 75);

                // Recurrent connection
                if (i < steps - 1) {
                    ctx.strokeStyle = isActive ? '#ff6b35' : 'rgba(255, 107, 53, 0.3)';
                    ctx.beginPath();
                    ctx.moveTo(x + 25, y);
                    ctx.lineTo(x + stepWidth - 25, y);
                    ctx.stroke();

                    // Animated signal
                    if (isActive) {
                        const signalX = x + 25 + (stepWidth - 50) * (progress % 1);
                        ctx.fillStyle = '#ff6b35';
                        ctx.beginPath();
                        ctx.arc(signalX, y, 5, 0, Math.PI * 2);
                        ctx.fill();
                    }
                }
            }
        }

        function downloadViz(moduleId) {
            const canvas = document.getElementById(moduleId + '-canvas');
            if (!canvas) return;

            const link = document.createElement('a');
            link.href = canvas.toDataURL('image/png');
            link.download = moduleId + '-visualization.png';
            link.click();
        }

        function drawGraphNetwork(ctx, canvas) {
            ctx.fillStyle = '#9900ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Graph Structure & Message Passing', canvas.width / 2, 30);

            const nodes = [
                { x: 100, y: 100 }, { x: 200, y: 50 }, { x: 300, y: 150 },
                { x: 150, y: 250 }, { x: 400, y: 100 }, { x: 500, y: 200 }
            ];
            const edges = [
                [0, 1], [0, 3], [1, 2], [1, 4], [2, 3], [2, 4], [4, 5]
            ];

            // Draw edges
            ctx.strokeStyle = 'rgba(153, 0, 255, 0.4)';
            ctx.lineWidth = 2;
            edges.forEach(e => {
                ctx.beginPath();
                ctx.moveTo(nodes[e[0]].x, nodes[e[0]].y);
                ctx.lineTo(nodes[e[1]].x, nodes[e[1]].y);
                ctx.stroke();
            });

            // Draw nodes
            nodes.forEach((n, i) => {
                ctx.fillStyle = '#9900ff';
                ctx.beginPath();
                ctx.arc(n.x, n.y, 15, 0, Math.PI * 2);
                ctx.fill();
                ctx.fillStyle = 'white';
                ctx.font = '12px Arial';
                ctx.fillText(i, n.x, n.y + 4);
            });

            // Draw Message Passing Animation (fake)
            const t = (Date.now() / 1000) % 2;
            if (t > 1) {
                ctx.strokeStyle = '#00ff88';
                ctx.lineWidth = 4;
                edges.forEach((e, idx) => {
                    if (idx % 2 === 0) {
                        ctx.beginPath();
                        ctx.moveTo(nodes[e[0]].x, nodes[e[0]].y);
                        ctx.lineTo(nodes[e[1]].x, nodes[e[1]].y);
                        ctx.stroke();
                    }
                });
            }
        }

        function drawGNNMath(ctx, canvas) {
            ctx.fillStyle = '#9900ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Graph Convolution Math', canvas.width / 2, 50);

            ctx.fillStyle = '#e4e6eb';
            ctx.font = '14px Courier New';
            ctx.fillText('H(l+1) = ฯƒ(D^-ยฝ A D^-ยฝ H(l) W(l))', canvas.width / 2, 100);

            ctx.fillStyle = '#00ff88';
            ctx.fillText('A = Neighborhood Connections', canvas.width / 2, 150);
            ctx.fillStyle = '#ff6b35';
            ctx.fillText('D = Normalization Factor', canvas.width / 2, 180);
        }

        function drawGNNApplications(ctx, canvas) {
            ctx.fillStyle = '#9900ff';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('๐Ÿ’Š Drug Discovery (Molecular Graphs)', canvas.width / 2, 60);

            ctx.fillStyle = '#00d4ff';
            ctx.fillText('๐Ÿš— Traffic Flow Prediction', canvas.width / 2, 120);

            ctx.fillStyle = '#ff6b35';
            ctx.fillText('๐Ÿ›’ Pinterest/Amazon Recommendations', canvas.width / 2, 180);
        }

        // ============ GenAI Visualizations ============

        function drawVectorSpace(ctx, canvas) {
            const w = canvas.width, h = canvas.height;
            ctx.fillStyle = '#00c9a7';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('Vector Space โ€” Similarity Search', w / 2, 30);

            // Draw axes
            ctx.strokeStyle = 'rgba(0, 201, 167, 0.3)';
            ctx.lineWidth = 1;
            ctx.beginPath(); ctx.moveTo(60, h - 40); ctx.lineTo(w - 20, h - 40); ctx.stroke();
            ctx.beginPath(); ctx.moveTo(60, h - 40); ctx.lineTo(60, 50); ctx.stroke();
            ctx.fillStyle = '#b0b7c3'; ctx.font = '11px Arial';
            ctx.fillText('Dimension 1', w / 2, h - 15);
            ctx.save(); ctx.translate(15, h / 2); ctx.rotate(-Math.PI / 2);
            ctx.fillText('Dimension 2', 0, 0); ctx.restore();

            // Cluster A (documents)
            const clusterA = [
                { x: 200, y: 120, label: 'doc1' }, { x: 230, y: 100, label: 'doc2' },
                { x: 180, y: 140, label: 'doc3' }, { x: 220, y: 150, label: 'doc4' }
            ];
            // Cluster B
            const clusterB = [
                { x: 420, y: 200, label: 'doc5' }, { x: 450, y: 220, label: 'doc6' },
                { x: 400, y: 240, label: 'doc7' }
            ];
            // Query
            const query = { x: 190, y: 130, label: '๐Ÿ” Query' };

            // Draw cluster backgrounds
            ctx.fillStyle = 'rgba(0, 136, 255, 0.08)';
            ctx.beginPath(); ctx.arc(210, 130, 60, 0, Math.PI * 2); ctx.fill();
            ctx.fillStyle = 'rgba(255, 107, 53, 0.08)';
            ctx.beginPath(); ctx.arc(423, 220, 55, 0, Math.PI * 2); ctx.fill();

            // Draw similarity lines from query to nearest
            ctx.strokeStyle = 'rgba(0, 255, 136, 0.5)';
            ctx.lineWidth = 2;
            ctx.setLineDash([5, 3]);
            clusterA.forEach(d => {
                ctx.beginPath(); ctx.moveTo(query.x, query.y);
                ctx.lineTo(d.x, d.y); ctx.stroke();
            });
            ctx.setLineDash([]);

            // Draw document points
            clusterA.forEach(d => {
                ctx.fillStyle = '#0088ff';
                ctx.beginPath(); ctx.arc(d.x, d.y, 8, 0, Math.PI * 2); ctx.fill();
                ctx.fillStyle = '#e4e6eb'; ctx.font = '10px Arial';
                ctx.fillText(d.label, d.x + 12, d.y + 4);
            });
            clusterB.forEach(d => {
                ctx.fillStyle = '#ff6b35';
                ctx.beginPath(); ctx.arc(d.x, d.y, 8, 0, Math.PI * 2); ctx.fill();
                ctx.fillStyle = '#e4e6eb'; ctx.font = '10px Arial';
                ctx.fillText(d.label, d.x + 12, d.y + 4);
            });

            // Draw query
            ctx.fillStyle = '#00ff88';
            ctx.beginPath(); ctx.arc(query.x, query.y, 10, 0, Math.PI * 2); ctx.fill();
            ctx.fillStyle = '#00ff88'; ctx.font = 'bold 12px Arial';
            ctx.fillText(query.label, query.x - 15, query.y - 18);

            // Legend
            ctx.font = '11px Arial'; let ly = h - 80;
            [['#0088ff', 'Cluster A (nearest)'], ['#ff6b35', 'Cluster B'], ['#00ff88', 'Query Vector']].forEach(([c, t]) => {
                ctx.fillStyle = c; ctx.fillRect(w - 160, ly, 10, 10);
                ctx.fillStyle = '#e4e6eb'; ctx.fillText(t, w - 145, ly + 9); ly += 18;
            });

            // Cosine score
            ctx.fillStyle = '#00c9a7'; ctx.font = 'bold 13px Arial';
            ctx.fillText('cos(query, doc1) = 0.97', w / 2, h - 55);
        }

        function drawRAGPipeline(ctx, canvas) {
            const w = canvas.width, h = canvas.height;
            ctx.fillStyle = '#00c9a7';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('RAG Pipeline โ€” Retrieval-Augmented Generation', w / 2, 30);

            const boxes = [
                { x: 30, y: 70, w: 90, h: 50, label: '๐Ÿ“„ Docs', color: '#0088ff' },
                { x: 145, y: 70, w: 90, h: 50, label: 'โœ‚๏ธ Chunk', color: '#0088ff' },
                { x: 260, y: 70, w: 90, h: 50, label: '๐Ÿงฎ Embed', color: '#0088ff' },
                { x: 375, y: 70, w: 100, h: 50, label: '๐Ÿงฒ Vector DB', color: '#0088ff' },
                { x: 30, y: 180, w: 90, h: 50, label: 'โ“ Query', color: '#00ff88' },
                { x: 145, y: 180, w: 90, h: 50, label: '๐Ÿงฎ Embed', color: '#00ff88' },
                { x: 260, y: 180, w: 90, h: 50, label: '๐Ÿ” Retrieve', color: '#ff6b35' },
                { x: 375, y: 180, w: 100, h: 50, label: '๐Ÿค– LLM', color: '#ffaa00' },
                { x: 500, y: 180, w: 90, h: 50, label: 'โœ… Answer', color: '#00c9a7' }
            ];

            // Draw arrows (indexing pipeline)
            ctx.strokeStyle = 'rgba(0, 136, 255, 0.6)'; ctx.lineWidth = 2;
            for (let i = 0; i < 3; i++) {
                ctx.beginPath();
                ctx.moveTo(boxes[i].x + boxes[i].w, boxes[i].y + 25);
                ctx.lineTo(boxes[i + 1].x, boxes[i + 1].y + 25);
                ctx.stroke();
                // Arrowhead
                ctx.fillStyle = 'rgba(0, 136, 255, 0.6)';
                ctx.beginPath();
                ctx.moveTo(boxes[i + 1].x, boxes[i + 1].y + 25);
                ctx.lineTo(boxes[i + 1].x - 8, boxes[i + 1].y + 20);
                ctx.lineTo(boxes[i + 1].x - 8, boxes[i + 1].y + 30);
                ctx.fill();
            }

            // Draw arrows (query pipeline)
            ctx.strokeStyle = 'rgba(0, 255, 136, 0.6)';
            for (let i = 4; i < 8; i++) {
                ctx.beginPath();
                ctx.moveTo(boxes[i].x + boxes[i].w, boxes[i].y + 25);
                ctx.lineTo(boxes[i + 1].x, boxes[i + 1].y + 25);
                ctx.stroke();
                ctx.fillStyle = 'rgba(0, 255, 136, 0.6)';
                ctx.beginPath();
                ctx.moveTo(boxes[i + 1].x, boxes[i + 1].y + 25);
                ctx.lineTo(boxes[i + 1].x - 8, boxes[i + 1].y + 20);
                ctx.lineTo(boxes[i + 1].x - 8, boxes[i + 1].y + 30);
                ctx.fill();
            }

            // Vector DB connection (vertical)
            ctx.strokeStyle = 'rgba(255, 107, 53, 0.6)'; ctx.setLineDash([4, 3]);
            ctx.beginPath();
            ctx.moveTo(boxes[3].x + 50, boxes[3].y + boxes[3].h);
            ctx.lineTo(boxes[6].x + 45, boxes[6].y);
            ctx.stroke(); ctx.setLineDash([]);

            // Draw boxes
            boxes.forEach(b => {
                ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
                ctx.fillRect(b.x, b.y, b.w, b.h);
                ctx.strokeStyle = b.color; ctx.lineWidth = 2;
                ctx.strokeRect(b.x, b.y, b.w, b.h);
                ctx.fillStyle = '#e4e6eb'; ctx.font = '11px Arial'; ctx.textAlign = 'center';
                ctx.fillText(b.label, b.x + b.w / 2, b.y + 30);
            });

            // Labels
            ctx.font = 'bold 12px Arial'; ctx.textAlign = 'left';
            ctx.fillStyle = '#0088ff'; ctx.fillText('Indexing (Offline)', 30, 60);
            ctx.fillStyle = '#00ff88'; ctx.fillText('Query (Online)', 30, 170);
        }

        function drawLoRADiagram(ctx, canvas) {
            const w = canvas.width, h = canvas.height;
            ctx.fillStyle = '#00c9a7';
            ctx.font = 'bold 16px Arial';
            ctx.textAlign = 'center';
            ctx.fillText('LoRA โ€” Low-Rank Adaptation', w / 2, 30);

            // Original Weight Matrix W (large)
            const wX = 50, wY = 60, wW = 120, wH = 120;
            ctx.fillStyle = 'rgba(0, 136, 255, 0.15)';
            ctx.fillRect(wX, wY, wW, wH);
            ctx.strokeStyle = '#0088ff'; ctx.lineWidth = 2;
            ctx.strokeRect(wX, wY, wW, wH);
            ctx.fillStyle = '#0088ff'; ctx.font = 'bold 14px Arial';
            ctx.fillText('W', wX + wW / 2, wY + wH / 2 + 5);
            ctx.font = '10px Arial'; ctx.fillStyle = '#b0b7c3';
            ctx.fillText('d ร— d', wX + wW / 2, wY + wH / 2 + 22);
            ctx.fillText('(Frozen)', wX + wW / 2, wY - 8);

            // Plus sign
            ctx.fillStyle = '#e4e6eb'; ctx.font = 'bold 24px Arial';
            ctx.fillText('+', wX + wW + 30, wY + wH / 2 + 8);

            // LoRA matrices B and A
            const bX = 230, bY = 60, bW = 30, bH = 120;
            ctx.fillStyle = 'rgba(0, 255, 136, 0.2)';
            ctx.fillRect(bX, bY, bW, bH);
            ctx.strokeStyle = '#00ff88'; ctx.lineWidth = 2;
            ctx.strokeRect(bX, bY, bW, bH);
            ctx.fillStyle = '#00ff88'; ctx.font = 'bold 14px Arial';
            ctx.fillText('B', bX + bW / 2, bY + bH / 2 + 5);
            ctx.font = '10px Arial'; ctx.fillStyle = '#b0b7c3';
            ctx.fillText('dร—r', bX + bW / 2, bY - 8);

            // ร— symbol
            ctx.fillStyle = '#e4e6eb'; ctx.font = 'bold 18px Arial';
            ctx.fillText('ร—', bX + bW + 18, bY + bH / 2 + 5);

            const aX = 290, aY = 100, aW = 120, aH = 30;
            ctx.fillStyle = 'rgba(255, 107, 53, 0.2)';
            ctx.fillRect(aX, aY, aW, aH);
            ctx.strokeStyle = '#ff6b35'; ctx.lineWidth = 2;
            ctx.strokeRect(aX, aY, aW, aH);
            ctx.fillStyle = '#ff6b35'; ctx.font = 'bold 14px Arial';
            ctx.fillText('A', aX + aW / 2, aY + aH / 2 + 5);
            ctx.font = '10px Arial'; ctx.fillStyle = '#b0b7c3';
            ctx.fillText('rร—d', aX + aW / 2, aY - 8);

            // = sign
            ctx.fillStyle = '#e4e6eb'; ctx.font = 'bold 24px Arial';
            ctx.fillText('=', aX + aW + 25, wY + wH / 2 + 8);

            // Result W'
            const rX = 460, rY = 60, rW = 120, rH = 120;
            ctx.fillStyle = 'rgba(0, 201, 167, 0.15)';
            ctx.fillRect(rX, rY, rW, rH);
            ctx.strokeStyle = '#00c9a7'; ctx.lineWidth = 2;
            ctx.strokeRect(rX, rY, rW, rH);
            ctx.fillStyle = '#00c9a7'; ctx.font = 'bold 14px Arial';
            ctx.fillText("W'", rX + rW / 2, rY + rH / 2 + 5);
            ctx.font = '10px Arial'; ctx.fillStyle = '#b0b7c3';
            ctx.fillText('d ร— d', rX + rW / 2, rY + rH / 2 + 22);
            ctx.fillText('(Adapted)', rX + rW / 2, rY - 8);

            // Stats
            ctx.font = '12px Arial'; ctx.textAlign = 'left';
            ctx.fillStyle = '#0088ff'; ctx.fillText('Full: 16,777,216 params', 50, 220);
            ctx.fillStyle = '#00ff88'; ctx.fillText('LoRA (r=16): 131,072 params', 50, 240);
            ctx.fillStyle = '#00c9a7'; ctx.fillText('Savings: 128x reduction (0.78%)', 50, 260);

            // Quantization bar chart
            ctx.fillStyle = '#e4e6eb'; ctx.font = 'bold 12px Arial'; ctx.textAlign = 'center';
            ctx.fillText('Memory: 7B Model', 480, 210);
            const bars = [
                { label: 'fp32', val: 28, color: '#ff6b35' },
                { label: 'fp16', val: 14, color: '#ffaa00' },
                { label: 'INT8', val: 7, color: '#0088ff' },
                { label: 'INT4', val: 3.5, color: '#00ff88' }
            ];
            bars.forEach((b, i) => {
                const bw = b.val * 4.5;
                ctx.fillStyle = b.color;
                ctx.fillRect(430, 220 + i * 22, bw, 16);
                ctx.fillStyle = '#e4e6eb'; ctx.font = '10px Arial'; ctx.textAlign = 'left';
                ctx.fillText(`${b.label}: ${b.val}GB`, 430 + bw + 5, 233 + i * 22);
            });
        }

        initDashboard();
    </script>
</body>

</html>