Skip to content

Instantly share code, notes, and snippets.

@VincentTatan
Created May 22, 2020 00:48
Show Gist options
  • Save VincentTatan/75826251c3be4e6f633398f8c70ca0a8 to your computer and use it in GitHub Desktop.
Save VincentTatan/75826251c3be4e6f633398f8c70ca0a8 to your computer and use it in GitHub Desktop.
from tensorflow.keras.preprocessing.sequence import pad_sequences
sequences = tokenizer.texts_to_sequences(sentences)
padded = pad_sequences(sequences, maxlen=5)
print("\nThe Word Index = " , word_index)
print("\nThe Sequences = " , sequences)
print("\nThe Padded Sequences:")
print(padded)
# Test data with sentences we have never seen
test_data = [
'i really love fish',
'you love to eat fish so much'
]
test_seq = tokenizer.texts_to_sequences(test_data)
print("\nTest Sequence = ", test_seq)
padded = pad_sequences(test_seq)
print("\nPadded Test Sequence: ")
print(padded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment