Word embeddings

Introduction au Natural Language Processing en R

Kasey Jones

Research Data Scientist

La limite des comptages de mots

Deux phrases :

  • Bob est la personne la plus intelligente que je connaisse.
  • Bob est la personne la plus brillante que je connaisse.

Sans stop words :

  • Bob smartest person
  • Bob brilliant person
Introduction au Natural Language Processing en R

Sens des mots

Données supplémentaires :

  • The smartest people ...
  • He was the smartest ...
  • Brilliant people ...
  • His was so brilliant ...
Introduction au Natural Language Processing en R

word2vec

  • représente les mots dans un grand espace vectoriel
  • capture plusieurs similarités entre les mots
  • les mots de sens proche sont plus proches dans l'espace

Avec une représentation word2vec, les mots similaires sont regroupés plus près les uns des autres dans un espace vectoriel multidimensionnel.

1 https://www.adityathakker.com/introduction-to-word2vec-how-it-works/
Introduction au Natural Language Processing en R

Préparer les données

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

Tokeniser avec h2o :

words <- h2o.tokenize(h2o_object$text_column, "\\\\W+")
words <- h2o.tolower(words)
words = words[is.na(words) || (!words %in% stop_words$word),]
Introduction au Natural Language Processing en R

Modéliser avec word2vec

word2vec_model <-
    h2o.word2vec(words, min_word_freq = 5, epochs = 5)
  • min_word_freq : supprime les mots utilisés moins de 5 fois
  • epochs : nombre d'itérations d'entraînement à exécuter
Introduction au Natural Language Processing en R

Synonymes de mots

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
Introduction au Natural Language Processing en R

Autres usages

  • modélisation de classification
  • analyse de sentiments
  • modélisation de sujets
Introduction au Natural Language Processing en R

Appliquer word2vec

Introduction au Natural Language Processing en R

Preparing Video For Download...