0Pricing
NLP Academy · Lezione

Frequenza dei termini e frequenza inversa dei documenti

Le due componenti del punteggio

Frequenza dei termini e frequenza inversa dei documenti è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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. ✅

Domande Frequenti

La lezione «Frequenza dei termini e frequenza inversa dei documenti» è gratuita?

Sì — il testo completo di «Frequenza dei termini e frequenza inversa dei documenti» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.

Cosa imparerò in «Frequenza dei termini e frequenza inversa dei documenti»?

Le due componenti del punteggio Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare NLP Academy?

Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Frequenza dei termini e frequenza inversa dei documenti»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione NLP Academy?

Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Il problema dei conteggi grezzi
  2. Frequenza dei termini e frequenza inversa dei documenti
  3. TF-IDF con scikit-learn
  4. Trovare le parole più importanti
← Torna a NLP Academy