Colab으로 하루에 하나씩 딥러닝

자연어 전처리_2.전처리_2) 불용어 제거 본문

딥러닝_개념

자연어 전처리_2.전처리_2) 불용어 제거

Elleik 2022. 12. 9. 22:31
728x90

불용어

  • 문장 내에서 빈번하게 발생하여 의미를 부여하기 어려운 단어 
  • 자연어 처리에 있어 효율성을 감소시키며, 처리 시간을 길게하기 때문에 반드시 제거해야 함
  • ex) 'a/an', 'the', 'of',  ...

### 불용어 제거

import nltk
from nltk.corpus import stopwords
nltk.download('stopwords')
nltk.download('punkt')
from nltk.tokenize import word_tokenize

sample_text = """One of the first things that we ask ourselves is 
              what are the pros and cons of any task wwe perform."""
text_tokens = word_tokenize(sample_text)

tokens_without_sw = [word for word in text_tokens if not word in stopwords.words('english')]

print('불용어 제거 미적용:', text_tokens, '\n')
print('불용어 제거 적용:', tokens_without_sw)

불용어 제거 미적용 / 적용 결과

출처: 서지영, 『딥러닝 텐서플로 교과서』, 길벗(2022)