Skip to content

Instantly share code, notes, and snippets.

@rishisidhu
Created August 25, 2020 06:00
Show Gist options
  • Save rishisidhu/e71774010aed36fdd5bdbd000fe5f9fd to your computer and use it in GitHub Desktop.
Save rishisidhu/e71774010aed36fdd5bdbd000fe5f9fd to your computer and use it in GitHub Desktop.
Converting sequences back to text
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