สร้างคลังคำศัพท์
จับคู่ทุกคำกับดัชนีคงที่
สร้างคลังคำศัพท์ เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What Is a Vocabulary?
A vocabulary is the full set of unique words your model knows. Each word gets one fixed slot in every document vector. 📖
Collect Every Unique Word
To build it, gather all words across your documents and keep only the distinct ones, dropping repeats.
words = set("the cat sat the mat".split())Give Each Word an Index
Sort the unique words and assign each a number. This word to index map is your vocabulary lookup.
vocab = {w: i for i, w in enumerate(sorted(words))}The Index Defines the Slot
The index tells a word which position it occupies in every vector, so cat always lands in the same column.
Vocabulary Sets Vector Length
If your vocabulary has 5000 words, every document becomes a vector of 5000 numbers, one slot per word.
Order Must Stay Fixed
Once set, the mapping must never change. A stable order guarantees that column 3 means the same word for every document.
Out-of-Vocabulary Words
A word not in your vocabulary is called out of vocabulary. The simplest choice is to ignore it during counting.
Pruning Rare Words
Words that appear once add noise and size. Dropping very rare terms keeps the vocabulary smaller and cleaner.
Dropping Very Common Words
You can also cut words that appear in nearly every document. These stopwords rarely help tell documents apart.
Look Up an Index
With the map built, finding a word position is instant. Just index the dictionary by the word you want.
print(vocab["cat"]) # the column index for catVocabulary Powers Counting
This map is the backbone of vectorization. Next you fill each slot with how often that word appears in a document.
Quick Check
What does a word index represent?
Recap: Your Vocabulary
You built a vocabulary of unique words, mapped each to a fixed index, and saw how pruning keeps it lean and useful. 🎉
คำถามที่พบบ่อย
บทเรียน “สร้างคลังคำศัพท์” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “สร้างคลังคำศัพท์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “สร้างคลังคำศัพท์”
จับคู่ทุกคำกับดัชนีคงที่ คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “สร้างคลังคำศัพท์” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ