Filtrado de stopwords con NLTK
Eliminar el ruido de una lista de tokens
Filtrado de stopwords con NLTK es una lección gratuita de NLP Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de NLP Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de NLP Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Filtrado de stopwords con NLTK» es gratis?
Sí — el texto completo de «Filtrado de stopwords con NLTK» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de NLP Academy, actualiza a CoddyKit PRO. El curso de NLP Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Filtrado de stopwords con NLTK»?
Eliminar el ruido de una lista de tokens Practicas NLP Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar NLP Academy?
No se requiere experiencia previa. NLP Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Filtrado de stopwords con NLTK»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de NLP Academy?
Sí. Cada lección de NLP Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- ¿Qué son las stopwords?
- Filtrado de stopwords con NLTK
- Eliminación de puntuación y símbolos
- Construcción de una función reutilizable para limpiar texto