Self-Attention ทีละขั้น
คิวรี คีย์ และค่า
Self-Attention ทีละขั้น เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What Is Self-Attention?
In self-attention, every word looks at every other word in the same sentence to build a richer, context-aware version of itself. 🔍
Three Roles per Word
Each word is projected into three vectors: a query, a key, and a value. These three roles drive the whole self-attention computation.
The Query
The query represents what a word is looking for. Think of it as the question this word asks about the rest of the sentence.
Keys and Values
Each word also offers a key that advertises what it contains, and a value holding the actual information to pass along if chosen.
Scoring With Dot Products
Compare a query to every key using a dot product. A larger product means the query and key align, so that word deserves more focus.
scores = query @ keys.TScale the Scores
Divide scores by the square root of the key dimension. This scaling keeps numbers stable so softmax does not become too sharp.
scores = scores / (d_k ** 0.5)Softmax for Weights
Run the scaled scores through softmax to get attention weights that are positive and sum to 1 across all words in the sentence.
weights = softmax(scores)Blend the Values
Multiply each value by its weight and add them up. The result is a new vector that blends information from the most relevant words.
output = weights @ valuesThe Full Formula
All steps combine into one tidy expression: scaled dot-product attention over queries, keys, and values, as introduced in the Transformer paper.
attn = softmax(Q @ K.T / d_k**0.5) @ VWhy Self, Not Cross
It is called self-attention because the queries, keys, and values all come from the same sequence, letting words attend to their own neighbors.
Resolving Ambiguity
In "it was tired," self-attention links it to the right noun by weighting nearby words, giving every token clearer context.
Quick Check
Let us confirm the self-attention steps.
Recap
You walked through self-attention: turn words into queries, keys, and values, score, scale, softmax, then blend the values. That is the engine. ⚙️
คำถามที่พบบ่อย
บทเรียน “Self-Attention ทีละขั้น” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “Self-Attention ทีละขั้น” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “Self-Attention ทีละขั้น”
คิวรี คีย์ และค่า คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “Self-Attention ทีละขั้น” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- แนวคิดของแอตเทนชัน
- Self-Attention ทีละขั้น
- แอตเทนชันหลายหัวและตำแหน่ง
- ภายในบล็อก Transformer