Python으로 배우는 Natural Language Processing (NLP)
Fouad Trad
Machine Learning Engineer

텍스트의 주제 파악

텍스트의 주제 파악

텍스트의 모든 단어가 필요한 작업

NLTK는 여러 언어의 불용어 목록을 제공합니다
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', '.']

문서에서 공통/중요 단어를 찾는 작업

문서에서 공통/중요 단어를 찾는 작업

문장 구조를 유지해 명확성이 필요한 작업

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']
Python으로 배우는 Natural Language Processing (NLP)