Фильтрация стоп-слов с помощью NLTK
Удалите шум из списка токенов
«Фильтрация стоп-слов с помощью NLTK» — бесплатный урок NLP Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения NLP Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс NLP Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
Let NLTK Do the Heavy Lifting
Building your own stopword list is fine, but NLTK already ships a curated one for many languages. Let us put it to work on a token list.
Grab the Data First
NLTK keeps word lists as downloadable data. You fetch the stopwords package once, then it stays on your machine.
import nltk
nltk.download("stopwords")Load the English List
Now import the corpus and ask for English. You get back a plain list of words you can inspect or filter against.
from nltk.corpus import stopwords
stops = stopwords.words("english")
print(len(stops))Convert It to a Set
The list works, but a set makes membership checks much faster. Wrap it once and reuse it for every token.
stops = set(stopwords.words("english"))Filter With a Comprehension
A list comprehension keeps only the words that are not stopwords. This single line is the heart of stopword removal.
tokens = ["the", "quick", "brown", "fox"]
clean = [w for w in tokens if w not in stops]
print(clean)Mind the Case
The list is lowercase, so The will not match the. Lowercase your tokens first, or you will leave capitalized stopwords behind.
clean = [w for w in tokens if w.lower() not in stops]See the Difference
Before filtering you might have ten tokens; after, only the meaningful four remain. That shrink is the noise you just dropped.
Other Languages Too
NLTK is not English-only. Swap the argument to pull a stopword list for Spanish, German, French, and many more.
spanish = set(stopwords.words("spanish"))Customize the List
The list is just a set, so you can add your own domain noise to it with normal set operations before filtering.
stops.add("subject")
stops.update(["http", "www"])Or Keep a Few Back
Want to protect a word like not? Just remove it from the set so filtering never strips it out.
stops.discard("not")Filter Once, Reuse Often
Build your stops set a single time at startup, not inside a loop. Rebuilding it for every document wastes real time.
Quick Check
One detail trips up almost everyone the first time.
Recap
You can now filter tokens against NLTK stopwords: download once, build a lowercase set, and keep only words not in it. Mind the case.
Часто задаваемые вопросы
Урок «Фильтрация стоп-слов с помощью NLTK» бесплатный?
Да — полный текст урока «Фильтрация стоп-слов с помощью NLTK» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс NLP Academy, подпишись на CoddyKit PRO. Курс NLP Academy содержит 4 уроков всего.
Чему я научусь в уроке «Фильтрация стоп-слов с помощью NLTK»?
Удалите шум из списка токенов Ты практикуешь NLP Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать NLP Academy?
Предыдущий опыт не требуется. NLP Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «Фильтрация стоп-слов с помощью NLTK»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке NLP Academy?
Да. Каждый урок NLP Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Что такое стоп-слова
- Фильтрация стоп-слов с помощью NLTK
- Удаление пунктуации и символов
- Создание универсальной функции очистки текста