0Pricing
AI Engineering Academy · บทเรียน

ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย

ทำความเข้าใจสถาปัตยกรรมทรานส์ฟอร์เมอร์โดยสำรวจว่ากลไกความสนใจช่วยให้โมเดลมุ่งเน้นบริบทที่เกี่ยวข้องได้อย่างไร โดยไม่จำเป็นต้องเข้าใจคณิตศาสตร์

ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย เป็นบทเรียน AI Engineering Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Engineering Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Engineering Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Core Problem: Long-Range Dependencies

In "the trophy didn't fit in the bag because it was too big," what is "it"? Old models lost track over long sentences. This is the long-range dependency problem.

Attention as Weighted Focus

Attention is how a model decides which words matter most for each word — like highlighting the key parts of a passage instead of treating every word the same.

Queries, Keys, and Values

Attention works like a search: each word sends a Query, matches it against every Key, and pulls in the most relevant Values. The code below shows the core idea.

# Simplified self-attention in pseudocode
import numpy as np

def scaled_dot_product_attention(Q, K, V):
    d_k = Q.shape[-1]  # dimension of keys
    scores = Q @ K.T / np.sqrt(d_k)  # scale to prevent vanishing gradients
    weights = np.exp(scores) / np.sum(np.exp(scores), axis=-1, keepdims=True)  # softmax
    output = weights @ V  # weighted sum of values
    return output

Multi-Head Attention: Multiple Perspectives

One attention head catches one kind of link. Multi-head attention runs many in parallel, so the model sees words through several lenses at once.

Positional Encodings: Adding Word Order

Attention alone ignores word order — "dog bites man" looks like "man bites dog." Positional encodings add a sense of position so order isn't lost.

Feed-Forward Layers After Attention

After attention shares context, a feed-forward network processes each word on its own. Interestingly, much of the model's factual knowledge seems to live here.

Encoder-Only vs Decoder-Only Models

BERT-style encoder-only models read all the text at once to understand it. GPT-style decoder-only models read left-to-right to generate it — which is what ChatGPT does.

Layer Stacking and Depth

Modern LLMs stack dozens of Transformer blocks. Each layer refines the last — early ones catch grammar, deeper ones handle reasoning. More depth, more thinking.

Residual Connections and Layer Normalization

Stacking many layers is tricky. Residual connections and layer normalization keep the signal stable, so deep models can train reliably at 100+ layers.

Why Attention Scales So Well

Attention is easy to run in parallel, so more GPUs mean faster training. That's how researchers trained on huge data and uncovered the famous scaling laws.

Flash Attention and Modern Optimizations

Long inputs make standard attention very memory-hungry. FlashAttention computes the same result far more efficiently, making big context windows practical.

Quick Check

Test your understanding of AI Engineering concepts from this lesson.

Lesson Recap

Recap: self-attention links every word to every other, multi-head attention captures many relationships at once, and residuals plus normalization let models go deep. Next: how LLMs are trained.

คำถามที่พบบ่อย

บทเรียน “ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Engineering Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Engineering Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย”

ทำความเข้าใจสถาปัตยกรรมทรานส์ฟอร์เมอร์โดยสำรวจว่ากลไกความสนใจช่วยให้โมเดลมุ่งเน้นบริบทที่เกี่ยวข้องได้อย่างไร โดยไม่จำเป็นต้องเข้าใจคณิตศาสตร์ คุณปฏิบัติ AI Engineering Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Engineering Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Engineering Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Engineering Academy นี้ได้ไหม

ได้ บทเรียน AI Engineering Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. จากการเติมข้อความอัตโนมัติสู่ ChatGPT
  2. ทรานส์ฟอร์เมอร์และกลไกความสนใจในภาษาที่เข้าใจง่าย
  3. การฝึก LLM
  4. ความสามารถและข้อจำกัดของ LLM
← กลับไปที่ AI Engineering Academy