Skip to content

Instantly share code, notes, and snippets.

@rishisidhu
Created September 1, 2020 02:38
Show Gist options
  • Save rishisidhu/cfcf9c4f038cdef6cfd84ad3c288c17b to your computer and use it in GitHub Desktop.
Save rishisidhu/cfcf9c4f038cdef6cfd84ad3c288c17b to your computer and use it in GitHub Desktop.
Building a word index from training sentences
from tensorflow.keras.preprocessing.text import Tokenizer
#Let's add custom sentences
sentences = [
"Apples are red",
"Apples are round",
"Oranges are round",
"Grapes are green"
]
#Tokenize the sentences
myTokenizer = Tokenizer(num_words=100)
myTokenizer.fit_on_texts(sentences)
print(myTokenizer.word_index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment