Created
February 23, 2018 09:38
-
-
Save Tony607/8b9ca78953f7ea04903daeffc62d63c6 to your computer and use it in GitHub Desktop.
source: How to generate realistic yelp restaurant reviews with Keras | DLology
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 getDataFromChunk(txtChunk, maxlen=60, step=1): | |
sentences = [] | |
next_chars = [] | |
for i in range(0, len(txtChunk) - maxlen, step): | |
sentences.append(txtChunk[i : i + maxlen]) | |
next_chars.append(txtChunk[i + maxlen]) | |
print('nb sequences:', len(sentences)) | |
print('Vectorization...') | |
X = np.zeros((len(sentences), maxlen, len(chars)), dtype=np.bool) | |
y = np.zeros((len(sentences), len(chars)), dtype=np.bool) | |
for i, sentence in enumerate(sentences): | |
for t, char in enumerate(sentence): | |
X[i, t, char_indices[char]] = 1 | |
y[i, char_indices[next_chars[i]]] = 1 | |
return [X, y] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment