概述
這是 Transformer 的核心操作,而注意力遮罩和模型架構決定了哪些位置可以貢獻於每個表示。
深入探討
The 2017 Attention Is All You Need paper introduced the transformer architecture built around attention rather than recurrence. Attention can be described through queries, keys, and values. A query is compared with keys to produce scores, and normalized weights combine the corresponding value vectors. Self-attention uses representations from the same sequence, while cross-attention can obtain keys and values from a separate encoded sequence. The allowed positions are important: a causal decoder mask prevents a position from using future positions during autoregressive training or generation. It is therefore inaccurate to say that every self-attention layer always reads every token without restrictions. Scaled dot-product attention divides query-key dot products by the square root of the key dimension before softmax. This scaling addresses how score magnitudes grow with dimension under the paper's assumptions. Softmax produces normalized weights over allowed positions, and the weighted value sum becomes the attention output. In a simple scalar illustration, values two and six with weights three-quarters and one-quarter combine to three. Multi-head attention performs several learned projections and attention operations before combining their outputs. It provides capacity to represent different relationships or subspaces without guaranteeing that every head has a unique, human-readable semantic role. Dense full attention involves pairwise interactions that scale quadratically with sequence length. Efficient implementations and alternative attention patterns address different costs; their benefits need measurement for a particular workload.
現實世界的實施
使用解碼器交叉注意力來組合來自編碼源序列的資訊。
在預測文字時應用因果自注意力,而不查看後續位置。
在對值向量進行加權之前,比較學習到的查詢-鍵分數。
評估特定序列長度下注意力實現的記憶體使用和執行時間。
注意力機制的未來
注意力研究探討實現方式、稀疏模式、共享鍵值投影和混合架構。這些技術改變計算的不同部分,因此比較時應報告使用了哪種注意力規則以及測量了哪些成本。更快的執行速度或更低的記憶體使用應與任務品質和相關序列長度一起評估。模型可以在改變其佈局或實現的同時保留注意力;識別這種區別有助於解釋優化實際改善了什麼。
付諸實踐
為什麼這很重要
- 速度與規模. 語言工作流程可以在不犧牲一致性的情況下更快地移動。
- 交通與覆蓋範圍. 它擴展了跨語言和溝通方式的訪問。
- 更明確的決策. 團隊可以花更多時間進行判斷,而自動化則可以處理重複。
留意
- 幻覺的事實可以悄悄地進入報告、支持流程或研究成果。
- 及時的敏感性可能會在類似的請求中產生不一致的結果。
- 如果存取控制薄弱,敏感文字資料可能會暴露。
後續步驟
- 在推出之前定義輸出格式、語氣和品質標準。
- 當準確性很重要時,請使用可信任來源進行地面回應。
- 為高風險輸出保留人工審查檢查點。
- 追蹤故障模式並定期重新訓練提示或工作流程。
不斷探索
常見問題
什麼是注意力機制?
注意力機制利用學習到的分數和權重,從允許的 token 位置組合資訊。這是 Transformer 的核心操作,而注意力遮罩和模型架構決定了哪些位置可以貢獻於每個表示。
token 注意力在形成輸出表示時結合了什麼?
注意力使用加權值,允許的上下文由遮罩和架構決定。
2017 年哪一篇具有里程碑意義的論文介紹了 Transformer 架構?
「Attention Is All You Need」(Vaswani 等人,2017)提出了 Transformer,它依賴注意力而不是遞歸。
為每個注意力標記計算的三個向量是什麼?
每個令牌都會產生一個查詢、一個鍵和一個值;查詢與鍵進行匹配以對值進行加權。
公式softmax(QK^T / √d_k) V中,為什麼要除以√d_k?
以關鍵維度的平方根進行縮放可以防止大點積將 softmax 推入微小梯度,從而保持訓練穩定。
為什麼密集的自我注意力機制會隨著極長的 token 序列而產生不斷增長的兩兩運算工作?
稠密注意力涉及 token 之間的成對互動。遮罩限制允許的位置,但全量或因果稠密注意力仍具有二次方的互動增長;遮罩改變的是允許的配對,而非移除該階別的增長。