Last active
August 1, 2020 14:13
-
-
Save arunm8489/fad2c93882737d80602ac6ea18119ad1 to your computer and use it in GitHub Desktop.
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
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