nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้
ตารางค้นหาที่ฝึกด้วยการไล่ระดับลง
nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้ เป็นบทเรียน Deep Learning Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Deep Learning Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Ids Alone Are Not Enough
Token ids are just labels. The id 5 is not greater than 2 in any meaningful way, so feeding raw ids to a net misleads it.
One-Hot Is Wasteful
One way to represent ids is a giant one-hot vector, but with thousands of words it is huge, sparse, and carries no similarity.
Enter the Embedding
An embedding maps each id to a short dense vector of floats. These few numbers can encode rich meaning about the word.
It Is a Lookup Table
Think of nn.Embedding as a lookup table: row i holds the vector for token id i. Indexing the table fetches that row.
import torch.nn as nn
emb = nn.Embedding(num_embeddings=1000, embedding_dim=16)Two Key Arguments
You set num_embeddings to your vocab size and embedding_dim to how many numbers each word vector holds.
Look Up a Word
Pass a tensor of ids and the layer returns their vectors. A batch of ids becomes a batch of dense vectors instantly.
ids = torch.tensor([1, 5, 2])
vecs = emb(ids) # shape (3, 16)Output Shape Grows a Dim
The embedding adds an extra dimension. An input of shape (batch, length) becomes (batch, length, embedding_dim).
The Vectors Start Random
At first the embedding rows are random. They hold no meaning yet, just noise waiting to be shaped by training.
They Are Trainable
Embedding weights are parameters. Gradient descent nudges each word vector during training, so the table learns over time.
Choosing the Dimension
A larger embedding_dim can capture more nuance but costs memory. Small tasks use 16 to 100; large language models use far more.
Plug It Into a Model
The embedding is usually the first layer. It converts ids to vectors, then later layers process those vectors as usual.
Quick Check
How does nn.Embedding turn a token id into a vector?
Recap
nn.Embedding is a trainable lookup table mapping ids to dense vectors. It starts random and learns meaning through training. ✅
คำถามที่พบบ่อย
บทเรียน “nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Deep Learning Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้”
ตารางค้นหาที่ฝึกด้วยการไล่ระดับลง คุณปฏิบัติ Deep Learning Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Deep Learning Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Deep Learning Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Deep Learning Academy นี้ได้ไหม
ได้ บทเรียน Deep Learning Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- แบ่งโทเค็นและสร้างคลังคำศัพท์
- nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้
- เหตุใดเอ็มเบดดิงจึงเก็บความหมายได้
- ฝึกตัวจำแนกข้อความ