Usuwanie interpunkcji i symboli
Usuń znaki, które dezorientują modele
Usuwanie interpunkcji i symboli to bezpłatna lekcja NLP Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej NLP Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs NLP Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Usuwanie interpunkcji i symboli” jest bezpłatna?
Tak — pełny tekst „Usuwanie interpunkcji i symboli” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu NLP Academy, przejdź na CoddyKit PRO. Kurs NLP Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Usuwanie interpunkcji i symboli”?
Usuń znaki, które dezorientują modele Ćwiczysz NLP Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć NLP Academy?
Nie wymagamy żadnego doświadczenia. NLP Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Usuwanie interpunkcji i symboli”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji NLP Academy?
Tak. Każda lekcja NLP Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Czym są stopwords?
- Filtrowanie stopwords za pomocą NLTK
- Usuwanie interpunkcji i symboli
- Tworzenie wielokrotnego użytku funkcji czyszczenia tekstu