Skip to content

Instantly share code, notes, and snippets.

@arunm8489
Last active August 1, 2020 14:13
Show Gist options
  • Save arunm8489/fad2c93882737d80602ac6ea18119ad1 to your computer and use it in GitHub Desktop.
Save arunm8489/fad2c93882737d80602ac6ea18119ad1 to your computer and use it in GitHub Desktop.
def padding_(sentences, seq_len):
"""
do padding on left handside
ie, if seq_len = 5 and input is [1,2,3] out will be [0,0,1,2,3]
"""
features = np.zeros((len(sentences), seq_len),dtype=int)
for ii, review in enumerate(sentences):
if len(review) != 0:
features[ii, -len(review):] = np.array(review)[:seq_len]
return features
# padding (we will pad to a length of 440)
essay_train_pad = padding_(np.array(essay_train_p),440)
essay_test_pad = padding_(np.array(essay_test_p),440)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment