0Pricing
Deep Learning Academy · บทเรียน

ฝึกตัวจำแนกข้อความ

ฝังข้อมูล พูล และทำนายความรู้สึก

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

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

The Goal: Predict a Label

A text classifier reads a sentence and predicts a label, like positive or negative sentiment for a movie review. 🎬

Step One: Encode the Text

Reuse your pipeline: tokenize each review and map tokens to ids, turning every sentence into a list of integers.

Step Two: Embed the Ids

Feed those ids into an embedding layer. Each review becomes a sequence of dense word vectors the model can process.

self.emb = nn.Embedding(vocab_size, 32)

Step Three: Pool the Vectors

A sentence has many vectors but you need one. Pooling, often a mean over the words, collapses them into a single vector.

pooled = vecs.mean(dim=1)  # average over the sequence

Step Four: A Linear Head

Send the pooled vector through a linear layer to produce one score per class. These raw scores are called logits.

self.fc = nn.Linear(32, num_classes)

Assemble the Model

Stack embed, pool, and the linear head in a forward method. That is a complete, tiny text classifier.

def forward(self, ids):
    x = self.emb(ids).mean(dim=1)
    return self.fc(x)

Pick the Loss

For multiclass labels use cross-entropy loss. It expects raw logits and the integer class index as the target.

loss_fn = nn.CrossEntropyLoss()

Choose an Optimizer

An optimizer like Adam updates the embedding and linear weights together as it minimizes the loss.

opt = torch.optim.Adam(model.parameters(), lr=1e-3)

The Training Loop

For each batch: forward, compute loss, backward, and step. Repeat over the data for several epochs.

logits = model(ids)
loss = loss_fn(logits, labels)
loss.backward()
opt.step()

Make a Prediction

At inference, take the class with the highest logit using argmax to get the predicted label for new text.

pred = model(ids).argmax(dim=1)

Measure Accuracy

Compare predictions to true labels to compute accuracy. Watch it climb as the embedding learns sentiment patterns.

Quick Check

In this classifier, what turns a sequence of word vectors into one vector?

Recap

You embed ids, pool them into one vector, classify with a linear head, and train with cross-entropy to label text. ✅

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

บทเรียน “ฝึกตัวจำแนกข้อความ” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “ฝึกตัวจำแนกข้อความ”

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

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

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

บทเรียน “ฝึกตัวจำแนกข้อความ” ใช้เวลานานแค่ไหน

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

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

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

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

  1. แบ่งโทเค็นและสร้างคลังคำศัพท์
  2. nn.Embedding: เวกเตอร์คำที่เรียนรู้ได้
  3. เหตุใดเอ็มเบดดิงจึงเก็บความหมายได้
  4. ฝึกตัวจำแนกข้อความ
← กลับไปที่ Deep Learning Academy