Natural Language Processing (NLP) bằng Python
Fouad Trad
Machine Learning Engineer

Nắm bắt chủ đề của văn bản

Nắm bắt chủ đề của văn bản

Các tác vụ cần mọi từ trong văn bản

NLTK cung cấp danh sách stop words cho nhiều ngôn ngữ
from nltk.corpus import stopwords nltk.download('stopwords')stop_words = stopwords.words('english')print(stop_words[:10])
['a', 'about', 'above', 'after', 'again', 'against', 'ain', 'all', 'am', 'an']
from nltk.tokenize import word_tokenizetext = "This is an example to demonstrate removing stop words."tokens = word_tokenize(text)# The .lower() method helps with case sensitivity filtered_tokens = [word for word in tokens if word.lower() not in stop_words]print(filtered_tokens)
['example', 'demonstrate', 'removing', 'stop', 'words', '.']

Các tác vụ cần tìm từ chung hoặc từ quan trọng trong tài liệu

Các tác vụ cần tìm từ chung hoặc từ quan trọng trong tài liệu

Các tác vụ cần giữ cấu trúc câu để rõ ràng

import string
print(string.punctuation)
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
text = "This is an example to demonstrate removing stop words." tokens = word_tokenize(text) filtered_tokens = [word for word in tokens if word.lower() not in stop_words]clean_tokens = [word for word in filtered_tokens if word not in string.punctuation]print(clean_tokens)
['example', 'demonstrate', 'removing', 'stop', 'words']
Natural Language Processing (NLP) bằng Python