Created
August 25, 2020 06:00
-
-
Save rishisidhu/e71774010aed36fdd5bdbd000fe5f9fd to your computer and use it in GitHub Desktop.
Converting sequences back to text
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 = [ | |
"One plus one is two!", | |
"Two plus two is four!" | |
] | |
for num_w in range(1,7): | |
myTokenizer = Tokenizer(num_words=num_w) | |
myTokenizer.fit_on_texts(sentences) | |
print("\n",num_w,": ",myTokenizer.texts_to_sequences(sentences)) | |
seqs = myTokenizer.texts_to_sequences(sentences) | |
#A Better Way | |
print(' : ',[x for x in myTokenizer.sequences_to_texts_generator(seqs)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment