แอตเทนชันหลายหัวและตำแหน่ง
มุมมองหลากหลายพร้อมการรับรู้ลำดับ
แอตเทนชันหลายหัวและตำแหน่ง เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
One Head Is Limiting
A single attention head can track only one kind of relationship at a time. Real language needs many patterns noticed at once. 🧠
Many Heads, Many Views
Multi-head attention runs several attention computations in parallel, each with its own learned projections and its own focus.
What Each Head Learns
One head might track subject-verb links while another follows pronouns. Together they capture a far richer picture of the sentence.
Split the Dimensions
The model splits its vector size across heads, so each head works in a smaller subspace. The total compute stays roughly the same.
d_head = d_model // num_headsCombine the Heads
After each head produces an output, you concatenate them and pass the result through one more linear layer to mix the views.
out = concat(head_1, head_2, ...) @ W_oAttention Ignores Order
Self-attention treats input as a set, so by itself it cannot tell "dog bites man" from "man bites dog." It is order-blind.
Adding Position Information
To fix this, we inject a positional encoding into each word so the model knows where every token sits in the sequence.
Sinusoidal Encodings
The original Transformer uses fixed sine and cosine waves of different frequencies to give each position a unique, smooth signature.
pe[pos, 2i] = sin(pos / 10000 ** (2*i/d))Added, Not Appended
Position vectors are added to the word embeddings, not stuck on the end. So each token carries both meaning and place together.
x = token_embeddings + positional_encodingLearned Positions Too
Many modern models replace fixed waves with learned position embeddings, trained alongside everything else for flexibility.
Why Both Matter
Multi-head attention sees many relationships; positional encodings restore order. Together they let the Transformer truly understand sequences. ✨
Quick Check
Let us test positions and heads.
Recap
You saw how multi-head attention captures many relationships in parallel, while positional encodings give the model a sense of order. 🎯
คำถามที่พบบ่อย
บทเรียน “แอตเทนชันหลายหัวและตำแหน่ง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “แอตเทนชันหลายหัวและตำแหน่ง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “แอตเทนชันหลายหัวและตำแหน่ง”
มุมมองหลากหลายพร้อมการรับรู้ลำดับ คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “แอตเทนชันหลายหัวและตำแหน่ง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- แนวคิดของแอตเทนชัน
- Self-Attention ทีละขั้น
- แอตเทนชันหลายหัวและตำแหน่ง
- ภายในบล็อก Transformer