fbpx Removing stop words là gì? Tại sao cần loại stop words? Skip to main content
stop words

Removing stop words là gì? Tại sao cần loại stop words?

🔡 Removing stop words là gì?

Removing stop words là quá trình loại bỏ các từ dừng (stop words) khỏi văn bản trong quá trình xử lý ngôn ngữ tự nhiên (NLP).


🧠 Stop words là gì?

Stop words là những từ:

  • Xuất hiện rất thường xuyên trong ngôn ngữ

  • Không mang nhiều ý nghĩa nội dung khi phân tích (thường là từ ngữ pháp hơn là ngữ nghĩa)

📌 Ví dụ

Tiếng Anh Tiếng Việt
the, is, and, in, to, it, on, at, a, an , của, , một, này, trong, đó, , được, bằng

Tại sao cần loại stop words?

Lý do Giải thích
🔽 Giảm độ nhiễu (noise) Những từ này không giúp ích cho mô hình học
🔍 Tăng độ chính xác Giữ lại những từ mang nội dung chính (danh từ, động từ,...)
⚡ Tăng tốc xử lý Giảm số lượng từ cần vector hóa hoặc phân tích

⚠️ Khi nào KHÔNG nên loại stop words?

  • Khi cần phân tích ngữ pháp hoặc ngữ nghĩa đầy đủ

  • Với mô hình như transformers (BERT, GPT), thường không cần loại stop words

  • Khi stop word có ý nghĩa quan trọng, ví dụ:

    "I am not happy" → nếu loại not → mất nghĩa phủ định


🐍 Cách loại stop words trong Python

✅ 1. Dùng nltk

import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

nltk.download("stopwords")
nltk.download("punkt")

text = "This is an example showing off stop word filtration."
words = word_tokenize(text)

filtered = [w for w in words if w.lower() not in stopwords.words("english")]
print(filtered)
# ➜ ['example', 'showing', 'stop', 'word', 'filtration', '.']

✅ 2. Dùng spaCy

import spacy
nlp = spacy.load("en_core_web_sm")

doc = nlp("This is an example showing off stop word removal.")
filtered = [token.text for token in doc if not token.is_stop]
print(filtered)
# ➜ ['example', 'showing', 'stop', 'word', 'removal', '.']

✍️ Tùy chỉnh stop words

Bạn có thể thêm / xóa stop words tùy ý:

from nltk.corpus import stopwords
custom_stopwords = set(stopwords.words('english'))
custom_stopwords.add("also")  # thêm từ mới

✅ Tổng kết

Thuật ngữ Giải thích
Stop word Từ thường xuyên, ít giá trị phân tích
Removing stop words Loại bỏ từ dừng khỏi văn bản
Dùng khi Phân loại văn bản, trích ý chính, vector hóa
Không dùng khi Phân tích cú pháp, cảm xúc, hoặc cần giữ đầy đủ ngữ cảnh

 

About

Công ty thiết kế web app chuyên thiết kế web và các dịch vụ maketing digital, seo, google adword...