0Pricing
NLP Academy · Lezione

Rimuovere punteggiatura e simboli

Eliminare i caratteri che confondono i modelli

Rimuovere punteggiatura e simboli è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 3 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.

Punctuation Is Noise Too

After stopwords, the next clutter is symbols. Commas, dollar signs, and emoji can confuse a model, so we often strip punctuation away.

Why It Matters

Without cleanup, your model sees cat, and cat as two different tokens. That trailing comma splits one word into two features.

Python Knows the Marks

The string module hands you every common mark in one constant called punctuation, so you never type them out by hand.

import string
print(string.punctuation)

The translate Trick

The fastest way to delete characters is str.translate with a table that maps each mark to nothing at all.

table = str.maketrans("", "", string.punctuation)
clean = "hello, world!".translate(table)
print(clean)

Per-Token Cleaning

You can also strip marks token by token. Apply translate inside a comprehension, then drop any token that became empty.

clean = [t.translate(table) for t in tokens]
clean = [t for t in clean if t]

Regex for Symbols

Need more control than the fixed list? A regex can wipe anything that is not a letter, number, or space.

import re
clean = re.sub(r"[^a-zA-Z0-9 ]", "", text)

Beware of Useful Marks

Some symbols carry meaning. Stripping every dot turns u.s.a into usa, and that may not be what you want for your task.

Numbers Are a Choice

Digits are not punctuation, but they are often noise. Decide on purpose whether to keep or drop numbers for your data.

no_digits = re.sub(r"\d+", "", text)

Watch Unicode Symbols

The ASCII punctuation set misses curly quotes and emoji. A Unicode-aware regex catches the symbols a fixed list leaves behind.

clean = re.sub(r"[^\w\s]", "", text)

Collapse Extra Spaces

Removing marks can leave gaps and double spaces. A quick whitespace squeeze tidies the result back into clean words.

clean = re.sub(r"\s+", " ", clean).strip()

Order of Operations

Sequence matters. Strip punctuation before you split or compare, so trailing marks never sneak into your final tokens.

Quick Check

Pick the cleanest way to delete punctuation from a string.

Recap

You can now strip punctuation with translate or regex, handle Unicode and numbers on purpose, and squeeze leftover spaces for clean tokens.

Domande Frequenti

La lezione «Rimuovere punteggiatura e simboli» è gratuita?

Sì — il testo completo di «Rimuovere punteggiatura e simboli» è 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 «Rimuovere punteggiatura e simboli»?

Eliminare i caratteri che confondono i modelli 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 3 di 4.

Quanto tempo richiede la lezione «Rimuovere punteggiatura e simboli»?

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. Che cosa sono le stopword?
  2. Filtrare le stopword con NLTK
  3. Rimuovere punteggiatura e simboli
  4. Creare una funzione riutilizzabile per pulire il testo
← Torna a NLP Academy