단어 임베딩

R로 배우는 자연어 처리 입문

Kasey Jones

Research Data Scientist

단어 수의 한계

두 문장:

  • Bob is the smartest person I know.
  • Bob is the most brilliant person I know.

불용어 제거 후:

  • Bob smartest person
  • Bob brilliant person
R로 배우는 자연어 처리 입문

단어 의미

추가 데이터:

  • The smartest people ...
  • He was the smartest ...
  • Brilliant people ...
  • His was so brilliant ...
R로 배우는 자연어 처리 입문

word2vec

  • 단어를 고차원 벡터 공간으로 표현
  • 단어 간 여러 유사성 포착
  • 의미가 비슷한 단어일수록 공간에서 더 가까움

word2vec 표현에서는 유사한 단어가 다차원 벡터 공간에서 서로 더 가깝게 묶입니다.

1 https://www.adityathakker.com/introduction-to-word2vec-how-it-works/
R로 배우는 자연어 처리 입문

데이터 준비

library(h2o)
h2o.init()
h2o_object = as.h2o(animal_farm)

h2o로 토크나이즈:

words <- h2o.tokenize(h2o_object$text_column, "\\\\W+")
words <- h2o.tolower(words)
words = words[is.na(words) || (!words %in% stop_words$word),]
R로 배우는 자연어 처리 입문

word2vec 모델링

word2vec_model <-
    h2o.word2vec(words, min_word_freq = 5, epochs = 5)
  • min_word_freq: 5회 미만 사용된 단어 제거
  • epochs: 학습 반복 횟수
R로 배우는 자연어 처리 입문

단어 유의어

h2o.findSynonyms(w2v.model, "animal")
    synonym     score
1     drink 0.8209088
2       age 0.7952490
3   alcohol 0.7867004
4       act 0.7710537
5      hero 0.7658424
h2o.findSynonyms(w2v.model, "jones")
      synonym     score
1      battle 0.7996588
2  discovered 0.7944554
3     cowshed 0.7823287
4     enemies 0.7766532
5       yards 0.7679787
R로 배우는 자연어 처리 입문

추가 활용

  • 분류 모델링
  • 감성 분석
  • 토픽 모델링
R로 배우는 자연어 처리 입문

word2vec 적용

R로 배우는 자연어 처리 입문

Preparing Video For Download...