0Pricing
NLP Academy · Lezione

Bigrams e trigrams spiegati

Finestre scorrevoli sui token

Bigrams e trigrams spiegati è 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.

Naming the N-Grams

The n in n-gram is just a number. Pick n and you decide how many neighboring words each feature bundles together.

Meet the Bigram

A bigram is an n-gram of size two, every adjacent pair of words. It is the most common upgrade over plain single words. 👍

Bigrams in Action

From four words you get three overlapping pairs. Notice how each bigram shares one word with the next one.

words = "i love clean code".split()
bigrams = list(zip(words, words[1:]))
print(bigrams)

Meet the Trigram

A trigram takes three words at a time. It captures even more context, like is not good as one unit.

words = "this is not good".split()
trigrams = list(zip(words, words[1:], words[2:]))
print(trigrams)

How Many Do You Get?

For a sentence of N words, you get N minus n plus one n-grams. So 4 words give 3 bigrams and 2 trigrams.

The Window Slides

Each n-gram comes from a small window moving one word forward. Overlap is the point, since shared words stitch context together.

A Reusable Helper

You can build any n-gram with one tidy function using zip. Change the value of n and the same code handles bigrams or trigrams.

def ngrams(words, n):
    return list(zip(*[words[i:] for i in range(n)]))

Bigger N, More Context

Higher values of n hold longer phrases, so they capture context more precisely. That power comes with a cost you will meet soon.

Bigger N, Rarer Grams

The longer the run, the less often that exact sequence repeats. Large n-grams become rare, appearing in few documents.

Why Bigrams Are Popular

Bigrams hit a sweet spot: enough context to catch not bad, common enough to repeat across texts. That balance makes them a reliable default.

Mixing Sizes

You rarely use one size alone. Most pipelines combine unigrams and bigrams so the model sees both single words and their key pairs.

Quick Check

How many bigrams come from the sentence text is just data, which has four words?

Recap: Bigrams and Trigrams

A bigram joins two words, a trigram joins three. Bigger n holds more context but appears less often. Next you will let scikit-learn build them. ⚙️

Domande Frequenti

La lezione «Bigrams e trigrams spiegati» è gratuita?

Sì — il testo completo di «Bigrams e trigrams spiegati» è 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 «Bigrams e trigrams spiegati»?

Finestre scorrevoli sui token 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 «Bigrams e trigrams spiegati»?

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. Perché le singole parole perdono significato
  2. Bigrams e trigrams spiegati
  3. Feature N-gram in scikit-learn
  4. Scegliere l'intervallo N-gram corretto
← Torna a NLP Academy