<jupyter_start><jupyter_text>Sequence Padding<jupyter_code>from keras.preprocessing.sequence import pad_sequences<jupyter_output>/home/cbrom/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.<jupyter_text>** pre-sequence padding **<jupyter_code>sequences = [
    [1, 2, 3, 4],
    [1, 2, 3], 
    [1]
]

# pad sequence
padded = pad_sequences(sequences)
print(padded)<jupyter_output>[[1 2 3 4]
 [0 1 2 3]
 [0 0 0 1]]<jupyter_text>** post-sequence padding **<jupyter_code># pad sequence
padded = pad_sequences(sequences, padding='post')
print(padded)<jupyter_output>[[1 2 3 4]
 [1 2 3 0]
 [1 0 0 0]]<jupyter_text>Sequence Truncation ** pre-sequence truncation **<jupyter_code># truncate sequence
truncated = pad_sequences(sequences, maxlen=2)
print(truncated)<jupyter_output>[[3 4]
 [2 3]
 [0 1]]<jupyter_text>** post-sequence truncation **<jupyter_code># truncate sequence
truncated = pad_sequences(sequences, maxlen=2, truncating='post')
print(truncated)<jupyter_output>[[1 2]
 [1 2]
 [0 1]]
{'fraction_non_alphanumeric': 0.1347517730496454, 'fraction_numerical': 0.0425531914893617, 'mean_word_length': 6.341040462427745, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '20007', 'license': 'MIT', 'n_tokens_mistral': 523, 'n_tokens_neox': 470, 'n_words': 114, 'path': 'Lesson-03/Prepare Sequencces with Varied Lengths.ipynb', 'repo_name': 'cbrom/LSTM-with-python', 'size': '1269'}