Pythonで学ぶ自然言語処理(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で学ぶ自然言語処理(NLP)