三個有關Self-Attention比較重要的資訊:
- 自注意力其實是模仿擴散活化
- 自注意力可以看作是核方法
- 從上下文內學習(In-context learning)其實是即時的梯度下降修正
1.自注意力Self-Attention 是認知心理學啟動效應(priming)或是(語義)擴散活化(spreading activation)理論的模仿。這種模仿類似類神經網路的神經元模仿生物神經元的大致模式,是一個有效的簡化版本。
而Self-Attention能解決一詞多義的問題
比起過去的Recurrent Neural Network 使用在NLP問題上,通常採用預先訓練的word embedding 將輸入的詞彙映射到表徵空間中,這樣的結果會使得一個詞彙只能對應到一個語義,即使是在訓練中讓embedding一起訓練,得到的結果依然是一組全局的靜態的一對一語義表徵。Self-Attention在一詞多義的問題上,有能力針對當前輸入的語句做出動態的語義”校正”,用類似spreading activation的概念來動態調整詞彙的語義。
2. 自注意力Self-Attention也可推導出徑向基函數核(RBF Kernel),相當於是將輸入的句子做升維。
這部分可以看做是Self-Attention在解決文法結構
文法結構通常可以用樹(Tree)的結構來描繪,而語義和文法也是很有直接關係。傳統NLP的作法會使用依存句法分析的演算法來”還原”一個句子,然後再做後續語義的判讀。或者,從語言的角度看,會認為語言本身就不是一維,但受限於我們的發音只能一次傳達一個符號,所以人類的交流只能”降維”壓縮到一維。Recurrent Neural Network等方法還是只有前後關係,效果當然不好,直到後來出現RNN的attention,可能稍微好些。而Self-attention mechanism的另外一個效果可被等價看作是對輸入做RBF kernel的操作,將輸入的語句”升維”回去,等價對的文法進行理解。
3.從上下文內學習(In-context learning)是自注意力Self-Attention以元學習的形式將上下文範例產生的誤差給當前輸入做即時的梯度下降法來修正輸出,達到類似人類只需要少量範例再搭配過去經驗就能學習和推理的效果。
In-context Learning 的出現讓類似人類學習的模式已經出現,這是過去機器學習演算法從未有過的能力,其大致原理可以從權重修正量梯度去拆解出Attention的式子,進而導出In-context Learning的修正方式。
另外兩個訓練的典範轉移
一個是在LLM中用prompt learning 取代 fine-tune,而另一個是用RL來對齊人類的偏好。
Reference:
- Ratcliff, R., & McKoon, G. (1981). Does activation really spread? Psychological Review, 88, 454-462.
- Anderson, J. R. (1995). Cognitive psychology and its implications (4th ed.). New York: W. H. Freeman.
- Lerner, I., Bentin, S., & Shriki, O. (2012). Spreading Activation in an Attractor Network With Latching Dynamics: Automatic Semantic Priming Revisited. Cognitive Science, 36(, 1339–1382.https://doi.org/10.1111/cogs.12007
- Evans, V., & Green, M. (2006). Cognitive Linguistics: An Introduction. Psychology Press.
- Digutsch, J., & Kosinski, M. (2023). Overlap in meaning is a stronger predictor of semantic activation in GPT-3 than in humans. Scientific Reports, 13(1).https://doi.org/10.1038/s41598-023-32248-6
- Lindsay, G. M. (2020). Attention in Psychology, Neuroscience, and Machine Learning. Frontiers in Computational Neuroscience, 14.https://doi.org/10.3389/fncom.2020.00029
- Peng, H., Pappas, N., Yogatama, D., Schwartz, R., Smith, N. A., & Kong, L. (2021). Random Feature Attention. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2103.02143
- Xiong, Y., Zeng, Z., Chakraborty, R., Tan, M., Fung, G., Li, Y., & Singh, V. (2021). Nyströmformer: A Nyström-Based Algorithm for Approximating Self-Attention. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2102.03902
- Gokhan Egri, Xinran (Nicole) Han (2021). Attention is Kernel Trick Reloaded. https://egrigokhan.github.io/……/cs_229_br_Project……
- Dai, D., Sun, Y., Dong, L., Hao, Y., Sui, Z., & Wei, F. (2022). Why Can GPT Learn In-Context? Language Models Secretly Perform Gradient Descent as Meta-Optimizers. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2212.10559
- Von Oswald, J., Niklasson, E., Randazzo, E., Sacramento, J., Mordvintsev, A., Zhmoginov, A., & Vladymyrov, M. (2022). Transformers learn in-context by gradient descent. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2212.07677
- Akyürek, E., Schuurmans, D., Andreas, J., Ma, T., & Zhou, D. (2022). What learning algorithm is in-context learning? Investigations with linear models. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2211.15661
- Xie, S. M., Raghunathan, A., Liang, P., & Ma, T. (2021). An Explanation of In-context Learning as Implicit Bayesian Inference. arXiv (Cornell University). https://doi.org/10.48550/arxiv.2111.02080
本文允許重製、散布、傳輸以及修改,但不得為商業目的之使用
使用時必須註明出處自:楊明翰 , 台灣人工智慧與資料科學研究室 https://aistudio.tw