ความถี่ของคำและความถี่ผกผันของเอกสาร
สององค์ประกอบของคะแนน
ความถี่ของคำและความถี่ผกผันของเอกสาร เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Two Halves of One Score
TF-IDF is built from two pieces that multiply together: term frequency and inverse document frequency. Each half fixes a different weakness of raw counts.
Term Frequency, Plainly
Term frequency measures how often a word appears inside one document. More mentions of a word suggest that document leans toward that topic.
Normalizing TF
We often divide a word's count by the document length. This normalization stops long documents from looking important just because they have more words.
count = 3
doc_length = 50
tf = count / doc_length
print(round(tf, 3))TF Alone Isn't Enough
By itself, term frequency still rewards filler words that appear a lot. We need a second factor to punish words that show up everywhere.
Document Frequency
Document frequency counts how many documents contain a word at all. A high document frequency means the word is common across your whole collection.
Flip It: Inverse
We want rare words to score high, so we invert that count. Inverse document frequency rises when a word appears in few documents and falls when it is everywhere.
The Log Tames It
IDF uses a logarithm so the values do not explode for very rare words. The log keeps the scale smooth and comparable across terms.
import math
total_docs = 1000
docs_with_word = 10
idf = math.log(total_docs / docs_with_word)
print(round(idf, 3))Multiply Them Together
The final score is simply TF times IDF. A word wins only if it is frequent here and rare elsewhere, which is exactly the combination we wanted.
tf = 0.06
idf = 4.6
tfidf = tf * idf
print(round(tfidf, 3))What Scores High
A topic word like neuroscience in one article gets a high score. A word like the gets crushed because its IDF is nearly zero.
What Scores Low
Words appearing in almost every document earn tiny weights. TF-IDF automatically demotes this background noise without any manual stopword list.
Why It Works So Well
TF-IDF balances local importance against global rarity in one clean formula. That balance is why this weighting stayed a search and text staple for decades. ⭐
Quick Check
What does the inverse document frequency part actually reward?
Recap
TF measures local frequency, IDF rewards global rarity, and their product is TF-IDF. Together they spotlight words that truly define a document. ✅
คำถามที่พบบ่อย
บทเรียน “ความถี่ของคำและความถี่ผกผันของเอกสาร” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ความถี่ของคำและความถี่ผกผันของเอกสาร” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ปัญหาของการนับแบบดิบ
- ความถี่ของคำและความถี่ผกผันของเอกสาร
- TF-IDF ด้วย scikit-learn
- ค้นหาคำที่สำคัญที่สุด