Woord-embeddings

Introductie tot Natural Language Processing in R

Kasey Jones

Research Data Scientist

Het probleem met woordtellingen

Twee zinnen:

  • Bob is de slimste persoon die ik ken.
  • Bob is de meest briljante persoon die ik ken.

Zonder stopwoorden:

  • Bob slimste persoon
  • Bob briljant persoon
Introductie tot Natural Language Processing in R

Woordbetekenissen

Extra data:

  • De slimste mensen ...
  • Hij was de slimste ...
  • Briljante mensen ...
  • Die van hem was zo briljant ...
Introductie tot Natural Language Processing in R

word2vec

  • stelt woorden voor als een grote vectorruimte
  • legt meerdere overeenkomsten tussen woorden vast
  • woorden met vergelijkbare betekenis liggen dichter bij elkaar

Met een word2vec-representatie liggen vergelijkbare woorden dichter bij elkaar in een multidimensionale vectorruimte.

1 https://www.adityathakker.com/introduction-to-word2vec-how-it-works/
Introductie tot Natural Language Processing in R

Data voorbereiden

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

Tokenizen met h2o:

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

word2vec-modellering

word2vec_model <-
    h2o.word2vec(words, min_word_freq = 5, epochs = 5)
  • min_word_freq: verwijdert woorden die minder dan 5× voorkomen
  • epochs: aantal trainingsiteraties
Introductie tot Natural Language Processing in R

Woordsynoniemen

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
Introductie tot Natural Language Processing in R

Extra toepassingen

  • classificatiemodellen
  • sentimentanalyse
  • topicmodellering
Introductie tot Natural Language Processing in R

word2vec toepassen

Introductie tot Natural Language Processing in R

Preparing Video For Download...