불용어와 문장부호 처리

Python으로 배우는 Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

불용어

  • 자주 등장하지만 맥락 이해에는 기여가 적음
  • 많은 NLP 작업에서 가치가 크지 않음
  • 제거하면 모델이 핵심 단어에 집중함

a, an, the, in, of, that, for, by 등 여러 불용어를 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

불용어 제거

유용한 경우

텍스트의 주제 파악

모바일 앱의 제품 리뷰를 보여주는 이미지

Python으로 배우는 Natural Language Processing (NLP)

불용어 제거

유용한 경우

텍스트의 주제 파악

모바일 앱의 제품 리뷰를 보여주는 이미지

유용하지 않은 경우

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

텍스트가 영어(Good morning)에서 프랑스어(Bonjour)로 번역되는 이미지를 보여줌.

Python으로 배우는 Natural Language Processing (NLP)

불용어 접근

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

불용어 제거

from nltk.tokenize import word_tokenize

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

문장부호

  • 사람을 위한 언어 구조화 요소
  • 많은 NLP 작업에서 의미 정보가 적음

문장부호와 특수문자를 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

문장부호 제거

유용한 경우

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

처리해야 할 여러 파일과 문서를 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

문장부호 제거

유용한 경우

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

처리해야 할 여러 파일과 문서를 보여주는 이미지.

유용하지 않은 경우

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

여러 책 더미와 그로부터 생성된 요약 문서를 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

문장부호 접근 및 제거

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)

연습해 봅시다!

Python으로 배우는 Natural Language Processing (NLP)

Preparing Video For Download...