> For the complete documentation index, see [llms.txt](https://www.nhasachso.io.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.nhasachso.io.vn/truc-tuyen/interactive-blocks-1/tac-gia/nguyen-hong-phuong/sach-cong-cu-ai-python/phan-4-xu-ly-ngon-ngu-tu-nhien-nlp/natural-language-toolkit-nltk-thu-vien-co-ban-de-tien-xu-ly-ngon-ngu-tu-nhien.md).

# Natural Language Toolkit (NLTK): Thư viện cơ bản để tiền xử lý ngôn ngữ tự nhiên

#### **NLTK (Natural Language Toolkit)**

**Mục tiêu:** Là một **thư viện Python nền tảng** dùng trong xử lý ngôn ngữ tự nhiên (**NLP**), rất hữu ích cho việc **nghiên cứu, giảng dạy và tiền xử lý văn bản**.

**📌 Đặc điểm nổi bật:**

* Cung cấp nhiều công cụ cơ bản: **tách từ (tokenization)**, **gán từ loại (POS tagging)**, **gốc từ (stemming)**, **rút gọn từ (lemmatization)**,...
* Tích hợp **corpus mẫu** và tập luật hỗ trợ học NLP.
* Hữu ích trong việc làm sạch và chuẩn hóa văn bản trước khi đưa vào mô hình học máy.
* Dễ học, phù hợp cho người mới bắt đầu nghiên cứu NLP.

**🧠 Ứng dụng:**

* Phân tích cú pháp và cấu trúc ngữ pháp câu.
* Phân loại văn bản, trích xuất thông tin từ dữ liệu phi cấu trúc.
* Tiền xử lý dữ liệu cho các mô hình NLP nâng cao.

**Ví dụ tiền xử lý văn bản với NLTK:**

```python
import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer

# Tải dữ liệu cần thiết
nltk.download('punkt')
nltk.download('stopwords')

# Văn bản mẫu
text = "Natural Language Processing with Python is powerful and fun."

# Tiền xử lý
tokens = word_tokenize(text.lower())
stop_words = set(stopwords.words('english'))
filtered_tokens = [w for w in tokens if w.isalpha() and w not in stop_words]

stemmer = PorterStemmer()
stemmed = [stemmer.stem(word) for word in filtered_tokens]

print(stemmed)
```

***
