chenglu commited on
Commit
2252c65
1 Parent(s): 87ecdac

Update Thinking Like Transformers-cn.md

Browse files
Files changed (1) hide show
  1. Thinking Like Transformers-cn.md +57 -57
Thinking Like Transformers-cn.md CHANGED
@@ -1,20 +1,20 @@
1
- # 像Transformer一样思考
2
- - [论文](https://arxiv.org/pdf/2106.06981.pdf)来自Gail Weiss, Yoav Goldberg,Eran Yahav.
3
- - 博客参考[ Sasha Rush ](https://rush-nlp.com/)和[ Gail Weiss ](https://sgailw.cswp.cs.technion.ac.il/)
4
- - 库和交互Notebook:[ srush/raspy ](https://github.com/srush/RASPy)
5
 
6
 
7
- Transformer 模型是AI系统的基础。已经有了数不清的关于" Transformer 如何工作"的核心结构图表。
 
 
 
 
8
 
9
  <center>
10
 
11
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(1).svg)
12
 
13
  </center>
14
 
15
  但是这些图表没有提供任何直观的计算该模型的框架表示。当研究者对于 Transformer 如何工作抱有兴趣时,直观的获取他运行的机制变得十分有用。
16
 
17
- [像Transformers一样思考](https://arxiv.org/pdf/2106.06981.pdf)提出 transformer 类计算框架。这个框架直接计算和模仿 Transformer 计算。使用[ RASP ](https://github.com/tech-srl/RASP)编程语言,使每个程序编译成一个特殊的 Transformer 。
18
 
19
  在这篇博客中,我用 python 复现了 RASP 的变体( RASPy )。该语言大致与原始版本相当,但是多了一些我认为很有趣的变化。通过这些语言,作者 Gail Weiss 的工作,提供了一套具有挑战性的有趣且正确的方式可以帮助了解其工作原理。
20
 
@@ -33,7 +33,7 @@ flip()
33
  ```
34
  <center>
35
 
36
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(2).svg)
37
 
38
  </center>
39
  ## 表格目录
@@ -53,7 +53,7 @@ flip()
53
 
54
  <center>
55
 
56
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(3).svg)
57
 
58
  </center>
59
 
@@ -65,7 +65,7 @@ tokens
65
 
66
  <center>
67
 
68
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(4).svg)
69
 
70
  </center>
71
 
@@ -77,7 +77,7 @@ tokens.input([5, 2, 4, 5, 2, 2])
77
 
78
  <center>
79
 
80
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(5).svg)
81
 
82
  </center>
83
 
@@ -90,7 +90,7 @@ indices
90
 
91
  <center>
92
 
93
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(6).svg)
94
 
95
  </center>
96
 
@@ -101,7 +101,7 @@ sop.input("goodbye")
101
 
102
  <center>
103
 
104
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(7).svg)
105
 
106
  </center>
107
 
@@ -112,7 +112,7 @@ sop.input("goodbye")
112
 
113
  <center>
114
 
115
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(8).svg)
116
 
117
  </center>
118
 
@@ -124,7 +124,7 @@ tokens == "l"
124
 
125
  <center>
126
 
127
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(9).svg)
128
 
129
  </center>
130
 
@@ -137,7 +137,7 @@ model.input([1, 2, 3, 5, 2])
137
 
138
  <center>
139
 
140
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(10).svg)
141
 
142
  </center>
143
 
@@ -150,7 +150,7 @@ model.input([1, 2, 3, 5, 2])
150
 
151
  <center>
152
 
153
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(11).svg)
154
 
155
  </center>
156
 
@@ -161,7 +161,7 @@ model.input([1, 2, 3, 5, 2])
161
 
162
  <center>
163
 
164
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(12).svg)
165
 
166
  </center>
167
 
@@ -174,7 +174,7 @@ where((tokens == "h") | (tokens == "l"), tokens, "q")
174
 
175
  <center>
176
 
177
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(13).svg)
178
 
179
  </center>
180
 
@@ -187,7 +187,7 @@ atoi.input("31234")
187
 
188
  <center>
189
 
190
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(14).svg)
191
 
192
  </center>
193
 
@@ -205,7 +205,7 @@ op.input("02-13")
205
 
206
  <center>
207
 
208
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(15).svg)
209
 
210
  </center>
211
 
@@ -214,7 +214,7 @@ op.input("02-13")
214
 
215
  <center>
216
 
217
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(16).svg)
218
 
219
  </center>
220
 
@@ -226,7 +226,7 @@ key(tokens)
226
 
227
  <center>
228
 
229
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(17).svg)
230
 
231
  </center>
232
 
@@ -239,7 +239,7 @@ query(tokens)
239
 
240
  <center>
241
 
242
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(18).svg)
243
 
244
  </center>
245
 
@@ -252,7 +252,7 @@ query(1)
252
 
253
  <center>
254
 
255
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(19).svg)
256
 
257
  </center>
258
 
@@ -266,7 +266,7 @@ eq
266
 
267
  <center>
268
 
269
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(20).svg)
270
 
271
  </center>
272
 
@@ -281,7 +281,7 @@ offset
281
 
282
  <center>
283
 
284
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(21).svg)
285
 
286
  </center>
287
 
@@ -295,7 +295,7 @@ before
295
 
296
  <center>
297
 
298
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(22).svg)
299
 
300
  </center>
301
 
@@ -309,7 +309,7 @@ after
309
 
310
  <center>
311
 
312
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(23).svg)
313
 
314
  </center>
315
 
@@ -321,7 +321,7 @@ before & eq
321
 
322
  <center>
323
 
324
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(24).svg)
325
 
326
  </center>
327
 
@@ -339,7 +339,7 @@ before & eq
339
 
340
  <center>
341
 
342
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(25).svg)
343
 
344
  </center>
345
 
@@ -347,7 +347,7 @@ before & eq
347
 
348
  <center>
349
 
350
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(27).svg)
351
 
352
  </center>
353
 
@@ -362,7 +362,7 @@ length
362
 
363
  <center>
364
 
365
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(28).svg)
366
 
367
  </center>
368
 
@@ -379,7 +379,7 @@ s1
379
 
380
  <center>
381
 
382
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(29).svg)
383
 
384
  </center>
385
 
@@ -391,7 +391,7 @@ s2
391
  ```
392
  <center>
393
 
394
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(30).svg)
395
 
396
  </center>
397
 
@@ -404,7 +404,7 @@ sel
404
 
405
  <center>
406
 
407
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(31).svg)
408
 
409
  </center>
410
 
@@ -417,7 +417,7 @@ sum2.input([1,3,2,2,2])
417
 
418
  <center>
419
 
420
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(32).svg)
421
 
422
  </center>
423
 
@@ -432,17 +432,17 @@ cumsum().input([3, 1, -2, 3, 1])
432
 
433
  <center>
434
 
435
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(33).svg)
436
 
437
  </center>
438
 
439
 
440
  ### 层
441
- 这个语言支持编译更加复杂的 transforms 。他同时通过跟踪每一个运算操作计算层。
442
 
443
  <center>
444
 
445
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(34).svg)
446
 
447
  </center>
448
 
@@ -456,7 +456,7 @@ x.input([3, 2, 3, 5])
456
 
457
  <center>
458
 
459
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(35).svg)
460
 
461
  </center>
462
 
@@ -486,7 +486,7 @@ index(1)
486
 
487
  <center>
488
 
489
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(36).svg)
490
 
491
  </center>
492
 
@@ -504,13 +504,13 @@ shift(2)
504
 
505
  <center>
506
 
507
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(37).svg)
508
 
509
  </center>
510
 
511
  ### 挑战三 :最小化
512
 
513
- 计算序列的最小值。(这一步开始变得困难,我们版本用了2层注意力机制)
514
 
515
  ```python
516
  def minimum(seq=tokens):
@@ -524,7 +524,7 @@ minimum()([5,3,2,5,2])
524
 
525
  <center>
526
 
527
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(38).svg)
528
 
529
  </center>
530
 
@@ -540,7 +540,7 @@ first("l")
540
 
541
  <center>
542
 
543
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(39).svg)
544
 
545
  </center>
546
 
@@ -558,7 +558,7 @@ ralign()("xyz__")
558
 
559
  <center>
560
 
561
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(40).svg)
562
 
563
  </center>
564
 
@@ -581,7 +581,7 @@ split("+", 1)("xyz+zyr")
581
 
582
  <center>
583
 
584
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(41).svg)
585
 
586
  </center>
587
 
@@ -591,7 +591,7 @@ split("+", 0)("xyz+zyr")
591
 
592
  <center>
593
 
594
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(42).svg)
595
 
596
  </center>
597
 
@@ -610,13 +610,13 @@ slide(tokens != "<").input("xxxh<<<l")
610
 
611
  <center>
612
 
613
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download%20(43).svg)
614
 
615
  </center>
616
 
617
  ## 挑战八:增加
618
 
619
- 您要执行两个数字的添加。这是步骤。
620
 
621
  ```python
622
  add().input("683+345")
@@ -636,7 +636,7 @@ add().input("683+345")
636
 
637
  3. 完成加法
638
 
639
- 这些都是1行代码。完整的系统是6个注意力机制。(尽管 Gail 说,如果您足够细心则可以在5个中完成!)。
640
 
641
  ```python
642
  def add(sop=tokens):
@@ -652,7 +652,7 @@ add()("683+345")
652
  ```
653
  <center>
654
 
655
- ![](https://raw.githubusercontent.com/innovation64/Picimg/main/download.svg)
656
 
657
  </center>
658
 
@@ -663,11 +663,11 @@ add()("683+345")
663
  ```python
664
  1028
665
  ```
666
- 非常整洁的东西。如果您对此主题更感兴趣,请务必查看论文:
667
 
668
  像 Transformer 和 RASP 语言一样思考。
669
 
670
- 如果您通常对形式语言和神经网络 ( FLaNN ) 的联系感兴趣,或者认识感兴趣的人,那么这里有一个在线社区,到目前为止非常友好且相当活跃!
671
 
672
  在 https://flann.super.site/ 上查看。
673
 
@@ -675,5 +675,5 @@ add()("683+345")
675
 
676
  <hr>
677
 
678
- >>>> 英文原文:[Thinking Like Transformers](https://srush.github.io/raspy/)
679
- >>>> 译者:innovation64 (李洋)
 
 
 
 
 
1
 
2
 
3
+ - [论文](https://arxiv.org/pdf/2106.06981.pdf) 来自 Gail Weiss, Yoav Goldberg,Eran Yahav.
4
+ - 博客参考 [Sasha Rush](https://rush-nlp.com/) 和 [Gail Weiss](https://sgailw.cswp.cs.technion.ac.il/)
5
+ - 库和交互 Notebook: [srush/raspy](https://github.com/srush/RASPy)
6
+
7
+ Transformer 模型是 AI 系统的基础。已经有了数不清的关于 "Transformer 如何工作" 的核心结构图表。
8
 
9
  <center>
10
 
11
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/fdf5ede1d0656.jpg)
12
 
13
  </center>
14
 
15
  但是这些图表没有提供任何直观的计算该模型的框架表示。当研究者对于 Transformer 如何工作抱有兴趣时,直观的获取他运行的机制变得十分有用。
16
 
17
+ [像Transformers一样思考](https://arxiv.org/pdf/2106.06981.pdf)提出 transformer 类计算框架。这个框架直接计算和模仿 Transformer 计算。使用 [RASP](https://github.com/tech-srl/RASP) 编程语言,使每个程序编译成一个特殊的 Transformer 。
18
 
19
  在这篇博客中,我用 python 复现了 RASP 的变体( RASPy )。该语言大致与原始版本相当,但是多了一些我认为很有趣的变化。通过这些语言,作者 Gail Weiss 的工作,提供了一套具有挑战性的有趣且正确的方式可以帮助了解其工作原理。
20
 
 
33
  ```
34
  <center>
35
 
36
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/c2ce067112df6.jpg)
37
 
38
  </center>
39
  ## 表格目录
 
53
 
54
  <center>
55
 
56
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/9b3880c89cddc.jpg)
57
 
58
  </center>
59
 
 
65
 
66
  <center>
67
 
68
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/74668f0bf46e0.jpg)
69
 
70
  </center>
71
 
 
77
 
78
  <center>
79
 
80
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/cae5a2208f808.jpg)
81
 
82
  </center>
83
 
 
90
 
91
  <center>
92
 
93
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/a0a85cb46698a.jpg)
94
 
95
  </center>
96
 
 
101
 
102
  <center>
103
 
104
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/88f599c30ba09.jpg)
105
 
106
  </center>
107
 
 
112
 
113
  <center>
114
 
115
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/20bc37ba063fc.jpg)
116
 
117
  </center>
118
 
 
124
 
125
  <center>
126
 
127
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/2262f13a202af.jpg)
128
 
129
  </center>
130
 
 
137
 
138
  <center>
139
 
140
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/3cf8157521c96.jpg)
141
 
142
  </center>
143
 
 
150
 
151
  <center>
152
 
153
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/9c73afb70fd78.jpg)
154
 
155
  </center>
156
 
 
161
 
162
  <center>
163
 
164
+ ![](hhttps://devrel.andfun.cn/devrel/posts/2023/01/eefdb8ae5c929.jpg)
165
 
166
  </center>
167
 
 
174
 
175
  <center>
176
 
177
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/46eac496f9afb.jpg)
178
 
179
  </center>
180
 
 
187
 
188
  <center>
189
 
190
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f7da799e5e2c6.jpg)
191
 
192
  </center>
193
 
 
205
 
206
  <center>
207
 
208
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/888c454a256e6.jpg)
209
 
210
  </center>
211
 
 
214
 
215
  <center>
216
 
217
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/ec55c964b6280.jpg)
218
 
219
  </center>
220
 
 
226
 
227
  <center>
228
 
229
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/d737b1a7b02db.jpg)
230
 
231
  </center>
232
 
 
239
 
240
  <center>
241
 
242
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/e464ca2e26db6.jpg)
243
 
244
  </center>
245
 
 
252
 
253
  <center>
254
 
255
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/eb151bafa0c31.jpg)
256
 
257
  </center>
258
 
 
266
 
267
  <center>
268
 
269
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f6e54bb8d4e4b.jpg)
270
 
271
  </center>
272
 
 
281
 
282
  <center>
283
 
284
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/cd1c4e50eab36.jpg)
285
 
286
  </center>
287
 
 
295
 
296
  <center>
297
 
298
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/c9084526bd12a.jpg)
299
 
300
  </center>
301
 
 
309
 
310
  <center>
311
 
312
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f5a8b3e8fe2ff.jpg)
313
 
314
  </center>
315
 
 
321
 
322
  <center>
323
 
324
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/a3d777c4d3bf0.jpg)
325
 
326
  </center>
327
 
 
339
 
340
  <center>
341
 
342
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/2480616d469d3.jpg)
343
 
344
  </center>
345
 
 
347
 
348
  <center>
349
 
350
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/61b054ef9d980.jpg)
351
 
352
  </center>
353
 
 
362
 
363
  <center>
364
 
365
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/fb750cdecc7b5.jpg)
366
 
367
  </center>
368
 
 
379
 
380
  <center>
381
 
382
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/342f3de71068f.jpg)
383
 
384
  </center>
385
 
 
391
  ```
392
  <center>
393
 
394
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f7d8cd3740935.jpg)
395
 
396
  </center>
397
 
 
404
 
405
  <center>
406
 
407
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/a5840fc2b397e.jpg)
408
 
409
  </center>
410
 
 
417
 
418
  <center>
419
 
420
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/132bb58b8948f.jpg)
421
 
422
  </center>
423
 
 
432
 
433
  <center>
434
 
435
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/bfaace579610a.jpg)
436
 
437
  </center>
438
 
439
 
440
  ### 层
441
+ 这个语言支持编译更加复杂的 transforms。他同时通过跟踪每一个运算操作计算层。
442
 
443
  <center>
444
 
445
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/3596032dc760e.jpg)
446
 
447
  </center>
448
 
 
456
 
457
  <center>
458
 
459
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/54d1ded5a9d85.jpg)
460
 
461
  </center>
462
 
 
486
 
487
  <center>
488
 
489
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f357ce42e5db5.jpg)
490
 
491
  </center>
492
 
 
504
 
505
  <center>
506
 
507
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/152755bcf4f76.jpg)
508
 
509
  </center>
510
 
511
  ### 挑战三 :最小化
512
 
513
+ 计算序列的最小值。(这一步开始变得困难,我们版本用了 2 层注意力机制)
514
 
515
  ```python
516
  def minimum(seq=tokens):
 
524
 
525
  <center>
526
 
527
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/f8f4c65d3402d.jpg)
528
 
529
  </center>
530
 
 
540
 
541
  <center>
542
 
543
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/95fd6f19781b3.jpg)
544
 
545
  </center>
546
 
 
558
 
559
  <center>
560
 
561
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/8ec0a6464037a.jpg)
562
 
563
  </center>
564
 
 
581
 
582
  <center>
583
 
584
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/7c4b7272a47b3.jpg)
585
 
586
  </center>
587
 
 
591
 
592
  <center>
593
 
594
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/9f5a2a64f0111.jpg)
595
 
596
  </center>
597
 
 
610
 
611
  <center>
612
 
613
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/27b3d49a00b63.jpg)
614
 
615
  </center>
616
 
617
  ## 挑战八:增加
618
 
619
+ 你要执行两个数字的添加。这是步骤。
620
 
621
  ```python
622
  add().input("683+345")
 
636
 
637
  3. 完成加法
638
 
639
+ 这些都是1行代码。完整的系统是6个注意力机制。(尽管 Gail 说,如果你足够细心则可以在5个中完成!)。
640
 
641
  ```python
642
  def add(sop=tokens):
 
652
  ```
653
  <center>
654
 
655
+ ![](https://devrel.andfun.cn/devrel/posts/2023/01/0c57f3e6ae5ac.jpg)
656
 
657
  </center>
658
 
 
663
  ```python
664
  1028
665
  ```
666
+ 非常整洁的东西。如果你对此主题更感兴趣,请务必查看论文:
667
 
668
  像 Transformer 和 RASP 语言一样思考。
669
 
670
+ 如果你通常对形式语言和神经网络 (FLaNN) 的联系感兴趣,或者认识感兴趣的人,那么这里有一个在线社区,到目前为止非常友好且相当活跃!
671
 
672
  在 https://flann.super.site/ 上查看。
673
 
 
675
 
676
  <hr>
677
 
678
+ > 英文原文:[Thinking Like Transformers](https://srush.github.io/raspy/)
679
+ > 译者:innovation64 (李洋)