n-그램으로 더 세밀하게

Python으로 배우는 Sentiment Analysis

Violeta Misheva

Data Scientist

문맥은 중요합니다

I am happy, not sad.

I am sad, not happy.

  • 단어 앞의 'not'(부정)은 문맥의 중요성을 보여주는 예입니다.
Python으로 배우는 Sentiment Analysis

BOW로 문맥 포착

  • 유니그램: 단일 토큰

  • 바이그램: 토큰의 쌍

  • 트라이그램: 토큰의 세 개 묶음

  • n-그램: n개의 토큰 시퀀스

Python으로 배우는 Sentiment Analysis

BOW로 문맥 포착

The weather today is wonderful.

  • 유니그램: { The, weather, today, is, wonderful }

  • 바이그램: {The weather, weather today, today is, is wonderful}

  • 트라이그램: {The weather today, weather today is, today is wonderful}

Python으로 배우는 Sentiment Analysis

CountVectorizer로 n-그램 사용

from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(ngram_range=(min_n, max_n))
# Only unigrams
ngram_range=(1, 1)
# Uni- and bigrams
ngram_range=(1, 2)
Python으로 배우는 Sentiment Analysis

최적의 n은?

더 긴 토큰 시퀀스
  • 특징 수 증가
  • 모델 정밀도 향상
  • 과적합 위험
Python으로 배우는 Sentiment Analysis

어휘 크기 지정

CountVectorizer(max_features, max_df, min_df)
  • max_features: 지정 시, 어휘에서 가장 빈도가 높은 단어만 포함합니다
    • max_features = None이면 모든 단어를 포함합니다
  • max_df: 지정 값보다 높은 빈도의 용어를 무시합니다
    • 정수면 절대 건수, 실수면 비율입니다
    • 기본값은 1.0으로, 어떤 용어도 무시하지 않습니다
  • min_df: 지정 값보다 낮은 빈도의 용어를 무시합니다
    • 정수면 절대 건수, 실수면 비율입니다
    • 기본값은 1.0으로, 어떤 용어도 무시하지 않습니다
Python으로 배우는 Sentiment Analysis

연습해 봅시다!

Python으로 배우는 Sentiment Analysis

Preparing Video For Download...