Created
September 1, 2020 02:38
-
-
Save rishisidhu/cfcf9c4f038cdef6cfd84ad3c288c17b to your computer and use it in GitHub Desktop.
Building a word index from training sentences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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