単語頻度と逆文書頻度
スコアを構成する 2 つの要素
「単語頻度と逆文書頻度」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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. ✅
よくある質問
「単語頻度と逆文書頻度」レッスンは無料ですか?
はい。「単語頻度と逆文書頻度」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。
「単語頻度と逆文書頻度」で何を学びますか?
スコアを構成する 2 つの要素 ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
NLP Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「単語頻度と逆文書頻度」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNLP Academyレッスンでコードを書いて実行できますか?
はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。