Skip to content

Instantly share code, notes, and snippets.

@ibombonato
Created July 19, 2017 18:01
Show Gist options
  • Save ibombonato/ac27546a5aaf2a7d00c8c86fb2200aff to your computer and use it in GitHub Desktop.
Save ibombonato/ac27546a5aaf2a7d00c8c86fb2200aff to your computer and use it in GitHub Desktop.
Using text to sequence in R with Keras
library(keras)
texts <- c("Today I got to the movie",
"Yesterday we got to the movie",
"Today was cold at the movie",
"Somethign happened yesterday")
tok <- keras::text_tokenizer(num_words = 5)
keras::fit_text_tokenizer(tok, texts)
tok$word_counts
tok$word_index
texts_sequence <- keras::texts_to_sequences(tok, texts)
pad_sequence <- keras::pad_sequences(texts_sequence, maxlen = 5)
pad_sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment