0Pricing
NLP Academy · Lección

Construcción de un vocabulario

Asignar cada palabra a un índice fijo

Construcción de un vocabulario 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.

What Is a Vocabulary?

A vocabulary is the full set of unique words your model knows. Each word gets one fixed slot in every document vector. 📖

Collect Every Unique Word

To build it, gather all words across your documents and keep only the distinct ones, dropping repeats.

words = set("the cat sat the mat".split())

Give Each Word an Index

Sort the unique words and assign each a number. This word to index map is your vocabulary lookup.

vocab = {w: i for i, w in enumerate(sorted(words))}

The Index Defines the Slot

The index tells a word which position it occupies in every vector, so cat always lands in the same column.

Vocabulary Sets Vector Length

If your vocabulary has 5000 words, every document becomes a vector of 5000 numbers, one slot per word.

Order Must Stay Fixed

Once set, the mapping must never change. A stable order guarantees that column 3 means the same word for every document.

Out-of-Vocabulary Words

A word not in your vocabulary is called out of vocabulary. The simplest choice is to ignore it during counting.

Pruning Rare Words

Words that appear once add noise and size. Dropping very rare terms keeps the vocabulary smaller and cleaner.

Dropping Very Common Words

You can also cut words that appear in nearly every document. These stopwords rarely help tell documents apart.

Look Up an Index

With the map built, finding a word position is instant. Just index the dictionary by the word you want.

print(vocab["cat"])  # the column index for cat

Vocabulary Powers Counting

This map is the backbone of vectorization. Next you fill each slot with how often that word appears in a document.

Quick Check

What does a word index represent?

Recap: Your Vocabulary

You built a vocabulary of unique words, mapped each to a fixed index, and saw how pruning keeps it lean and useful. 🎉

Preguntas frecuentes

¿La lección «Construcción de un vocabulario» es gratis?

Sí — el texto completo de «Construcción de un vocabulario» 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 «Construcción de un vocabulario»?

Asignar cada palabra a un índice fijo 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 «Construcción de un vocabulario»?

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

  1. Por qué los modelos necesitan números, no palabras
  2. Construcción de un vocabulario
  3. Conteo con CountVectorizer
  4. Lectura de la matriz documento-término
← Volver a NLP Academy